-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Olga Bulat <obulat@gmail.com>
- Loading branch information
Showing
20 changed files
with
307 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,75 @@ | ||
import { test, expect } from "@playwright/test" | ||
|
||
import { turnOnAnalytics } from "~~/test/playwright/utils/navigation" | ||
import { preparePageForTests } from "~~/test/playwright/utils/navigation" | ||
import { | ||
collectAnalyticsEvents, | ||
expectEventPayloadToMatch, | ||
} from "~~/test/playwright/utils/analytics" | ||
|
||
test.describe.configure({ mode: "parallel" }) | ||
|
||
test.beforeEach(async ({ context }) => { | ||
await context.grantPermissions(["clipboard-read", "clipboard-write"]) | ||
}) | ||
|
||
test("can copy rich text attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-rich"]') | ||
await page.click('[id="copyattr-rich"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
test.describe("attribution", () => { | ||
test.beforeEach(async ({ context, page }) => { | ||
await preparePageForTests(page, "xl", { features: { analytics: "on" } }) | ||
await context.grantPermissions(["clipboard-read", "clipboard-write"]) | ||
}) | ||
// The Clipboard API returns a plain-text-ified version of the rich text. | ||
expect(clippedText).toContain('"bubbles in honey" by mutednarayan') | ||
}) | ||
|
||
test("can copy HTML attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-html"]') | ||
await page.click('[id="copyattr-html"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
}) | ||
const snippets = [ | ||
'<p class="attribution">', | ||
">bubbles in honey</a>", | ||
">mutednarayan</a>", | ||
] | ||
snippets.forEach((snippet) => { | ||
expect(clippedText).toContain(snippet) | ||
test("can copy rich text attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-rich"]') | ||
await page.click('[id="copyattr-rich"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
}) | ||
// The Clipboard API returns a plain-text-ified version of the rich text. | ||
expect(clippedText).toContain('"bubbles in honey" by mutednarayan') | ||
}) | ||
}) | ||
|
||
test("can copy plain text attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-plain"]') | ||
await page.click('[id="copyattr-plain"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
test("can copy HTML attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-html"]') | ||
await page.click('[id="copyattr-html"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
}) | ||
const snippets = [ | ||
'<p class="attribution">', | ||
">bubbles in honey</a>", | ||
">mutednarayan</a>", | ||
] | ||
snippets.forEach((snippet) => { | ||
expect(clippedText).toContain(snippet) | ||
}) | ||
}) | ||
// Only the plain-text license contains the "To view" bit. | ||
expect(clippedText).toContain("To view a copy of this license") | ||
}) | ||
|
||
test("sends analytics event on copy", async ({ page }) => { | ||
let copyAttributionEventData: { | ||
id: string | ||
format: string | ||
mediaType: string | ||
} = { id: "", format: "", mediaType: "" } | ||
page.on("request", (req) => { | ||
if (req.method() === "POST") { | ||
const requestData = req.postDataJSON() | ||
if (requestData?.n == "COPY_ATTRIBUTION") { | ||
copyAttributionEventData = JSON.parse(requestData?.p) | ||
} | ||
} | ||
test("can copy plain text attribution", async ({ page }) => { | ||
await page.goto("image/e9d97a98-621b-4ec2-bf70-f47a74380452") | ||
await page.click('[aria-controls="panel-plain"]') | ||
await page.click('[id="copyattr-plain"]') | ||
const clippedText = await page.evaluate(async () => { | ||
return navigator.clipboard.readText() | ||
}) | ||
// Only the plain-text license contains the "To view" bit. | ||
expect(clippedText).toContain("To view a copy of this license") | ||
}) | ||
const mediaType = "image" | ||
const id = "e9d97a98-621b-4ec2-bf70-f47a74380452" | ||
const format = "rich" | ||
|
||
await turnOnAnalytics(page) | ||
test("sends analytics event on copy", async ({ page }) => { | ||
const analyticsEvents = collectAnalyticsEvents(page.context()) | ||
|
||
await page.goto(`${mediaType}/${id}?ff_analytics=on`) | ||
await page.click(`[id="copyattr-${format}"]`) | ||
const mediaType = "image" | ||
const id = "e9d97a98-621b-4ec2-bf70-f47a74380452" | ||
const format = "rich" | ||
|
||
expect(copyAttributionEventData.id).toEqual(id) | ||
expect(copyAttributionEventData.format).toEqual(format) | ||
expect(copyAttributionEventData.mediaType).toEqual(mediaType) | ||
await page.goto(`${mediaType}/${id}?ff_analytics=on`) | ||
await page.click(`[id="copyattr-${format}"]`) | ||
|
||
const copyAttributionEvent = analyticsEvents.find( | ||
(event) => event.n === "COPY_ATTRIBUTION" | ||
) | ||
expectEventPayloadToMatch(copyAttributionEvent, { | ||
id, | ||
format, | ||
mediaType, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,64 @@ | ||
import { test, expect } from "@playwright/test" | ||
|
||
import { setCookies, t } from "~~/test/playwright/utils/navigation" | ||
import { preparePageForTests, t } from "~~/test/playwright/utils/navigation" | ||
|
||
test.describe.configure({ mode: "parallel" }) | ||
|
||
test.beforeEach(async ({ context, page }) => { | ||
await setCookies(context, { | ||
features: { additional_search_views: "on", analytics: "off" }, | ||
test.describe("collections", () => { | ||
test.beforeEach(async ({ page }) => { | ||
await preparePageForTests(page, "xl", { | ||
features: { | ||
additional_search_views: "on", | ||
}, | ||
}) | ||
await page.goto("/image/f9384235-b72e-4f1e-9b05-e1b116262a29?q=cat") | ||
}) | ||
await page.goto("/image/f9384235-b72e-4f1e-9b05-e1b116262a29?q=cat") | ||
}) | ||
test("can open tags collection page from image page", async ({ page }) => { | ||
// Using the href because there are multiple links with the same text. | ||
await page.click('[href*="/tag/cat"]') | ||
|
||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
test("can open tags collection page from image page", async ({ page }) => { | ||
// Using the href because there are multiple links with the same text. | ||
await page.click('[href*="/tag/cat"]') | ||
|
||
await expect(page.getByRole("heading", { name: /cat/i })).toBeVisible() | ||
expect(await page.locator("figure").count()).toEqual(20) | ||
expect(page.url()).toMatch(/image\/tag\/cat/) | ||
}) | ||
test("can open source collection page from image page", async ({ page }) => { | ||
const sourcePattern = /flickr/i | ||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
|
||
await page.getByRole("link", { name: sourcePattern }).first().click() | ||
await expect( | ||
page.getByRole("heading", { level: 1, name: /cat/i }) | ||
).toBeVisible() | ||
expect(await page.locator("figure").count()).toEqual(20) | ||
expect(page.url()).toMatch(/image\/tag\/cat/) | ||
}) | ||
test("can open source collection page from image page", async ({ page }) => { | ||
const sourcePattern = /flickr/i | ||
|
||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
await page.getByRole("link", { name: sourcePattern }).first().click() | ||
|
||
await expect(page.getByRole("heading", { name: sourcePattern })).toBeVisible() | ||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
|
||
expect(await page.locator("figure").count()).toEqual(20) | ||
await expect( | ||
page.getByRole("heading", { name: sourcePattern }) | ||
).toBeVisible() | ||
|
||
expect(page.url()).toMatch(/image\/source\/flickr\/$/) | ||
}) | ||
test("can open creator collection page from image page", async ({ page }) => { | ||
const creatorPattern = /strogoscope/i | ||
await page.getByRole("link", { name: creatorPattern }).first().click() | ||
expect(await page.locator("figure").count()).toEqual(20) | ||
|
||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
expect(page.url()).toMatch(/image\/source\/flickr\/$/) | ||
}) | ||
test("can open creator collection page from image page", async ({ page }) => { | ||
const creatorPattern = /strogoscope/i | ||
await page.getByRole("link", { name: creatorPattern }).first().click() | ||
|
||
await expect( | ||
page.getByRole("button", { name: t("browsePage.load") }) | ||
).toBeEnabled() | ||
|
||
await expect( | ||
page.getByRole("heading", { name: creatorPattern }) | ||
).toBeVisible() | ||
await expect( | ||
page.getByRole("heading", { level: 1, name: creatorPattern }) | ||
).toBeVisible() | ||
|
||
expect(await page.locator("figure").count()).toEqual(20) | ||
expect(await page.locator("figure").count()).toEqual(20) | ||
|
||
expect(page.url()).toMatch(/image\/source\/flickr\/creator\/strogoscope\//) | ||
expect(page.url()).toMatch(/image\/source\/flickr\/creator\/strogoscope\//) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.