update-confirmation.fixture.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { ConfirmDialogHost } from "@/ConfirmDialog.js";
  4. import { ZCodeIntlProvider, useZCodeIntl } from "@/i18n/IntlProvider.js";
  5. import { useConfirmDialogStore } from "@/store/confirmDialogStore.js";
  6. import "@/styles.css";
  7. const params = new URLSearchParams(location.search);
  8. const theme = params.get("theme") === "dark" ? "dark" : "light";
  9. document.documentElement.className = `${theme} theme-zai-${theme} platform-windows-desktop`;
  10. function Fixture() {
  11. const { intl } = useZCodeIntl();
  12. const [choice, setChoice] = useState("pending");
  13. const requestChoice = useConfirmDialogStore((state) => state.requestChoice);
  14. const open = (update: boolean) => {
  15. setChoice("pending");
  16. void requestChoice({
  17. ...(update ? { presentation: "update-confirmation" as const, showKeyboardHints: false } : {}),
  18. testId: "confirmation-fixture",
  19. title: intl.formatMessage({ id: "updateReady.confirm.title" }, { version: "3.19.0" }),
  20. description: intl.formatMessage({ id: "updateReady.confirm.description" }),
  21. confirmLabel: intl.formatMessage({ id: "updateReady.confirm.ok" }),
  22. cancelLabel: intl.formatMessage({ id: "updateReady.confirm.cancel" }),
  23. }).then(setChoice);
  24. };
  25. return (
  26. <main className="min-h-dvh bg-background p-5 text-foreground">
  27. <button data-testid="open-update" onClick={() => open(true)}>
  28. Update
  29. </button>
  30. <button data-testid="open-default" onClick={() => open(false)}>
  31. Default
  32. </button>
  33. <output data-testid="choice">{choice}</output>
  34. <ConfirmDialogHost />
  35. </main>
  36. );
  37. }
  38. createRoot(document.getElementById("root")!).render(
  39. <ZCodeIntlProvider initialLocale={params.get("locale") === "en-US" ? "en-US" : "zh-CN"}>
  40. <Fixture />
  41. </ZCodeIntlProvider>,
  42. );