Skip to content

Commit ae26b78

Browse files
committed
add toast
1 parent e2f6b84 commit ae26b78

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

tests/browser/responses-pilot/SelectLocation.browser.vitest.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import { describe, it, expect, beforeAll } from "vitest";
1+
import { describe, it, expect, beforeAll, vi } from "vitest";
22
import { page } from "@vitest/browser/context";
33
import { SelectLocation } from "@responses-pilot/location/SelectLocation";
44
import { render } from "./testUtils";
55
import { setupFonts } from "./testHelpers";
66

77
import "@root/styles/app.scss";
88

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+
918
describe("SelectLocation - Browser Mode", () => {
1019
beforeAll(() => {
1120
setupFonts();
@@ -49,4 +58,27 @@ describe("SelectLocation - Browser Mode", () => {
4958
.element(backButton)
5059
.toHaveAttribute("href", "/en/form-builder/test-form/responses-pilot/load-key?reset=true");
5160
});
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+
});
5284
});

tests/browser/responses-pilot/testUtils.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PilotBadge } from "@clientComponents/globals/PilotBadge";
77
import { ApiClientSetter } from "./AplClientSetter";
88
import { GCFormsApiClient } from "@responses-pilot/lib/apiClient";
99
import { showOpenFilePicker } from "native-file-system-adapter";
10+
import { ToastContainer } from "@formBuilder/components/shared/Toast";
1011

1112
// Import to trigger i18next initialization
1213
import "@root/i18n/client";
@@ -40,6 +41,9 @@ export function TestWrapper({
4041
<h1 className="mb-4">Responses</h1>
4142
<PilotBadge className="mb-8" />
4243
<ContentWrapper>{children}</ContentWrapper>
44+
<ToastContainer />
45+
<ToastContainer containerId="wide" width="600px" />
46+
<ToastContainer containerId="error-persistent" autoClose={false} />
4347
</ResponsesProvider>
4448
</BrowserResponsesAppProvider>
4549
);

0 commit comments

Comments
 (0)