-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'custom404' into playwright
* custom404: [pre-commit.ci] auto fixes from pre-commit.com hooks Added NotFound.test.tsx Resolve ' issue [pre-commit.ci] auto fixes from pre-commit.com hooks Added Custom 404 Page.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { MemoryRouter, Route, Routes } from "react-router"; | ||
import NotFound from "./NotFound"; | ||
|
||
interface NotFoundTestParams { | ||
path: string; | ||
expectedText: string; | ||
} | ||
|
||
const testCases: NotFoundTestParams[] = [ | ||
{ | ||
path: "/random-path", | ||
expectedText: "404 Not Found", | ||
}, | ||
]; | ||
|
||
describe.each(testCases)("NotFound Component", ({ path, expectedText }) => { | ||
const testName = `Render correctly when navigating to '${path}'`; | ||
test(testName, () => { | ||
render( | ||
<MemoryRouter initialEntries={[path]}> | ||
<Routes> | ||
<Route path="*" element={<NotFound />} /> | ||
</Routes> | ||
</MemoryRouter>, | ||
); | ||
expect(screen.getByText(expectedText)).not.toBeNull(); | ||
}); | ||
}); |
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,25 @@ | ||
import { Link } from "react-router"; | ||
import { useContext } from "react"; | ||
import { ThemeContext } from "../context/ThemeContext"; | ||
|
||
const NotFound = () => { | ||
const { isDarkMode } = useContext(ThemeContext); | ||
|
||
return ( | ||
<div className="vh-100 d-flex flex-column align-items-center justify-content-center"> | ||
<h1 | ||
className={`display-4 fw-bold mb-4 ${isDarkMode ? "text-info" : "text-secondary"}`} | ||
> | ||
404 Not Found | ||
</h1> | ||
<p className="fs-5 text-muted mb-4 text-center"> | ||
Sorry, the page you're looking for doesn't exist. | ||
</p> | ||
<Link to="/" className="btn btn-primary btn-lg px-4 py-2 shadow-sm"> | ||
Go To Home | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NotFound; |
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