From 37886d869881d6192246de56e3456cef69840b92 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Wed, 15 Nov 2023 14:54:31 -0500 Subject: [PATCH] Viewer test --- .github/workflows/test.yml | 4 +-- .gitignore | 1 + plugins/test/index.js | 12 ++++++--- tests/anonymous/viewer/document.spec.js | 36 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/anonymous/viewer/document.spec.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37c823012..ecf7ec911 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ on: branches: [master] jobs: - build: + test: runs-on: ubuntu-latest steps: @@ -20,7 +20,7 @@ jobs: with: node-version: "18.x" - run: npm ci - - run: npm run build --if-present + - run: npm run build env: NODE_ENV: production - run: npm test diff --git a/.gitignore b/.gitignore index e2a59a3be..86da8a731 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ public/assets/ .env.test .env.sentry-build-plugin playwright-report +test-results .vscode diff --git a/plugins/test/index.js b/plugins/test/index.js index 55e3fbc7e..401e44169 100644 --- a/plugins/test/index.js +++ b/plugins/test/index.js @@ -2,10 +2,16 @@ export async function onSuccess({ utils }) { console.log("Installing Playwright dependencies"); - await utils.run("playwright", ["install"]); + await utils.run("playwright", ["install"]).catch((err) => { + utils.build.failBuild(err); + }); console.log("Running Playwright tests"); - await utils.run("playwright", ["test"]); + result = await utils.run("playwright", ["test"]).catch((err) => { + utils.build.failBuild(err); + }); - console.log("Done."); + utils.status.show({ + title: "Playwright tests completed.", + }); } diff --git a/tests/anonymous/viewer/document.spec.js b/tests/anonymous/viewer/document.spec.js new file mode 100644 index 000000000..842f86bc6 --- /dev/null +++ b/tests/anonymous/viewer/document.spec.js @@ -0,0 +1,36 @@ +// @ts-check + +import { test, expect } from "@playwright/test"; + +test("test", async ({ page }) => { + // this is on staging; don't delete this document + const title = "FINALSeasonal_allergies_pollen_and_mold_2023__EN_"; + const url = + "/documents/20000007-finalseasonal_allergies_pollen_and_mold_2023__en"; + await page.goto(url); + + await expect(page.locator(".sidebar").getByRole("heading")).toHaveText(title); + + await page.getByRole("link", { name: "Original Document (PDF) ยป" }).click(); + + await expect(page.locator("h1")).toHaveText(title); + + await page.getByRole("link", { name: "p. 1" }).click(); + + const currentUrl = new URL(page.url()); + + expect(currentUrl.hash).toEqual("#document/p1"); + + await page + .locator("div") + .filter({ hasText: /^DocumentPlain TextThumbnailSearch Results$/ }) + .getByRole("combobox") + .selectOption("text"); + + // check that text view loaded + await expect(page.locator(".text").first()).toHaveText(/^MARCH 2023/); + + // switch to thumbnail view, click the first image + await page.getByRole("combobox").selectOption("thumbnail"); + await page.locator("img").first().click(); +});