Skip to content

Commit

Permalink
Test on an available public document
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Nov 17, 2023
1 parent 93cfc0b commit d597d1c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
15 changes: 13 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { defineConfig, devices } from "@playwright/test";
import dotenv from "dotenv";

const environment = process.env.NODE_ENV || "development";

dotenv.config({
path: environment === "development" ? ".env" : `.env.${environment}`,
});

if (environment === "development") {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
}

export default defineConfig({
// Look for test files in the "tests" directory, relative to this configuration file.
Expand Down Expand Up @@ -27,7 +38,6 @@ export default defineConfig({
},

// Options specific to each project.
/*
projects: [
{
name: "chromium",
Expand All @@ -41,6 +51,7 @@ export default defineConfig({
name: "webkit",
use: devices["Desktop Safari"],
},
/* todo configure tests for mobile
{
name: "Mobile Chrome",
use: devices["Pixel 5"],
Expand All @@ -49,6 +60,6 @@ export default defineConfig({
name: "Mobile Safari",
use: devices["iPhone 12"],
},
*/
],
*/
});
73 changes: 50 additions & 23 deletions tests/anonymous/viewer/document.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,64 @@

import { test, expect } from "@playwright/test";

test("basic document test", async ({ page }) => {
// this is on staging; don't delete this document
const title = "FINALSeasonal_allergies_pollen_and_mold_2023__EN_";
const url =
"/documents/20005908-finalseasonal_allergies_pollen_and_mold_2023__en";
await page.goto(url);
const DC_BASE = process.env.DC_BASE;

console.log(page.url());
let document, text;

await expect(page.locator(".sidebar").getByRole("heading")).toHaveText(title);
test.describe("document tests", () => {
// fetch the first available public document as a test case
test.beforeAll(async () => {
const endpoint = new URL(
"api/documents.json?access=public&per_page=1",
DC_BASE,
);

expect(new URL(page.url()).pathname).toBe(url);
const { results } = await fetch(endpoint)
.then((r) => r.json())
.catch(console.error);

await page.getByRole("link", { name: "Original Document (PDF) »" }).click();
document = results[0];

await expect(page.locator("h1")).toHaveText(title);
console.log(`Using test document: ${document.title}`);

await page.getByRole("link", { name: "p. 1" }).click();
const textEndpoint = new URL(
`documents/${document.id}/${document.slug}.txt.json`,
document.asset_url,
);

expect(new URL(page.url()).hash).toEqual("#document/p1");
text = await fetch(textEndpoint).then((r) => r.json());
});

await page
.locator("div")
.filter({ hasText: /^DocumentPlain TextThumbnailSearch Results$/ })
.getByRole("combobox")
.selectOption("text");
test("basic document test", async ({ page }) => {
await page.goto(document.canonical_url);

// check that text view loaded
await expect(page.locator(".text").first()).toHaveText(/^MARCH 2023/);
expect(page.url()).toBe(document.canonical_url);

// switch to thumbnail view, click the first image
await page.getByRole("combobox").selectOption("thumbnail");
await page.locator("img").first().click();
await expect(page.locator(".sidebar").getByRole("heading")).toHaveText(
document.title,
);

await page.getByRole("link", { name: "Original Document (PDF) »" }).click();

await expect(page.locator("h1")).toHaveText(document.title);

await page.getByRole("link", { name: "p. 1" }).click();

expect(new URL(page.url()).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(
text.pages[0].contents,
);

// switch to thumbnail view, click the first image
await page.getByRole("combobox").selectOption("thumbnail");
await page.locator("img").first().click();
});
});

0 comments on commit d597d1c

Please sign in to comment.