|
| 1 | +import { describe, it, expect, beforeEach, afterEach } from "vitest"; |
| 2 | +import { render, screen, waitFor } from "@testing-library/preact"; |
| 3 | +import { App } from "./app"; |
| 4 | + |
| 5 | +describe("App Routing", () => { |
| 6 | + beforeEach(() => { |
| 7 | + // Reset path before each test |
| 8 | + window.history.replaceState(null, "", "/"); |
| 9 | + }); |
| 10 | + |
| 11 | + afterEach(() => { |
| 12 | + window.history.replaceState(null, "", "/"); |
| 13 | + }); |
| 14 | + |
| 15 | + it("renders Layout at root path '/'", async () => { |
| 16 | + window.history.replaceState(null, "", "/"); |
| 17 | + render(<App />); |
| 18 | + |
| 19 | + await waitFor(() => { |
| 20 | + expect(screen.getByText("Finote")).toBeInTheDocument(); |
| 21 | + }); |
| 22 | + expect(screen.queryByText("Halaman Tidak Ditemukan")).not.toBeInTheDocument(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("renders Layout at GitHub Pages repository path '/arxfinote'", async () => { |
| 26 | + window.history.replaceState(null, "", "/arxfinote"); |
| 27 | + render(<App />); |
| 28 | + |
| 29 | + await waitFor(() => { |
| 30 | + expect(screen.getByText("Finote")).toBeInTheDocument(); |
| 31 | + }); |
| 32 | + expect(screen.queryByText("Halaman Tidak Ditemukan")).not.toBeInTheDocument(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("renders NotFound page for unknown routes", async () => { |
| 36 | + window.history.replaceState(null, "", "/halaman-ngawur"); |
| 37 | + render(<App />); |
| 38 | + |
| 39 | + await waitFor(() => { |
| 40 | + expect(screen.getByText("Halaman Tidak Ditemukan")).toBeInTheDocument(); |
| 41 | + }); |
| 42 | + expect(screen.getByText("404")).toBeInTheDocument(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments