Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button } from "@/components/ui/button";
import { Screen } from "@/components/ui/screen";
import { Text } from "@/components/ui/text";
import { useRouter } from "expo-router";
import { View } from "react-native";

export default function NotFoundScreen() {
const router = useRouter();

return (
<Screen>
<View className="flex-1 items-center justify-center gap-6 px-6">
<Text variant="h2">Page not found</Text>
<Text variant="muted">The page you're looking for doesn't exist.</Text>

Check failure on line 14 in app/+not-found.tsx

View workflow job for this annotation

GitHub Actions / autofix

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`

Check failure on line 14 in app/+not-found.tsx

View workflow job for this annotation

GitHub Actions / autofix

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`
<Button variant="accent" onPress={() => router.back()}>
<Text>Go back</Text>
</Button>
</View>
</Screen>
);
}
1 change: 1 addition & 0 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const RootLayout = () => {
<Stack.Screen name="purchase/[token]" options={{ title: "" }} />
<Stack.Screen name="post/[id]" options={{ title: "" }} />
<Stack.Screen name="pdf-viewer" options={{ title: "PDF" }} />
<Stack.Screen name="+not-found" options={{ title: "Not Found" }} />
</Stack>
<StatusBar style="light" />
<PortalHost />
Expand Down
26 changes: 26 additions & 0 deletions tests/components/not-found-screen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen, fireEvent } from "@testing-library/react-native";

const mockBack = jest.fn();
jest.mock("expo-router", () => ({
useRouter: () => ({ back: mockBack }),
}));

import NotFoundScreen from "@/app/+not-found";

describe("NotFoundScreen", () => {
beforeEach(() => {
jest.clearAllMocks();
});

it("renders the not found message", () => {
render(<NotFoundScreen />);
expect(screen.getByText("Page not found")).toBeTruthy();
expect(screen.getByText("The page you're looking for doesn't exist.")).toBeTruthy();
});

it("navigates back when the button is pressed", () => {
render(<NotFoundScreen />);
fireEvent.press(screen.getByText("Go back"));
expect(mockBack).toHaveBeenCalled();
});
});
Loading