Skip to content

Commit

Permalink
Use document fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeseast committed Nov 20, 2023
1 parent 23045c6 commit af8d693
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public/assets/
playwright-report
test-results

# local fixtures, everyone should generate their own
tests/fixtures/development.json

.vscode

scratch/
68 changes: 30 additions & 38 deletions tests/anonymous/viewer/document.spec.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
// @ts-check

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

const DC_BASE = process.env.DC_BASE;

let document, text;

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,
import fs from "node:fs/promises";
import { test as base, expect } from "@playwright/test";

const {
DC_BASE = "https://api.dev.documentcloud.org",
NODE_ENV = "development",
} = process.env;

const test = base.extend({
document: async ({ page }, use) => {
const filename = new URL(
`../../fixtures/${NODE_ENV}.json`,
import.meta.url,
);

const { results } = await fetch(endpoint)
.then((r) => r.json())
.catch(console.error);

document = results[0];

console.log(`Using test document: ${document.title}`);
const documents = await fs
.readFile(filename)
.then((s) => JSON.parse(s.toString()));

const textEndpoint = new URL(
`documents/${document.id}/${document.slug}.txt.json`,
document.asset_url,
);

text = await fetch(textEndpoint)
.then((r) => r.json())
.catch((e) => {
console.error(e);
console.error(textEndpoint);
});
});
await use(documents[0]);
},
});

