|
| 1 | +// cspell: ignore nsewdrag |
| 2 | + |
| 3 | +import { test, expect } from "@playwright/test"; |
| 4 | +import { getComparator } from "playwright-core/lib/utils"; |
| 5 | +import { |
| 6 | + localUrl, |
| 7 | + referenceUrl, |
| 8 | + username, |
| 9 | + repo1, |
| 10 | + repo2, |
| 11 | + authenticate, |
| 12 | + getChartScreenshot, |
| 13 | +} from "./utils"; |
| 14 | + |
| 15 | +test("Basic Flow", async ({ page }, testDir) => { |
| 16 | + const getGridStarsCount = async (rowNum: number) => { |
| 17 | + return Number( |
| 18 | + await page.getByRole("row").nth(rowNum).getByRole("gridcell").nth(1).textContent(), |
| 19 | + ); |
| 20 | + }; |
| 21 | + |
| 22 | + const takeReferenceScreenshots = async () => { |
| 23 | + await page.goto(referenceUrl); |
| 24 | + |
| 25 | + await authenticate(page); |
| 26 | + |
| 27 | + const screenshots: Buffer[] = []; |
| 28 | + |
| 29 | + // Get screenshot for repo1 |
| 30 | + await page.getByPlaceholder("Username").fill(username); |
| 31 | + await page.getByPlaceholder("Repo name").fill(repo1); |
| 32 | + await page.getByRole("button", { name: "Go!" }).click(); |
| 33 | + await page.getByRole("button", { name: "Go!" }).waitFor({ state: "visible" }); |
| 34 | + |
| 35 | + screenshots.push(await getChartScreenshot(page, testDir.outputPath("repo1-reference.png"))); |
| 36 | + |
| 37 | + // Get screenshot for repo1 + repo2 |
| 38 | + await page.getByPlaceholder("Username").fill(username); |
| 39 | + await page.getByPlaceholder("Repo name").fill(repo2); |
| 40 | + await page.getByRole("button", { name: "Go!" }).click(); |
| 41 | + await page.getByRole("button", { name: "Go!" }).waitFor({ state: "visible" }); |
| 42 | + |
| 43 | + screenshots.push(await getChartScreenshot(page, testDir.outputPath("repo1and2-reference.png"))); |
| 44 | + |
| 45 | + return screenshots; |
| 46 | + }; |
| 47 | + |
| 48 | + const expectedScreenshots = await takeReferenceScreenshots(); |
| 49 | + |
| 50 | + await page.goto(localUrl); |
| 51 | + |
| 52 | + await authenticate(page); |
| 53 | + |
| 54 | + const screenshots: Buffer[] = []; |
| 55 | + |
| 56 | + // Get stats for repo1 |
| 57 | + await page.getByPlaceholder("Username").fill(username); |
| 58 | + await page.getByPlaceholder("Repo name").fill(repo1); |
| 59 | + await page.getByRole("button", { name: "Go!" }).click(); |
| 60 | + await expect(page.getByRole("button", { name: `${username} / ${repo1}` }).first()).toBeVisible(); |
| 61 | + await expect( |
| 62 | + page.getByRole("gridcell", { name: `${username} / ${repo1}` }).getByRole("button"), |
| 63 | + ).toBeVisible(); |
| 64 | + await expect(page.getByRole("textbox").last()).toHaveValue( |
| 65 | + `${localUrl}preload?r=${username},${repo1}`, |
| 66 | + ); |
| 67 | + screenshots.push(await getChartScreenshot(page, testDir.outputPath("repo1-actual.png"))); |
| 68 | + |
| 69 | + // Get stats for repo2 |
| 70 | + await page.getByPlaceholder("Username").fill(username); |
| 71 | + await page.getByPlaceholder("Repo name").fill(repo2); |
| 72 | + await page.getByRole("button", { name: "Go!" }).click(); |
| 73 | + await expect(page.getByRole("button", { name: `${username} / ${repo1}` }).first()).toBeVisible(); |
| 74 | + await expect(page.getByRole("button", { name: `${username} / ${repo2}` }).first()).toBeVisible(); |
| 75 | + await expect( |
| 76 | + page.getByRole("gridcell", { name: `${username} / ${repo1}` }).getByRole("button"), |
| 77 | + ).toBeVisible(); |
| 78 | + page.getByRole("row").first().first(); |
| 79 | + await expect( |
| 80 | + page.getByRole("gridcell", { name: `${username} / ${repo2}` }).getByRole("button"), |
| 81 | + ).toBeVisible(); |
| 82 | + await expect(page.getByRole("textbox").last()).toHaveValue( |
| 83 | + `${localUrl}preload?r=${username},${repo1}&r=${username},${repo2}`, |
| 84 | + ); |
| 85 | + screenshots.push(await getChartScreenshot(page, testDir.outputPath("repo1and2-actual.png"))); |
| 86 | + |
| 87 | + const comparator = getComparator("image/png"); |
| 88 | + screenshots.forEach((screenshot, index) => { |
| 89 | + expect(comparator(expectedScreenshots[index], screenshot)).toBeNull(); |
| 90 | + }); |
| 91 | + |
| 92 | + const gridStarsCountRepo1 = await getGridStarsCount(1); |
| 93 | + const gridStarsCountRepo2 = await getGridStarsCount(2); |
| 94 | + |
| 95 | + // Sync stats to chart data |
| 96 | + await page.getByLabel("Sync stats to chart zoom level").check(); |
| 97 | + await expect(page.getByText("Date range")).not.toBeVisible(); |
| 98 | + await page.locator(".nsewdrag").scrollIntoViewIfNeeded(); |
| 99 | + const chartBoundingBox = await page.locator(".nsewdrag").boundingBox(); |
| 100 | + expect(chartBoundingBox).not.toBeNull(); |
| 101 | + if (chartBoundingBox) { |
| 102 | + await page.mouse.move( |
| 103 | + chartBoundingBox?.x + chartBoundingBox?.width / 2, |
| 104 | + chartBoundingBox?.y + chartBoundingBox?.height / 2, |
| 105 | + ); |
| 106 | + await page.mouse.down(); |
| 107 | + await page.mouse.move( |
| 108 | + chartBoundingBox?.x + chartBoundingBox?.width / 2 + 150, |
| 109 | + chartBoundingBox?.y + chartBoundingBox?.height / 2, |
| 110 | + ); |
| 111 | + await page.mouse.up(); |
| 112 | + } |
| 113 | + await expect(page.getByText("Date range")).toBeVisible(); |
| 114 | + expect(await getGridStarsCount(1)).toBeLessThan(gridStarsCountRepo1); |
| 115 | + expect(await getGridStarsCount(2)).toBeLessThan(gridStarsCountRepo2); |
| 116 | + |
| 117 | + // Remove repo2 |
| 118 | + await page.getByTestId("CancelIcon").last().click(); |
| 119 | + const screenshotWithRepo1 = await getChartScreenshot( |
| 120 | + page, |
| 121 | + testDir.outputPath("repo1b-actual.png"), |
| 122 | + ); |
| 123 | + expect(comparator(screenshots[0], screenshotWithRepo1)).toBeNull(); |
| 124 | + |
| 125 | + // Remove repo1 |
| 126 | + await page.getByTestId("CancelIcon").last().click(); |
| 127 | + const chartElement = page.locator(".nsewdrag"); |
| 128 | + const gridElement = page.getByRole("gridcell"); |
| 129 | + const downloadDataElement = page.getByText("Download Data"); |
| 130 | + await chartElement.waitFor({ state: "hidden", timeout: 5000 }); |
| 131 | + await gridElement.waitFor({ state: "hidden", timeout: 5000 }); |
| 132 | + await downloadDataElement.waitFor({ state: "hidden", timeout: 5000 }); |
| 133 | + expect(chartElement).not.toBeVisible(); |
| 134 | + expect(gridElement).not.toBeVisible(); |
| 135 | + expect(downloadDataElement).not.toBeVisible(); |
| 136 | +}); |
0 commit comments