Skip to content

Commit

Permalink
Merge pull request #347 from MuckRock/188-more-tests
Browse files Browse the repository at this point in the history
More tests
  • Loading branch information
eyeseast authored Nov 21, 2023
2 parents eb4ae50 + 62e541c commit 8f7f8de
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/addons/dispatch/Selection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
bind:group={choice}
/>
{$_("addonDispatchDialog.labelSelected", {
values: { n: $layout.selected.length },
values: { n: $layout.selected?.length },
})}
</label>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion src/addons/dispatch/fields/ArrayField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/api/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/pages/FlatPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
42 changes: 37 additions & 5 deletions tests/anonymous/manager/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
8 changes: 8 additions & 0 deletions tests/anonymous/pages/home.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
6 changes: 1 addition & 5 deletions tests/anonymous/viewer/document.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 8f7f8de

Please sign in to comment.