test("basic document test", async ({ page }) => {
await page.goto(document.canonical_url);
test.describe("document tests", () => {
test("basic document test", async ({ page, document }) => {
// canonical will point to a URL that might not exist on staging
const path = new URL(document.canonical_url).pathname;
await page.goto(path).catch(console.error);

expect(page.url()).toBe(document.canonical_url);
expect(new URL(page.url()).pathname).toBe(path);

await expect(page.locator(".sidebar").getByRole("heading")).toHaveText(
document.title,
Expand All @@ -59,9 +49,11 @@ test.describe("document tests", () => {
.selectOption("text");

// check that text view loaded
await expect(page.locator(".text").first()).toHaveText(
text.pages[0].contents,
);
/*
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");
Expand Down
158 changes: 158 additions & 0 deletions tests/fixtures/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
[
{
"id": 1,
"access": "public",
"admin_noindex": false,
"asset_url": "https://s3.documentcloud.org/",
"canonical_url": "https://www.documentcloud.org/documents/1-a-i-g-bailout-the-inspector-generals-report",
"created_at": "2010-02-22T19:48:08.738905Z",
"data": {},
"description": "Neil Barofsky's report concludes that officials overseeing the rescue of the American International Group might have overpaid other banks to wrap up A.I.G.'s financial obligations.",
"edit_access": false,
"file_hash": "",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 47,
"page_spec": "612.0x792.0:0-46",
"projects": [
46386,
6
],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "a-i-g-bailout-the-inspector-generals-report",
"source": "Office of the Special Inspector General for T.A.R.P.",
"status": "success",
"title": "A.I.G. Bailout: The Inspector General's Report",
"updated_at": "2020-11-10T16:23:31.154198Z",
"user": 1
},
{
"id": 2,
"access": "public",
"admin_noindex": false,
"asset_url": "https://s3.documentcloud.org/",
"canonical_url": "https://www.documentcloud.org/documents/2-president-obamas-health-care-proposal",
"created_at": "2010-02-22T19:57:44.131650Z",
"data": {},
"description": "On Feb. 22, 2010, the Obama Administration released a detailed proposal outlining the President's plan for a compromise among the House and Senate versions of a health care bill, and Republican concerns.",
"edit_access": false,
"file_hash": "",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 11,
"page_spec": "612.0x792.0:0-10",
"projects": [],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "president-obamas-health-care-proposal",
"source": "whitehouse.gov",
"status": "success",
"title": "President Obama's Health Care Proposal",
"updated_at": "2020-11-10T16:23:31.180653Z",
"user": 1
},
{
"id": 3,
"access": "public",
"admin_noindex": false,
"asset_url": "https://s3.documentcloud.org/",
"canonical_url": "https://www.documentcloud.org/documents/3-shaping-the-next-economic-expansion",
"created_at": "2010-02-22T20:13:31.180904Z",
"data": {},
"description": "A speech delivered by Lawrence Summers to the New York Economic Club on October 29, 2009. ",
"edit_access": false,
"file_hash": "",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 7,
"page_spec": "612.0x792.0:0-6",
"projects": [
46386,
6
],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "shaping-the-next-economic-expansion",
"source": "New York Economic Club",
"status": "success",
"title": "Shaping the Next Economic Expansion",
"updated_at": "2020-11-10T16:23:31.160644Z",
"user": 1
},
{
"id": 4,
"access": "public",
"admin_noindex": false,
"asset_url": "https://s3.documentcloud.org/",
"canonical_url": "https://www.documentcloud.org/documents/4-inspector-generals-report-on-medicare-prescription-fraud",
"created_at": "2010-02-22T20:16:51.842446Z",
"data": {},
"description": "Daniel Levinson's report concludes that federal health officials need to cooperate better with fraud investigations, and that the government should require private insurers to report all instances of suspected fraud.",
"edit_access": false,
"file_hash": "",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 31,
"page_spec": "612.0x792.0:0-26,28-30;616.7999877929688x795.1199951171875:27",
"projects": [
2,
9352
],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "inspector-generals-report-on-medicare-prescription-fraud",
"source": "Department of Health and Human Services",
"status": "success",
"title": "Inspector General's Report on Medicare Prescription Fraud",
"updated_at": "2020-11-10T16:23:31.160353Z",
"user": 1
},
{
"id": 5,
"access": "public",
"admin_noindex": false,
"asset_url": "https://s3.documentcloud.org/",
"canonical_url": "https://www.documentcloud.org/documents/5-wiretapping-lawsuits-thrown-out",
"created_at": "2010-02-22T21:22:53.524125Z",
"data": {},
"description": "In this ruling, Judge Vaughn R. Walker throws out dozens of lawsuits claiming that the nation's largest telecommunications companies illegally assisted in the government's wiretapping program.",
"edit_access": false,
"file_hash": "",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 46,
"page_spec": "612.0x792.0:0-45",
"projects": [
2
],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "wiretapping-lawsuits-thrown-out",
"source": "United States District Court for Northern California",
"status": "success",
"title": "Wiretapping Lawsuits Thrown Out",
"updated_at": "2020-11-10T16:23:31.159780Z",
"user": 1
}
]
60 changes: 60 additions & 0 deletions tests/fixtures/staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"id": 20005908,
"access": "public",
"admin_noindex": false,
"asset_url": "https://documentcloud-staging-files.s3.amazonaws.com/",
"canonical_url": "https://www.staging.documentcloud.org/documents/20005908-finalseasonal_allergies_pollen_and_mold_2023__en",
"created_at": "2023-03-21T20:33:35.857475Z",
"data": {},
"description": "",
"edit_access": false,
"file_hash": "f776f2148c685d7d67aef0082f1d430dfe4bbe17",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 9,
"page_spec": "612.0x792.0000610351562:0-8",
"projects": [],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "finalseasonal_allergies_pollen_and_mold_2023__en",
"source": "",
"status": "success",
"title": "FINALSeasonal_allergies_pollen_and_mold_2023__EN_",
"updated_at": "2023-09-18T16:56:04.839073Z",
"user": 100012
},
{
"id": 20006188,
"access": "public",
"admin_noindex": false,
"asset_url": "https://documentcloud-staging-files.s3.amazonaws.com/",
"canonical_url": "https://www.staging.documentcloud.org/documents/20006188-change-assessment_w_mjw-letter",
"created_at": "2023-10-25T17:39:22.192849Z",
"data": {},
"description": "",
"edit_access": false,
"file_hash": "0ee61c995723d434b710f89d95a2681b56a0f30c",
"noindex": false,
"language": "eng",
"organization": 1,
"original_extension": "pdf",
"page_count": 24,
"page_spec": "612.0x792.0:0-23",
"projects": [],
"publish_at": null,
"published_url": "",
"related_article": "",
"revision_control": false,
"slug": "change-assessment_w_mjw-letter",
"source": "",
"status": "success",
"title": "Change-assessment_w_MJW-letter",
"updated_at": "2023-11-20T16:02:35.301271Z",
"user": 100012
}
]

0 comments on commit af8d693

Please sign in to comment.