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

Commit

Permalink
cover more error cases in Login (#11073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry authored Jun 13, 2023
1 parent 41dfec2 commit f7137b4
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion test/components/structures/auth/Login-test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 New Vector Ltd
Copyright 2019, 2023 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,6 +50,7 @@ describe("Login", function () {
mockClient.baseUrl = opts.baseUrl;
return mockClient;
});
fetchMock.resetBehavior();
fetchMock.get("https://matrix.org/_matrix/client/versions", {
unstable_features: {},
versions: [],
Expand Down Expand Up @@ -253,4 +254,69 @@ describe("Login", function () {
const ssoButtons = container.querySelectorAll(".mx_SSOButton");
expect(ssoButtons.length).toBe(idpsWithIcons.length + 1);
});

it("should display an error when homeserver doesn't offer any supported login flows", async () => {
mockClient.loginFlows.mockResolvedValue({
flows: [
{
type: "just something weird",
},
],
});

getComponent();
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

expect(
screen.getByText("This homeserver doesn't offer any login flows which are supported by this client."),
).toBeInTheDocument();
});

it("should display a connection error when getting login flows fails", async () => {
mockClient.loginFlows.mockRejectedValue("oups");

getComponent();
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

expect(
screen.getByText("There was a problem communicating with the homeserver, please try again later."),
).toBeInTheDocument();
});

it("should display an error when homeserver fails liveliness check", async () => {
fetchMock.resetBehavior();
fetchMock.get("https://matrix.org/_matrix/client/versions", {
status: 400,
});
getComponent();
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

// error displayed
expect(screen.getByText("Your test-brand is misconfigured")).toBeInTheDocument();
});

it("should reset liveliness error when server config changes", async () => {
fetchMock.resetBehavior();
// matrix.org is not alive
fetchMock.get("https://matrix.org/_matrix/client/versions", {
status: 400,
});
// but server2 is
fetchMock.get("https://server2/_matrix/client/versions", {
unstable_features: {},
versions: [],
});
const { rerender } = render(getRawComponent());
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

// error displayed
expect(screen.getByText("Your test-brand is misconfigured")).toBeInTheDocument();

rerender(getRawComponent("https://server2"));

await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

// error cleared
expect(screen.queryByText("Your test-brand is misconfigured")).not.toBeInTheDocument();
});
});

0 comments on commit f7137b4

Please sign in to comment.