alertDialogStore.test.ts 920 B

12345678910111213141516171819202122232425
  1. import { beforeEach, describe, expect, it } from "vitest";
  2. import { useAlertDialogStore } from "@/store/alertDialogStore.js";
  3. describe("alertDialogStore", () => {
  4. beforeEach(() => {
  5. useAlertDialogStore.setState({ pendingRequest: undefined });
  6. });
  7. it("returns false when a concurrent alert is dropped", async () => {
  8. const first = useAlertDialogStore.getState().requestAlert({ title: "first" });
  9. const second = await useAlertDialogStore.getState().requestAlert({ title: "second" });
  10. expect(second).toBe(false);
  11. useAlertDialogStore.getState().settleAlert();
  12. await expect(first).resolves.toBe(true);
  13. });
  14. it("returns false when the dialog is closed without confirmation", async () => {
  15. const request = useAlertDialogStore.getState().requestAlert({ title: "close" });
  16. useAlertDialogStore.getState().settleAlert(false);
  17. await expect(request).resolves.toBe(false);
  18. });
  19. });