-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WD-3060 - Handle login timeouts (#1457)
* Handle login timeouts.
- Loading branch information
Showing
15 changed files
with
195 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { Provider } from "react-redux"; | ||
import configureStore from "redux-mock-store"; | ||
|
||
import { rootStateFactory } from "testing/factories/root"; | ||
|
||
import ConnectionError from "./ConnectionError"; | ||
|
||
const mockStore = configureStore(); | ||
|
||
describe("ConnectionError", () => { | ||
let reload: Location["reload"]; | ||
|
||
beforeEach(() => { | ||
reload = window.location.reload; | ||
Object.defineProperty(window, "location", { | ||
value: { reload: jest.fn() }, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
Object.defineProperty(window, "location", { | ||
value: { reload }, | ||
}); | ||
}); | ||
|
||
it("displays connection errors", () => { | ||
const state = rootStateFactory | ||
.withGeneralConfig() | ||
.build({ general: { connectionError: "Can't connect" } }); | ||
const store = mockStore(state); | ||
render( | ||
<Provider store={store}> | ||
<ConnectionError /> | ||
</Provider> | ||
); | ||
expect(screen.getByText(/Can't connect/)).toBeInTheDocument(); | ||
}); | ||
|
||
it("can refresh the window", async () => { | ||
const state = rootStateFactory | ||
.withGeneralConfig() | ||
.build({ general: { connectionError: "Can't connect" } }); | ||
const store = mockStore(state); | ||
render( | ||
<Provider store={store}> | ||
<ConnectionError /> | ||
</Provider> | ||
); | ||
await userEvent.click(screen.getByRole("button", { name: "refreshing" })); | ||
expect(window.location.reload).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Button, Notification, Strip } from "@canonical/react-components"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
import { getConnectionError } from "store/general/selectors"; | ||
import { useAppSelector } from "store/store"; | ||
|
||
const ConnectionError = ({ children }: PropsWithChildren) => { | ||
const error = useAppSelector(getConnectionError); | ||
if (error) { | ||
return ( | ||
<Strip> | ||
<Notification severity="negative" title="Error"> | ||
{error} Try{" "} | ||
<Button appearance="link" onClick={() => window.location.reload()}> | ||
refreshing | ||
</Button>{" "} | ||
the page. | ||
</Notification> | ||
</Strip> | ||
); | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export default ConnectionError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./ConnectionError"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters