Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
478 changes: 478 additions & 0 deletions __tests__/av_tests.js

Large diffs are not rendered by default.

80 changes: 2 additions & 78 deletions __tests__/test.js → __tests__/image_tests.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
test.skip("Configuration options", () => {});

const puppeteer = require("puppeteer");
const { BASE_URL } = require("../scripts/testBaseUrl");

// Cookbook manifest for viewer control tests
const COOKBOOK_BOUND_MULTIVOLUME_MANIFEST =
"https://iiif.io/api/cookbook/recipe/0031-bound-multivolume/manifest.json";

// PDF manifest for PDF-specific behaviour
const PDF_MULTI_FILE_MANIFEST =
"https://digital.library.villanova.edu/Item/vudl:294631/Manifest";

const viewerUrl = (manifestUrl) => {
//const separator = BASE_URL.includes("#?") ? "&" : "#?";
return `${BASE_URL}#?manifest=${encodeURIComponent(manifestUrl)}`;
Expand Down Expand Up @@ -211,9 +205,8 @@ describe("Universal Viewer", () => {
// COOKBOOK MANIFEST TEST
describe("viewer controls", () => {
beforeEach(async () => {
await page.goto(viewerUrl(COOKBOOK_BOUND_MULTIVOLUME_MANIFEST),
{
waitUntil: "domcontentloaded"
await page.goto(viewerUrl(COOKBOOK_BOUND_MULTIVOLUME_MANIFEST), {
waitUntil: "domcontentloaded",
});
});

Expand Down Expand Up @@ -414,73 +407,4 @@ describe("Universal Viewer", () => {
await page.waitForSelector(moreInfoHeader, { hidden: true });
});
});

// PDF MANIFEST TEST
describe("PDF manifest", () => {
beforeEach(async () => {
await page.goto(viewerUrl(PDF_MULTI_FILE_MANIFEST), {
waitUntil: "domcontentloaded",
});
});

it("loads PDF manifest successfully", async () => {
expect(page.url()).toContain(encodeURIComponent(PDF_MULTI_FILE_MANIFEST));

await page.waitForSelector(".uv", { visible: true });

await page.waitForFunction(() => {
return document.querySelectorAll("iframe").length > 0;
});

const viewerFrame = page.frames().find((f) => {
const url = f.url();

return (
url.includes("uv.html") ||
url.includes("viewer") ||
url.includes("manifest")
);
});

expect(viewerFrame).toBeTruthy();

await viewerFrame.waitForSelector("canvas", { visible: true});

const canvasInfo = await viewerFrame.evaluate(() => {
const canvas = document.querySelector(
"canvas"
);

if (!canvas) return null;
return {
width: canvas.width,
height: canvas.height,
};
});
expect(canvasInfo).not.toBeNull();
expect(canvasInfo.width).toBeGreaterThan(0);
expect(canvasInfo.height).toBeGreaterThan(0);

const pageText = await viewerFrame.evaluate(() => document.body.innerText);

expect(pageText).not.toContain("Unable to load");
expect(pageText).not.toContain("Error loading");
});

it("shows multiple PDF files in the sidebar and allows navigation", async () => {
await page.waitForSelector("button.expandButton", { visible: true });
await page.click("button.expandButton");

await page.waitForSelector(".thumb", { visible: true });

const thumbs = await page.$$(".thumb");

expect(thumbs.length).toBeGreaterThan(1);
await thumbs[1].click();

await page.waitForFunction(() => window.location.href.includes("cv=1"));

expect(page.url()).toContain("cv=1");
});
});
});
142 changes: 142 additions & 0 deletions __tests__/pdf_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
const puppeteer = require("puppeteer");
const { BASE_URL } = require("../scripts/testBaseUrl");

// PDF manifest for PDF-specific behaviour
const PDF_MULTI_FILE_MANIFEST =
"https://digital.library.villanova.edu/Item/vudl:294631/Manifest";

const viewerUrl = (manifestUrl) => {
//const separator = BASE_URL.includes("#?") ? "&" : "#?";
return `${BASE_URL}#?manifest=${encodeURIComponent(manifestUrl)}`;
};

describe("Universal Viewer", () => {
let browser;
let page;

beforeAll(async () => {
browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
page = await browser.newPage();
});

afterAll(async () => {
await browser.close();
});

// PDF MANIFEST TEST
describe("PDF manifest", () => {
beforeEach(async () => {
await page.goto(viewerUrl(PDF_MULTI_FILE_MANIFEST), {
waitUntil: "domcontentloaded",
});
});

it("loads PDF manifest successfully", async () => {
expect(page.url()).toContain(encodeURIComponent(PDF_MULTI_FILE_MANIFEST));

await page.waitForSelector(".uv", { visible: true });

await page.waitForFunction(() => {
return document.querySelectorAll("iframe").length > 0;
});

const viewerFrame = page.frames().find((f) => {
const url = f.url();

return (
url.includes("uv.html") ||
url.includes("viewer") ||
url.includes("manifest")
);
});

expect(viewerFrame).toBeTruthy();

await viewerFrame.waitForSelector("canvas", { visible: true });

const canvasInfo = await viewerFrame.evaluate(() => {
const canvas = document.querySelector("canvas");

if (!canvas) return null;
return {
width: canvas.width,
height: canvas.height,
};
});
expect(canvasInfo).not.toBeNull();
expect(canvasInfo.width).toBeGreaterThan(0);
expect(canvasInfo.height).toBeGreaterThan(0);

const pageText = await viewerFrame.evaluate(
() => document.body.innerText
);

expect(pageText).not.toContain("Unable to load");
expect(pageText).not.toContain("Error loading");
});

it("shows multiple PDF files in the sidebar and allows navigation", async () => {
// In a fresh browser session the left panel opens automatically
// (panelOpen defaults to true), so wait for it rather than clicking
// the expand button, which is only visible while the panel is closed.
await page.waitForSelector(".leftPanel.open", { visible: true });

await page.waitForSelector(".thumb", { visible: true });

const thumbs = await page.$$(".thumb");

expect(thumbs.length).toBeGreaterThan(1);
await thumbs[1].click();

await page.waitForFunction(() => window.location.href.includes("cv=1"));

expect(page.url()).toContain("cv=1");
});

it("can collapse and re-expand the sidebar with the expand button", async () => {
// The sidebar opens automatically, so collapse it first to make the
// expand button available. The open-finished class is toggled once
// the panel animation completes.
await page.waitForSelector(".leftPanel.open-finished", {
visible: true,
});
await page.click(".leftPanel button.collapseButton");

// Collapsed: the panel content hides and the expand button appears.
await page.waitForFunction(() => {
const panel = document.querySelector(".leftPanel");
return panel && !panel.classList.contains("open-finished");
});
await page.waitForSelector(".leftPanel button.expandButton", {
visible: true,
});
await page.waitForSelector(".leftPanel .tabs", { hidden: true });

expect(
await page.$eval(".leftPanel button.expandButton", (btn) =>
btn.getAttribute("aria-expanded")
)
).toBe("false");

await page.click(".leftPanel button.expandButton");

// Expanded again: the panel reopens and the thumbnails are visible.
await page.waitForSelector(".leftPanel.open-finished", {
visible: true,
});
await page.waitForSelector(".thumb", { visible: true });

expect(
await page.$eval(".leftPanel", (el) => el.classList.contains("open"))
).toBe(true);
expect(
await page.$eval(".leftPanel button.expandButton", (btn) =>
btn.getAttribute("aria-expanded")
)
).toBe("true");
});
});
});
14 changes: 5 additions & 9 deletions scripts/testBaseUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ let BASE_URL = "http://localhost:4444";

// environment variable
if (process.env.BASE_URL) {
BASE_URL = process.env.BASE_URL
BASE_URL = process.env.BASE_URL;
}

// local config file
if (fs.existsSync(localConfigPath)) {
try {
const localConfig = JSON.parse(
fs.readFileSync(localConfigPath, "utf8")
);
const localConfig = JSON.parse(fs.readFileSync(localConfigPath, "utf8"));

if (localConfig && localConfig.BASE_URL) {
BASE_URL = localConfig.BASE_URL;
}
}
} catch (err) {
console.warn(
"Invalid testBaseUrl.local.json, using default BASE_URL"
);
console.warn("Invalid testBaseUrl.local.json, using default BASE_URL");
}
}
module.exports = { BASE_URL };
module.exports = { BASE_URL };
Loading