mirror of
https://github.com/VladSez/easy-invoice-pdf
synced 2026-04-21 21:47:52 +00:00
* Added URL assertions to ensure correct navigation after page loads in the About, Changelog, Invoice Generator, and Not Found pages. * Updated tests to verify that the expected URLs are displayed after navigating to specific routes, improving test reliability and coverage. * Cleaned up redundant code in invoice form tests and ensured consistent URL checks across all relevant test cases.
86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import {
|
|
INVOICE_PDF_FONTS,
|
|
MARKETING_FEATURES_CARDS,
|
|
STATIC_ASSETS_URL,
|
|
VIDEO_DEMO_FALLBACK_IMG,
|
|
VIDEO_DEMO_URL,
|
|
} from "@/config";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
test.describe("Static assets (fonts, images, videos) should be accessible", () => {
|
|
test("should load static assets successfully", async ({ page }) => {
|
|
// Test video demo URL
|
|
const videoResponse = await page.request.get(VIDEO_DEMO_URL);
|
|
|
|
expect(videoResponse.status()).toBe(200);
|
|
expect(videoResponse.headers()["content-type"]).toContain("video/mp4");
|
|
|
|
// Test video fallback image
|
|
const fallbackImageResponse = await page.request.get(
|
|
VIDEO_DEMO_FALLBACK_IMG,
|
|
);
|
|
expect(fallbackImageResponse.status()).toBe(200);
|
|
expect(fallbackImageResponse.headers()["content-type"]).toContain(
|
|
"image/png",
|
|
);
|
|
|
|
/**
|
|
* Test PDF fonts
|
|
*/
|
|
for (const [, fonts] of Object.entries(INVOICE_PDF_FONTS)) {
|
|
for (const [, fontUrl] of Object.entries(fonts)) {
|
|
const fontResponse = await page.request.get(fontUrl);
|
|
|
|
expect(fontResponse.status()).toBe(200);
|
|
expect(fontResponse.headers()["content-type"]).toContain("font/ttf");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test marketing features cards
|
|
*/
|
|
for (const { videoSrc, videoFallbackImg } of MARKETING_FEATURES_CARDS) {
|
|
const videoResponse = await page.request.get(videoSrc);
|
|
|
|
expect(videoResponse.status()).toBe(200);
|
|
expect(videoResponse.headers()["content-type"]).toContain("video/mp4");
|
|
|
|
const fallbackResponse = await page.request.get(videoFallbackImg);
|
|
|
|
expect(fallbackResponse.status()).toBe(200);
|
|
expect(fallbackResponse.headers()["content-type"]).toContain("image/png");
|
|
}
|
|
});
|
|
|
|
test("no CDN assets fail on app page", async ({ page }) => {
|
|
const failed: string[] = [];
|
|
|
|
// register a response listener to check for failed assets
|
|
page.on("response", (res) => {
|
|
if (res.url().startsWith(STATIC_ASSETS_URL) && !res.ok()) {
|
|
failed.push(`${res.status()} ${res.url()}`);
|
|
}
|
|
});
|
|
|
|
await page.goto("/");
|
|
await expect(page).toHaveURL("/?template=default");
|
|
|
|
expect(failed).toEqual([]);
|
|
});
|
|
|
|
test("no CDN assets fail on about page", async ({ page }) => {
|
|
const failed: string[] = [];
|
|
|
|
// register a response listener to check for failed assets
|
|
page.on("response", (res) => {
|
|
if (res.url().startsWith(STATIC_ASSETS_URL) && !res.ok()) {
|
|
failed.push(`${res.status()} ${res.url()}`);
|
|
}
|
|
});
|
|
|
|
await page.goto("/en/about");
|
|
await expect(page).toHaveURL("/en/about");
|
|
|
|
expect(failed).toEqual([]);
|
|
});
|
|
});
|