dynamicWorkflowGrayAutomationsPage.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @vitest-environment jsdom
  2. // 动态工作流灰度关掉之后的自动化页(docs/dynamic-workflow/launch.md「Gray release」DWG-07):
  3. // 灰度关闭时标题不提供工作流标签。
  4. //
  5. import { createElement, useState } from "react";
  6. import { cleanup, render, screen } from "@testing-library/react";
  7. import { afterEach, describe, expect, it } from "vitest";
  8. import { TID_AUTOMATIONS_PAGE_TAB } from "@zcode/shared";
  9. import { testId } from "@zcode/shared/test-ids";
  10. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  11. import {
  12. AutomationsPageTitle,
  13. type AutomationsPageTab,
  14. } from "@/settings/saved-workflows/AutomationsPageTitleSwitch.js";
  15. function Title({
  16. workflowTabEnabled,
  17. locale = "zh-CN",
  18. }: {
  19. workflowTabEnabled: boolean;
  20. locale?: "zh-CN" | "en-US";
  21. }) {
  22. const [tab, setTab] = useState<AutomationsPageTab>("automation");
  23. return createElement(
  24. ZCodeIntlProvider,
  25. { initialLocale: locale },
  26. createElement(AutomationsPageTitle, {
  27. workflowTabEnabled,
  28. value: tab,
  29. onValueChange: setTab,
  30. }),
  31. );
  32. }
  33. describe("AutomationsPageTitle 灰度门", () => {
  34. afterEach(() => {
  35. cleanup();
  36. });
  37. it("灰度关 → 平铺的「自动化」标题,没有 tablist,也没有「工作流」这个词", () => {
  38. render(createElement(Title, { workflowTabEnabled: false }));
  39. expect(screen.queryByRole("tablist")).toBeNull();
  40. expect(screen.queryByTestId(testId(TID_AUTOMATIONS_PAGE_TAB, "workflow"))).toBeNull();
  41. const heading = screen.getByRole("heading", { level: 1 });
  42. expect(heading.textContent).toBe("自动化");
  43. });
  44. it("灰度关 + en-US → 标题走同一个 i18n key,不是硬编码中文", () => {
  45. render(createElement(Title, { workflowTabEnabled: false, locale: "en-US" }));
  46. expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("Automations");
  47. });
  48. it("灰度开 → 与改动前一致:两个标题词组成 tablist", () => {
  49. render(createElement(Title, { workflowTabEnabled: true }));
  50. expect(screen.getAllByRole("tab").map((tab) => tab.textContent)).toEqual(["自动化", "工作流"]);
  51. expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
  52. });
  53. });