Show error when searching public rooms fails (#11378)
* Show error when searching public rooms fails * Fix types * Improve test coverage * Improve coverage
This commit is contained in:
parent
b5bfc5be21
commit
2b17fc3221
4 changed files with 63 additions and 13 deletions
|
@ -16,7 +16,14 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { IProtocol, IPublicRoomsChunkRoom, MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
ConnectionError,
|
||||
IProtocol,
|
||||
IPublicRoomsChunkRoom,
|
||||
MatrixClient,
|
||||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
|
||||
|
@ -495,4 +502,32 @@ describe("Spotlight Dialog", () => {
|
|||
expect(screen.getByText(potatoRoom.name!)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("should show error if /publicRooms API failed", async () => {
|
||||
mocked(mockedClient.publicRooms).mockRejectedValue(new ConnectionError("Failed to fetch"));
|
||||
render(<SpotlightDialog initialFilter={Filter.PublicRooms} onFinished={() => null} />);
|
||||
|
||||
jest.advanceTimersByTime(200);
|
||||
await flushPromisesWithFakeTimers();
|
||||
|
||||
expect(screen.getByText("Failed to query public rooms")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should show error both 'Show rooms' and 'Show spaces' are unchecked", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName, roomId, excludeDefault) => {
|
||||
if (settingName === "feature_exploring_public_spaces") {
|
||||
return true;
|
||||
} else {
|
||||
return []; // SpotlightSearch.recentSearches
|
||||
}
|
||||
});
|
||||
render(<SpotlightDialog initialFilter={Filter.PublicRooms} onFinished={() => null} />);
|
||||
|
||||
jest.advanceTimersByTime(200);
|
||||
await flushPromisesWithFakeTimers();
|
||||
|
||||
fireEvent.click(screen.getByText("Show rooms"));
|
||||
|
||||
expect(screen.getByText("You cannot search for rooms that are neither a room nor a space")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue