share-disclosure-feedback.mjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. export function registerShareDisclosureTests(environment) {
  4. test("SHARE34 warning row shakes once and respects reduced motion", async () => {
  5. for (const reducedMotion of ["no-preference", "reduce"]) {
  6. const { browser, origin } = environment();
  7. const page = await browser.newPage({ viewport: { width: 1200, height: 900 }, reducedMotion });
  8. await page.goto(`${origin}fixture?theme=light&locale=zh-CN`);
  9. await page.getByTestId("conversation-share-trigger").click();
  10. const animations = await page.evaluate(() => {
  11. const button = document.querySelector('[data-testid="conversation-share-confirm"]');
  12. const row = document
  13. .querySelector('[data-testid="conversation-share-disclosure-checkbox"]')
  14. .closest("label");
  15. button.click();
  16. button.click();
  17. return row
  18. .getAnimations()
  19. .map((a) => a.effect.getKeyframes().map((frame) => frame.transform));
  20. });
  21. assert.equal(animations.length, reducedMotion === "reduce" ? 0 : 1);
  22. if (reducedMotion !== "reduce") assert.ok(animations[0].includes("translateX(-4px)"));
  23. await page.getByTestId("conversation-share-disclosure-checkbox").check();
  24. assert.equal(
  25. await page
  26. .getByTestId("conversation-share-disclosure")
  27. .locator("label")
  28. .evaluate((row) => row.getAnimations().length),
  29. 0,
  30. );
  31. assert.equal(await page.getByTestId("conversation-share-publish-progress").count(), 0);
  32. await page.close();
  33. }
  34. });
  35. test("SHARE34 short viewport keeps unchecked feedback inside the popover", async () => {
  36. const { browser, origin } = environment();
  37. const page = await browser.newPage({ viewport: { width: 390, height: 420 } });
  38. await page.goto(`${origin}fixture?theme=dark&locale=en-US`);
  39. await page.getByTestId("conversation-share-trigger").click();
  40. const popover = page.getByTestId("conversation-share-popover");
  41. await popover.waitFor();
  42. await page.evaluate(async () => {
  43. await Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {})));
  44. });
  45. const submit = page.getByTestId("conversation-share-confirm");
  46. const before = await submit.boundingBox();
  47. await submit.click();
  48. assert.deepEqual(await submit.boundingBox(), before);
  49. assert.equal(await page.evaluate(() => window.scrollY), 0);
  50. const checkbox = await page.getByTestId("conversation-share-disclosure-checkbox").boundingBox();
  51. const body = await page.getByTestId("conversation-share-confirmation-body").boundingBox();
  52. assert.ok(checkbox.y >= body.y && checkbox.y + checkbox.height <= body.y + body.height);
  53. assert.equal(await page.getByTestId("conversation-share-publish-progress").count(), 0);
  54. await page.close();
  55. });
  56. }