diff --git a/src/addons/dispatch/Selection.svelte b/src/addons/dispatch/Selection.svelte index e4eec64d1..6522bcf6e 100644 --- a/src/addons/dispatch/Selection.svelte +++ b/src/addons/dispatch/Selection.svelte @@ -92,7 +92,7 @@ bind:group={choice} /> {$_("addonDispatchDialog.labelSelected", { - values: { n: $layout.selected.length }, + values: { n: $layout.selected?.length }, })} {/if} diff --git a/src/addons/dispatch/fields/ArrayField.svelte b/src/addons/dispatch/fields/ArrayField.svelte index d0acb27e5..f193ecf36 100644 --- a/src/addons/dispatch/fields/ArrayField.svelte +++ b/src/addons/dispatch/fields/ArrayField.svelte @@ -15,8 +15,8 @@ }; export let count: number = 1; - export let value = Array(count).fill(null); + $: numItems = value.length; // only one level of nesting allowed diff --git a/src/api/document.js b/src/api/document.js index 4ad5158f0..7414d0eea 100644 --- a/src/api/document.js +++ b/src/api/document.js @@ -73,7 +73,7 @@ export async function searchDocumentsUrl(url) { async function searchDocumentsHelper(url) { const { data } = await session.get(url); - if (data.results.length > 0 && data.results[0].hasOwnProperty("document")) { + if (data.results?.length > 0 && data.results[0].hasOwnProperty("document")) { // if we are using the project API, the document is one level down data.results = filterDeleted( data.results.map((doc) => new Document(doc.document)), @@ -112,7 +112,7 @@ export async function getDocumentsWithIds( GET_BATCH, GET_BATCH_DELAY, async (subIds) => { - if (subIds.length == 0) return []; + if (subIds?.length == 0) return []; // Return documents with the specified ids const params = { expand, id__in: subIds }; if (remaining) params["remaining"] = true; diff --git a/src/pages/FlatPage.svelte b/src/pages/FlatPage.svelte index 215bbc08f..5ce6af438 100644 --- a/src/pages/FlatPage.svelte +++ b/src/pages/FlatPage.svelte @@ -26,7 +26,13 @@ } function navTo(hash, smooth = false) { - const elem = document.querySelector(hash); + let elem; + try { + elem = document.querySelector(hash); + } catch (error) { + elem = null; + } + if (elem) { if (elem.scrollIntoView) { elem.scrollIntoView({ diff --git a/tests/README.md b/tests/README.md index c3e497fce..1fce016a4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -6,4 +6,4 @@ This directory includes [Playwright](https://playwright.dev) tests that run in a URL=https://www.dev.documentcloud.org npx playwright test ``` -Netlify will automatically run this against any pull request using a deploy preview, and it will set the `URL` environment variable to the correct target. +Github will automatically run this against any pull request using a deploy preview, and it will set the `URL` environment variable to the correct target. diff --git a/tests/anonymous/manager/app.spec.js b/tests/anonymous/manager/app.spec.js index 5d02c4903..41703742b 100644 --- a/tests/anonymous/manager/app.spec.js +++ b/tests/anonymous/manager/app.spec.js @@ -2,11 +2,43 @@ import { test, expect } from "@playwright/test"; -test("basic manager rendering", async ({ page }) => { - await page.goto("/app"); +test.describe("manager tests", () => { + test("rendering", async ({ page }) => { + await page.goto("/app"); - const url = new URL(page.url()); - expect(url.pathname).toBe("/app"); + const url = new URL(page.url()); + expect(url.pathname).toBe("/app"); - await expect(page).toHaveTitle("DocumentCloud"); + await expect(page).toHaveTitle("DocumentCloud"); + + // anonymous message header + await expect( + page.getByRole("heading", { + name: "Welcome to DocumentCloud, an open document archive from MuckRock!", + }), + ).toBeVisible(); + + // close the overlay + await page.getByRole("button").nth(3).click(); + + // can we see documents? + await expect(page.locator(".outer > div").first()).toBeVisible(); + }); + + test("menus", async ({ page }) => { + await page.goto("/app"); + + // help + await page.getByText("Help ▼").click(); + await expect(page.getByRole("button", { name: "FAQ" })).toBeVisible(); + + // close the menu + await page.locator(".shim").click(); + + // language + await page.getByText("Language ▼").click(); + await expect(page.getByRole("button", { name: "English ✓" })).toBeVisible(); + + await page.locator(".shim").click(); + }); }); diff --git a/tests/anonymous/pages/home.spec.js b/tests/anonymous/pages/home.spec.js index 08cf99803..699c9aecc 100644 --- a/tests/anonymous/pages/home.spec.js +++ b/tests/anonymous/pages/home.spec.js @@ -6,4 +6,12 @@ test("basic homepage test", async ({ page }) => { await page.goto("/home"); await expect(page).toHaveTitle("Home | DocumentCloud"); + + // go to the app + await page.getByRole("banner").getByRole("link").first().click(); + + // and back + await page.getByRole("link", { name: "Home" }).click(); + + await expect(page).toHaveTitle("Home | DocumentCloud"); }); diff --git a/tests/anonymous/viewer/document.spec.js b/tests/anonymous/viewer/document.spec.js index 01c11840b..69c6aacb9 100644 --- a/tests/anonymous/viewer/document.spec.js +++ b/tests/anonymous/viewer/document.spec.js @@ -49,11 +49,7 @@ 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()).toBeVisible(); // switch to thumbnail view, click the first image await page.getByRole("combobox").selectOption("thumbnail");