mobile-result-image.spec.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { test, expect } = require("@playwright/test");
  2. const { baseUrls } = require("./helpers/env");
  3. test.use({ viewport: { width: 360, height: 800 } });
  4. async function openResultImage(page, width, height) {
  5. await page.goto(`${baseUrls.standaloneNew}/index-modern.html`);
  6. await page.locator("#results").evaluate(
  7. (image, dimensions) => {
  8. image.src =
  9. "data:image/svg+xml," +
  10. encodeURIComponent(
  11. `<svg xmlns="http://www.w3.org/2000/svg" width="${dimensions.width}" height="${dimensions.height}"><rect width="100%" height="100%" fill="black"/></svg>`
  12. );
  13. },
  14. { width, height }
  15. );
  16. await page.locator("#share").evaluate(dialog => dialog.showModal());
  17. const image = page.locator("#results");
  18. await expect(image).toBeVisible();
  19. await expect(image).toHaveJSProperty("complete", true);
  20. return image.evaluate(element => ({
  21. width: element.getBoundingClientRect().width,
  22. height: element.getBoundingClientRect().height,
  23. dialogWidth: element.closest("dialog").clientWidth,
  24. dialogHeight: element.closest("dialog").clientHeight
  25. }));
  26. }
  27. test.describe("Mobile result-image sharing", () => {
  28. test("keeps the landscape result image within the share dialog width", async ({ page }) => {
  29. const dimensions = await openResultImage(page, 800, 480);
  30. expect(dimensions.width).toBeLessThanOrEqual(dimensions.dialogWidth);
  31. });
  32. test("keeps a tall result image within the share dialog height", async ({ page }) => {
  33. const dimensions = await openResultImage(page, 480, 1600);
  34. expect(dimensions.height).toBeLessThanOrEqual(dimensions.dialogHeight);
  35. });
  36. });