offpeak-eligibility-cases.mjs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. export function registerOffPeakEligibilityCases(getContext) {
  4. test("offpeak: actual home Team-only entry preserves gray, inactive and dismiss gates", async () => {
  5. const { browser, origin } = getContext();
  6. const page = await browser.newPage();
  7. const errors = [];
  8. page.on("pageerror", (error) => errors.push(String(error)));
  9. try {
  10. for (const family of ["bigmodel", "zai"]) {
  11. for (const gate of ["", "&inactive=1", "&noPlan=1", "&grayOff=1"]) {
  12. await page.goto(`${origin}fixture?teamEntry=1&family=${family}&locale=zh-CN${gate}`);
  13. await page.waitForFunction(
  14. () => document.querySelector('[data-testid="team-loaded"]')?.textContent === "true",
  15. );
  16. const entry = page.locator("[data-off-peak-new-task-entry]");
  17. if (gate === "&grayOff=1") {
  18. assert.equal(await entry.count(), 0);
  19. continue;
  20. }
  21. await entry.locator("[data-off-peak-template-grid] button").last().click();
  22. assert.equal(await page.getByTestId("team-opened").textContent(), gate ? "0" : "1");
  23. if (!gate) {
  24. assert.match(await page.getByTestId("team-draft").textContent(), /app.session/);
  25. await page.getByTestId("dismiss-entry").click();
  26. assert.equal(await entry.count(), 0);
  27. }
  28. }
  29. }
  30. assert.deepEqual(errors, []);
  31. } finally {
  32. await page.close();
  33. }
  34. });
  35. test("offpeak: Registry ready notification and manual refresh share current eligibility", async () => {
  36. const { browser, origin } = getContext();
  37. const page = await browser.newPage();
  38. const calls = [],
  39. errors = [];
  40. page.on("pageerror", (error) => errors.push(String(error)));
  41. await page.route("**/eligibility-rpc", async (route) => {
  42. calls.push(route.request().postDataJSON());
  43. await route.fulfill({ status: 200, body: "{}" });
  44. });
  45. const settled = async (status) =>
  46. page.waitForFunction(
  47. (value) =>
  48. document.querySelector('[data-testid="status-automation"]')?.textContent === value,
  49. status,
  50. );
  51. try {
  52. await page.goto(`${origin}fixture?offpeak=1&locale=zh-CN&theme=dark`);
  53. await settled("idle");
  54. assert.equal(await page.getByTestId("create-automation").isDisabled(), true);
  55. assert.equal(calls.length, 1, "two entries share initialization");
  56. calls.length = 0;
  57. await page.getByTestId("account-ready").click();
  58. await settled("ready");
  59. assert.equal(await page.getByTestId("create-automation").isEnabled(), true);
  60. assert.equal(await page.getByTestId("create-home").isEnabled(), true);
  61. assert.deepEqual(
  62. calls.map((c) => c.call),
  63. ["support", "availability"],
  64. );
  65. await page.getByTestId("account-off").click();
  66. await settled("idle");
  67. assert.equal(await page.getByTestId("create-automation").isDisabled(), true);
  68. calls.length = 0;
  69. await page.getByTestId("account-silent").click();
  70. await page.getByTestId("refresh-automation").click();
  71. await settled("ready");
  72. assert.deepEqual(
  73. calls.map((c) => c.call),
  74. ["support", "availability"],
  75. );
  76. await page.getByTestId("rpc-fail").click();
  77. await settled("error");
  78. assert.equal(await page.getByTestId("create-automation").isDisabled(), true);
  79. await page.getByTestId("account-ready").click();
  80. await settled("ready");
  81. assert.equal(await page.getByTestId("create-automation").isEnabled(), true);
  82. assert.deepEqual(errors, []);
  83. } finally {
  84. await page.close();
  85. }
  86. });
  87. }