hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; |
| 2 | import { createSignal } from "solid-js"; |
| 3 | import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog"; |
| 4 | |
| 5 | beforeEach(() => vi.spyOn(window, "scrollTo").mockImplementation(() => {})); |
| 6 | afterEach(() => { |
| 7 | cleanup(); |
| 8 | vi.restoreAllMocks(); |
| 9 | }); |
| 10 | |
| 11 | test("dialog closes when backdrop is pressed", async () => { |
| 12 | function TestDialog() { |
| 13 | const [open, setOpen] = createSignal(true); |
| 14 | return ( |
| 15 | <> |
| 16 | <span>{open() ? "open" : "closed"}</span> |
| 17 | <Dialog open={open()} onOpenChange={setOpen}> |
| 18 | <DialogContent> |
| 19 | <DialogTitle>Test dialog</DialogTitle> |
| 20 | </DialogContent> |
| 21 | </Dialog> |
| 22 | </> |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | render(() => <TestDialog />); |
| 27 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 28 | fireEvent.pointerDown(document.querySelector("[data-expanded]")!); |
| 29 | |
| 30 | expect(screen.getByText("closed")).toBeTruthy(); |
| 31 | }); |