InviteDialog: remove broken checks for unknown users (#33026)
* InviteDialog: remove broken checks for unknown users Per https://github.com/element-hq/element-web/issues/33020, this doesn't actually work, and if we were to bring it back, we'd design it differently. * Remove now-unused `UserProfilesStore.getProfileLookupError` This was only used in `InviteDialog.checkProfileAndStartDm`, which has now been removed.
This commit is contained in:
@@ -32,7 +32,6 @@ import { type IConfigOptions } from "../../../../../src/IConfigOptions";
|
||||
import { SdkContextClass } from "../../../../../src/contexts/SDKContext";
|
||||
import { type IProfileInfo } from "../../../../../src/hooks/useProfileInfo";
|
||||
import { DirectoryMember, startDmOnFirstMessage } from "../../../../../src/utils/direct-messages";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
|
||||
const mockGetAccessToken = jest.fn().mockResolvedValue("getAccessToken");
|
||||
jest.mock("../../../../../src/IdentityAuthClient", () =>
|
||||
@@ -120,7 +119,7 @@ describe("InviteDialog", () => {
|
||||
if (userId === bobId) return bobProfileInfo;
|
||||
|
||||
throw new MatrixError({
|
||||
errcode: "M_NOT_FOUND",
|
||||
errcode: "M_UNKNOWN",
|
||||
error: "Profile not found",
|
||||
});
|
||||
}),
|
||||
@@ -418,55 +417,8 @@ describe("InviteDialog", () => {
|
||||
});
|
||||
|
||||
describe("when inviting a user with an unknown profile", () => {
|
||||
beforeEach(async () => {
|
||||
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
|
||||
await enterIntoSearchField(carolId);
|
||||
await userEvent.click(screen.getByRole("button", { name: "Go" }));
|
||||
// Wait for the »invite anyway« modal to show up
|
||||
await screen.findByText("The following users may not exist");
|
||||
});
|
||||
|
||||
it("should not start the DM", () => {
|
||||
expect(startDmOnFirstMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should show the »invite anyway« dialog if the profile is not available", () => {
|
||||
expect(screen.getByText("The following users may not exist")).toBeInTheDocument();
|
||||
expect(screen.getByText(`${carolId}: Profile not found`)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("when clicking »Start DM anyway«", () => {
|
||||
beforeEach(async () => {
|
||||
await userEvent.click(screen.getByRole("button", { name: "Start DM anyway" }));
|
||||
});
|
||||
|
||||
it("should start the DM", () => {
|
||||
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockClient, [
|
||||
new DirectoryMember({
|
||||
user_id: carolId,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when clicking »Close«", () => {
|
||||
beforeEach(async () => {
|
||||
mocked(startDmOnFirstMessage).mockClear();
|
||||
await userEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
});
|
||||
|
||||
it("should not start the DM", () => {
|
||||
expect(startDmOnFirstMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when inviting a user with an unknown profile and »promptBeforeInviteUnknownUsers« setting = false", () => {
|
||||
beforeEach(async () => {
|
||||
mocked(startDmOnFirstMessage).mockClear();
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||
(settingName) => settingName !== "promptBeforeInviteUnknownUsers",
|
||||
);
|
||||
render(<InviteDialog kind={InviteKind.Dm} onFinished={jest.fn()} />);
|
||||
await enterIntoSearchField(carolId);
|
||||
await userEvent.click(screen.getByRole("button", { name: "Go" }));
|
||||
@@ -474,10 +426,6 @@ describe("InviteDialog", () => {
|
||||
await sleep(100);
|
||||
});
|
||||
|
||||
it("should not show the »invite anyway« dialog", () => {
|
||||
expect(screen.queryByText("The following users may not exist")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should start the DM directly", () => {
|
||||
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockClient, [
|
||||
new DirectoryMember({
|
||||
|
||||
@@ -86,11 +86,6 @@ describe("UserProfilesStore", () => {
|
||||
expect(profile).toBeNull();
|
||||
});
|
||||
|
||||
it("should cache the error and result", () => {
|
||||
expect(userProfilesStore.getProfile(userIdDoesNotExist)).toBeNull();
|
||||
expect(userProfilesStore.getProfileLookupError(userIdDoesNotExist)).toBe(userDoesNotExistError);
|
||||
});
|
||||
|
||||
describe("when the profile does not exist and fetching it again", () => {
|
||||
beforeEach(async () => {
|
||||
mockClient.getProfileInfo.mockResolvedValue(user1Profile);
|
||||
@@ -100,10 +95,6 @@ describe("UserProfilesStore", () => {
|
||||
it("should return the profile", () => {
|
||||
expect(profile).toBe(user1Profile);
|
||||
});
|
||||
|
||||
it("should clear the error", () => {
|
||||
expect(userProfilesStore.getProfileLookupError(userIdDoesNotExist)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -119,22 +110,6 @@ describe("UserProfilesStore", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProfileLookupError", () => {
|
||||
it("should return undefined if a profile was not fetched", () => {
|
||||
expect(userProfilesStore.getProfileLookupError(user1Id)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return undefined if a profile was successfully fetched", async () => {
|
||||
await userProfilesStore.fetchProfile(user1Id);
|
||||
expect(userProfilesStore.getProfileLookupError(user1Id)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return the error if there was one", async () => {
|
||||
await userProfilesStore.fetchProfile(userIdDoesNotExist);
|
||||
expect(userProfilesStore.getProfileLookupError(userIdDoesNotExist)).toBe(userDoesNotExistError);
|
||||
});
|
||||
});
|
||||
|
||||
it("getOnlyKnownProfile should return undefined if the profile was not fetched", () => {
|
||||
expect(userProfilesStore.getOnlyKnownProfile(user1Id)).toBeUndefined();
|
||||
});
|
||||
@@ -195,7 +170,6 @@ describe("UserProfilesStore", () => {
|
||||
|
||||
expect(userProfilesStore.getProfile(user1Id)).toBeUndefined();
|
||||
expect(userProfilesStore.getOnlyKnownProfile(user1Id)).toBeUndefined();
|
||||
expect(userProfilesStore.getProfileLookupError(userIdDoesNotExist)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user