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:
parent
d9aaed0ef6
commit
9136a581d2
2 changed files with 82 additions and 21 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue