This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 816
Fix email lookup in invite dialog #10150
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d9ff5f
Fix email lookup in invite dialog
weeman1337 5bad827
Merge branch 'develop' into weeman1337/invite-email-lookup
weeman1337 a7f319b
Refactor InviteDialog logic
weeman1337 2428fe2
Merge branch 'develop' into weeman1337/invite-email-lookup
weeman1337 aff24ed
Revert "Refactor InviteDialog logic"
weeman1337 7d02055
Merge branch 'develop' into weeman1337/invite-email-lookup
weeman1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ limitations under the License. | |
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { RoomType } from "matrix-js-sdk/src/@types/event"; | ||
import { Room } from "matrix-js-sdk/src/matrix"; | ||
|
||
import InviteDialog from "../../../../src/components/views/dialogs/InviteDialog"; | ||
import { KIND_INVITE } from "../../../../src/components/views/dialogs/InviteDialogTypes"; | ||
import { getMockClientWithEventEmitter, mkStubRoom } from "../../../test-utils"; | ||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; | ||
import { KIND_DM, KIND_INVITE } from "../../../../src/components/views/dialogs/InviteDialogTypes"; | ||
import { getMockClientWithEventEmitter, mkMembership, mkMessage, mkRoomCreateEvent } from "../../../test-utils"; | ||
import DMRoomMap from "../../../../src/utils/DMRoomMap"; | ||
import SdkConfig from "../../../../src/SdkConfig"; | ||
import { ValidatedServerConfig } from "../../../../src/utils/ValidatedServerConfig"; | ||
|
@@ -37,8 +37,11 @@ jest.mock("../../../../src/IdentityAuthClient", () => | |
describe("InviteDialog", () => { | ||
const roomId = "!111111111111111111:example.org"; | ||
const aliceId = "@alice:example.org"; | ||
const aliceEmail = "[email protected]"; | ||
const bobId = "@bob:example.org"; | ||
const mockClient = getMockClientWithEventEmitter({ | ||
getUserId: jest.fn().mockReturnValue(aliceId), | ||
getUserId: jest.fn().mockReturnValue(bobId), | ||
getSafeUserId: jest.fn().mockReturnValue(bobId), | ||
isGuest: jest.fn().mockReturnValue(false), | ||
getVisibleRooms: jest.fn().mockReturnValue([]), | ||
getRoom: jest.fn(), | ||
|
@@ -58,36 +61,61 @@ describe("InviteDialog", () => { | |
getOpenIdToken: jest.fn().mockResolvedValue({}), | ||
getIdentityAccount: jest.fn().mockResolvedValue({}), | ||
getTerms: jest.fn().mockResolvedValue({ policies: [] }), | ||
supportsThreads: jest.fn().mockReturnValue(false), | ||
isInitialSyncComplete: jest.fn().mockReturnValue(true), | ||
}); | ||
let room: Room; | ||
|
||
beforeEach(() => { | ||
SdkConfig.put({ validated_server_config: {} as ValidatedServerConfig } as IConfigOptions); | ||
DMRoomMap.makeShared(); | ||
jest.clearAllMocks(); | ||
mockClient.getUserId.mockReturnValue("@bob:example.org"); | ||
|
||
const room = mkStubRoom(roomId, "Room", mockClient); | ||
mockClient.getUserId.mockReturnValue(bobId); | ||
|
||
room = new Room(roomId, mockClient, mockClient.getSafeUserId()); | ||
room.addLiveEvents([ | ||
mkMessage({ | ||
msg: "Hello", | ||
relatesTo: undefined, | ||
event: true, | ||
room: roomId, | ||
user: mockClient.getSafeUserId(), | ||
ts: Date.now(), | ||
}), | ||
]); | ||
room.currentState.setStateEvents([ | ||
mkRoomCreateEvent(bobId, roomId), | ||
mkMembership({ | ||
event: true, | ||
room: roomId, | ||
mship: "join", | ||
user: aliceId, | ||
skey: aliceId, | ||
}), | ||
]); | ||
jest.spyOn(DMRoomMap.shared(), "getUniqueRoomsWithIndividuals").mockReturnValue({ | ||
[aliceId]: room, | ||
}); | ||
mockClient.getRooms.mockReturnValue([room]); | ||
mockClient.getRoom.mockReturnValue(room); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.spyOn(MatrixClientPeg, "get").mockRestore(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it("should label with space name", () => { | ||
mockClient.getRoom(roomId)!.isSpaceRoom = jest.fn().mockReturnValue(true); | ||
mockClient.getRoom(roomId)!.getType = jest.fn().mockReturnValue(RoomType.Space); | ||
mockClient.getRoom(roomId)!.name = "Space"; | ||
room.isSpaceRoom = jest.fn().mockReturnValue(true); | ||
room.getType = jest.fn().mockReturnValue(RoomType.Space); | ||
room.name = "Space"; | ||
render(<InviteDialog kind={KIND_INVITE} roomId={roomId} onFinished={jest.fn()} />); | ||
|
||
expect(screen.queryByText("Invite to Space")).toBeTruthy(); | ||
}); | ||
|
||
it("should label with room name", () => { | ||
render(<InviteDialog kind={KIND_INVITE} roomId={roomId} onFinished={jest.fn()} />); | ||
|
||
expect(screen.queryByText("Invite to Room")).toBeTruthy(); | ||
expect(screen.getByText(`Invite to ${roomId}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should suggest valid MXIDs even if unknown", async () => { | ||
|
@@ -116,27 +144,37 @@ describe("InviteDialog", () => { | |
expect(screen.queryByText("@localpart:server:tld")).toBeFalsy(); | ||
}); | ||
|
||
it("should lookup inputs which look like email addresses", async () => { | ||
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server"); | ||
mockClient.lookupThreePid.mockResolvedValue({ | ||
address: "[email protected]", | ||
medium: "email", | ||
mxid: "@foobar:server", | ||
}); | ||
mockClient.getProfileInfo.mockResolvedValue({ | ||
displayname: "Mr. Foo", | ||
avatar_url: "mxc://foo/bar", | ||
}); | ||
|
||
render( | ||
<InviteDialog kind={KIND_INVITE} roomId={roomId} onFinished={jest.fn()} initialText="[email protected]" />, | ||
); | ||
|
||
await screen.findByText("Mr. Foo"); | ||
await screen.findByText("@foobar:server"); | ||
expect(mockClient.lookupThreePid).toHaveBeenCalledWith("email", "[email protected]", expect.anything()); | ||
expect(mockClient.getProfileInfo).toHaveBeenCalledWith("@foobar:server"); | ||
}); | ||
it.each([[KIND_DM], [KIND_INVITE]] as [typeof KIND_DM | typeof KIND_INVITE][])( | ||
"should lookup inputs which look like email addresses (%s)", | ||
async (kind: typeof KIND_DM | typeof KIND_INVITE) => { | ||
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server"); | ||
mockClient.lookupThreePid.mockResolvedValue({ | ||
address: aliceEmail, | ||
medium: "email", | ||
mxid: aliceId, | ||
}); | ||
mockClient.getProfileInfo.mockResolvedValue({ | ||
displayname: "Mrs Alice", | ||
avatar_url: "mxc://foo/bar", | ||
}); | ||
|
||
render( | ||
<InviteDialog | ||
kind={kind} | ||
roomId={kind === KIND_INVITE ? roomId : ""} | ||
onFinished={jest.fn()} | ||
initialText={aliceEmail} | ||
/>, | ||
); | ||
|
||
await screen.findByText("Mrs Alice"); | ||
// expect the email and MXID to be visible | ||
await screen.findByText(aliceId); | ||
await screen.findByText(aliceEmail); | ||
expect(mockClient.lookupThreePid).toHaveBeenCalledWith("email", aliceEmail, expect.anything()); | ||
expect(mockClient.getProfileInfo).toHaveBeenCalledWith(aliceId); | ||
}, | ||
); | ||
|
||
it("should suggest e-mail even if lookup fails", async () => { | ||
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server"); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.