share-selection-mask.mjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import assert from "node:assert/strict";
  2. export async function verifySelectionScrollMask(panel, screenshotPath) {
  3. const viewport = panel.locator('[data-slot="scroll-area-viewport"]');
  4. const footer = panel.getByTestId("conversation-share-selection-footer");
  5. const bounds = await viewport.boundingBox();
  6. const header = await panel.getByTestId("conversation-share-selection-header").boundingBox();
  7. assert.equal(header.y, (await panel.boundingBox()).y);
  8. assert.equal(bounds.y, header.y + header.height);
  9. assert.equal(bounds.y + bounds.height, (await footer.boundingBox()).y);
  10. const readMask = () => viewport.evaluate((node) => getComputedStyle(node).maskImage);
  11. const scroll = async (position) => {
  12. await viewport.evaluate(async (node, next) => {
  13. node.scrollTop = next;
  14. await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
  15. }, position);
  16. };
  17. const maxScroll = await viewport.evaluate((node) => node.scrollHeight - node.clientHeight);
  18. await scroll(0);
  19. if (maxScroll <= 1) {
  20. assert.equal(await readMask(), "none");
  21. return;
  22. }
  23. const topMask = await readMask();
  24. assert.match(topMask, /32px/);
  25. assert.equal((topMask.match(/rgba\(0, 0, 0, 0\)/g) ?? []).length, 1);
  26. await scroll(maxScroll / 2);
  27. const middleMask = await readMask();
  28. assert.equal((middleMask.match(/rgba\(0, 0, 0, 0\)/g) ?? []).length, 2);
  29. assert.equal(await footer.evaluate((node) => getComputedStyle(node).maskImage), "none");
  30. assert.equal(
  31. await panel
  32. .getByTestId("conversation-share-selection-scroll-thumb")
  33. .evaluate((node) => getComputedStyle(node).maskImage),
  34. "none",
  35. );
  36. await panel.screenshot({ path: screenshotPath });
  37. await scroll(maxScroll);
  38. const bottomMask = await readMask();
  39. assert.notEqual(bottomMask, topMask);
  40. assert.equal((bottomMask.match(/rgba\(0, 0, 0, 0\)/g) ?? []).length, 1);
  41. await scroll(0);
  42. assert.equal(await readMask(), topMask);
  43. }