Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f7137b4

Browse files
author
Kerry
authored
cover more error cases in Login (#11073)
1 parent 41dfec2 commit f7137b4

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

test/components/structures/auth/Login-test.tsx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2019 New Vector Ltd
2+
Copyright 2019, 2023 New Vector Ltd
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@ describe("Login", function () {
5050
mockClient.baseUrl = opts.baseUrl;
5151
return mockClient;
5252
});
53+
fetchMock.resetBehavior();
5354
fetchMock.get("https://matrix.org/_matrix/client/versions", {
5455
unstable_features: {},
5556
versions: [],
@@ -253,4 +254,69 @@ describe("Login", function () {
253254
const ssoButtons = container.querySelectorAll(".mx_SSOButton");
254255
expect(ssoButtons.length).toBe(idpsWithIcons.length + 1);
255256
});
257+
258+
it("should display an error when homeserver doesn't offer any supported login flows", async () => {
259+
mockClient.loginFlows.mockResolvedValue({
260+
flows: [
261+
{
262+
type: "just something weird",
263+
},
264+
],
265+
});
266+
267+
getComponent();
268+
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
269+
270+
expect(
271+
screen.getByText("This homeserver doesn't offer any login flows which are supported by this client."),
272+
).toBeInTheDocument();
273+
});
274+
275+
it("should display a connection error when getting login flows fails", async () => {
276+
mockClient.loginFlows.mockRejectedValue("oups");
277+
278+
getComponent();
279+
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
280+
281+
expect(
282+
screen.getByText("There was a problem communicating with the homeserver, please try again later."),
283+
).toBeInTheDocument();
284+
});
285+
286+
it("should display an error when homeserver fails liveliness check", async () => {
287+
fetchMock.resetBehavior();
288+
fetchMock.get("https://matrix.org/_matrix/client/versions", {
289+
status: 400,
290+
});
291+
getComponent();
292+
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
293+
294+
// error displayed
295+
expect(screen.getByText("Your test-brand is misconfigured")).toBeInTheDocument();
296+
});
297+
298+
it("should reset liveliness error when server config changes", async () => {
299+
fetchMock.resetBehavior();
300+
// matrix.org is not alive
301+
fetchMock.get("https://matrix.org/_matrix/client/versions", {
302+
status: 400,
303+
});
304+
// but server2 is
305+
fetchMock.get("https://server2/_matrix/client/versions", {
306+
unstable_features: {},
307+
versions: [],
308+
});
309+
const { rerender } = render(getRawComponent());
310+
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
311+
312+
// error displayed
313+
expect(screen.getByText("Your test-brand is misconfigured")).toBeInTheDocument();
314+
315+
rerender(getRawComponent("https://server2"));
316+
317+
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
318+
319+
// error cleared
320+
expect(screen.queryByText("Your test-brand is misconfigured")).not.toBeInTheDocument();
321+
});
256322
});

0 commit comments

Comments
 (0)