|
1 | | -import { describe, it, expect, beforeAll } from "vitest"; |
| 1 | +import { describe, it, expect, beforeAll, vi } from "vitest"; |
2 | 2 | import { page } from "@vitest/browser/context"; |
3 | 3 | import { SelectLocation } from "@responses-pilot/location/SelectLocation"; |
4 | 4 | import { render } from "./testUtils"; |
5 | 5 | import { setupFonts } from "./testHelpers"; |
6 | 6 |
|
7 | 7 | import "@root/styles/app.scss"; |
8 | 8 |
|
| 9 | +// Mock the native-file-system-adapter module |
| 10 | +vi.mock("native-file-system-adapter", async () => { |
| 11 | + const actual = await vi.importActual("native-file-system-adapter"); |
| 12 | + return { |
| 13 | + ...actual, |
| 14 | + showDirectoryPicker: vi.fn(), |
| 15 | + }; |
| 16 | +}); |
| 17 | + |
9 | 18 | describe("SelectLocation - Browser Mode", () => { |
10 | 19 | beforeAll(() => { |
11 | 20 | setupFonts(); |
@@ -49,4 +58,27 @@ describe("SelectLocation - Browser Mode", () => { |
49 | 58 | .element(backButton) |
50 | 59 | .toHaveAttribute("href", "/en/form-builder/test-form/responses-pilot/load-key?reset=true"); |
51 | 60 | }); |
| 61 | + |
| 62 | + it("should show toast when directory is selected", async () => { |
| 63 | + const { showDirectoryPicker } = await import("native-file-system-adapter"); |
| 64 | + |
| 65 | + // Mock the directory picker to return a mock handle |
| 66 | + vi.mocked(showDirectoryPicker).mockResolvedValueOnce({ |
| 67 | + name: "test-directory", |
| 68 | + kind: "directory", |
| 69 | + getDirectoryHandle: vi.fn().mockResolvedValue({}), |
| 70 | + } as never); |
| 71 | + |
| 72 | + await render(<SelectLocation locale="en" id="test-form" />); |
| 73 | + |
| 74 | + const pickerButton = page.getByTestId("choose-location-button"); |
| 75 | + await pickerButton.click(); |
| 76 | + |
| 77 | + // Wait for toast to appear |
| 78 | + await new Promise((resolve) => setTimeout(resolve, 500)); |
| 79 | + |
| 80 | + // Check for toast message |
| 81 | + const toast = page.getByText(/test-directory/i); |
| 82 | + await expect.element(toast).toBeInTheDocument(); |
| 83 | + }); |
52 | 84 | }); |
0 commit comments