You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
Prevent re-filtering user directory results in spotlight (#11290)
* Prevent re-filtering user directory results in spotlight As they were already filtered by the server and may be fuzzier than any filtering we can do locally, e.g. matching against email addresses or other fields not available to the client * deduplicate work * Improve coverage
This commit is contained in:
committed by
GitHub
parent
d9aaed0ef6
commit
9136a581d2
@@ -338,6 +338,52 @@ describe("Spotlight Dialog", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not filter out users sent by the server", async () => {
|
||||
mocked(mockedClient.searchUserDirectory).mockResolvedValue({
|
||||
results: [
|
||||
{ user_id: "@user1:server", display_name: "User Alpha", avatar_url: "mxc://1/avatar" },
|
||||
{ user_id: "@user2:server", display_name: "User Beta", avatar_url: "mxc://2/avatar" },
|
||||
],
|
||||
limited: false,
|
||||
});
|
||||
|
||||
render(<SpotlightDialog initialFilter={Filter.People} initialText="Alpha" onFinished={() => null} />);
|
||||
// search is debounced
|
||||
jest.advanceTimersByTime(200);
|
||||
await flushPromisesWithFakeTimers();
|
||||
|
||||
const content = document.querySelector("#mx_SpotlightDialog_content")!;
|
||||
const options = content.querySelectorAll("li.mx_SpotlightDialog_option");
|
||||
expect(options.length).toBeGreaterThanOrEqual(2);
|
||||
expect(options[0]).toHaveTextContent("User Alpha");
|
||||
expect(options[1]).toHaveTextContent("User Beta");
|
||||
});
|
||||
|
||||
it("should not filter out users sent by the server even if a local suggestion gets filtered out", async () => {
|
||||
const member = new RoomMember(testRoom.roomId, testPerson.user_id);
|
||||
member.name = member.rawDisplayName = testPerson.display_name!;
|
||||
member.getMxcAvatarUrl = jest.fn().mockReturnValue("mxc://0/avatar");
|
||||
mocked(testRoom.getJoinedMembers).mockReturnValue([member]);
|
||||
mocked(mockedClient.searchUserDirectory).mockResolvedValue({
|
||||
results: [
|
||||
{ user_id: "@janedoe:matrix.org", display_name: "User Alpha", avatar_url: "mxc://1/avatar" },
|
||||
{ user_id: "@johndoe:matrix.org", display_name: "User Beta", avatar_url: "mxc://2/avatar" },
|
||||
],
|
||||
limited: false,
|
||||
});
|
||||
|
||||
render(<SpotlightDialog initialFilter={Filter.People} initialText="Beta" onFinished={() => null} />);
|
||||
// search is debounced
|
||||
jest.advanceTimersByTime(200);
|
||||
await flushPromisesWithFakeTimers();
|
||||
|
||||
const content = document.querySelector("#mx_SpotlightDialog_content")!;
|
||||
const options = content.querySelectorAll("li.mx_SpotlightDialog_option");
|
||||
expect(options.length).toBeGreaterThanOrEqual(2);
|
||||
expect(options[0]).toHaveTextContent(testPerson.display_name!);
|
||||
expect(options[1]).toHaveTextContent("User Beta");
|
||||
});
|
||||
|
||||
it("should start a DM when clicking a person", async () => {
|
||||
render(
|
||||
<SpotlightDialog
|
||||
|
Reference in New Issue
Block a user