-
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.
feat(apps/web): Add loading and error states to pages
- Loading branch information
1 parent
52d8b95
commit 3c5bc74
Showing
9 changed files
with
82 additions
and
4 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
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,12 @@ | ||
"use client"; | ||
|
||
import type { FC } from "react"; | ||
import PageError from "../components/pageError"; | ||
|
||
interface PageErrorProps { | ||
reset: () => void; | ||
} | ||
|
||
const Error: FC<PageErrorProps> = ({ reset }) => <PageError reset={reset} />; | ||
|
||
export default Error; |
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,5 @@ | ||
import PageLoader from "../components/pageLoader"; | ||
|
||
export default function Loading() { | ||
return <PageLoader />; | ||
} |
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,16 @@ | ||
import type { FC } from "react"; | ||
import { Flex, Loader } from "@mantine/core"; | ||
|
||
const PageLoader: FC = () => ( | ||
<Flex | ||
w="100%" | ||
h="100%" | ||
justify="center" | ||
align="center" | ||
style={{ minHeight: "inherit" }} | ||
> | ||
<Loader data-testid="page-spinner" /> | ||
</Flex> | ||
); | ||
|
||
export default PageLoader; |
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,32 @@ | ||
import { describe, it } from "vitest"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { withMantineTheme } from "../utils/WithMantineTheme"; | ||
import PageError from "../../src/components/pageError"; | ||
|
||
const Component = withMantineTheme(PageError); | ||
const props = { | ||
reset: () => undefined, | ||
}; | ||
|
||
describe("PageError component", () => { | ||
it("should display correct heading", () => { | ||
render(<Component {...props} />); | ||
expect(screen.getByText("Something went wrong!")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display correct button text", () => { | ||
render(<Component {...props} />); | ||
expect(screen.getByText("Try again")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should invoke reset function when button is clicked", () => { | ||
const mockedReset = vi.fn(); | ||
render(<Component reset={mockedReset} />); | ||
|
||
const button = screen.getByText("Try again") | ||
.parentElement as HTMLButtonElement; | ||
fireEvent.click(button); | ||
|
||
expect(mockedReset).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,13 @@ | ||
import { describe, it } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { withMantineTheme } from "../utils/WithMantineTheme"; | ||
import PageLoader from "../../src/components/pageLoader"; | ||
|
||
const Component = withMantineTheme(PageLoader); | ||
|
||
describe("PageLoader component", () => { | ||
it("should display spinner", () => { | ||
render(<Component />); | ||
expect(screen.getByTestId("page-spinner")).toBeInTheDocument(); | ||
}); | ||
}); |