|
1 | 1 | /* |
2 | | -Copyright 2019 New Vector Ltd |
| 2 | +Copyright 2019, 2023 New Vector Ltd |
3 | 3 |
|
4 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | you may not use this file except in compliance with the License. |
@@ -50,6 +50,7 @@ describe("Login", function () { |
50 | 50 | mockClient.baseUrl = opts.baseUrl; |
51 | 51 | return mockClient; |
52 | 52 | }); |
| 53 | + fetchMock.resetBehavior(); |
53 | 54 | fetchMock.get("https://matrix.org/_matrix/client/versions", { |
54 | 55 | unstable_features: {}, |
55 | 56 | versions: [], |
@@ -253,4 +254,69 @@ describe("Login", function () { |
253 | 254 | const ssoButtons = container.querySelectorAll(".mx_SSOButton"); |
254 | 255 | expect(ssoButtons.length).toBe(idpsWithIcons.length + 1); |
255 | 256 | }); |
| 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 | + }); |
256 | 322 | }); |
0 commit comments