Skip to content

Commit

Permalink
Merge branch 'main' into refactor-css
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikSchmidt committed Jan 16, 2025
2 parents c7fba55 + bd13144 commit 6608476
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ lefthook-local.yml
/blob-report/
/playwright/.cache/
/test-results/

# Playwright snapshot testing
*-snapshots/
2 changes: 2 additions & 0 deletions packages/dito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"test": "vitest",
"test:e2e": "playwright test tests/e2e --config=tests/playwright.config.ts",
"test:a11y": "playwright test tests/a11y --config=tests/playwright.config.ts",
"test:snapshots": "playwright test tests/snapshots --config=tests/playwright-snapshots.config.ts",
"test:update-snapshots": "playwright test tests/snapshots --config=tests/playwright-snapshots.config.ts --update-snapshots",
"tests": "vitest run && npm run test:e2e && npm run test:a11y",
"test:generate-coverage": "jest --coverage",
"typecheck": "tsc"
Expand Down
26 changes: 9 additions & 17 deletions packages/dito/tests/e2e/general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@ import { preCheck } from "resources/content";
import * as staticRoutes from "resources/staticRoutes";

test.describe("test general availability", () => {
test.afterEach(async ({ context }) => {
for (const page of context.pages()) {
await page.close();
}
await context.close();
});

test("landing page to not have breadcrumbs", async ({ page }) => {
await page.goto(allRoutes[0].url);
await expect(page.getByTestId("breadcrumbs-menu")).not.toBeVisible();
});

test("all routes are reachable and have a breadcrumb menu + title if they aren't landing page or a PDF", async ({
page,
}) => {
test.setTimeout(90000);
// Remove first page from allRoutes array
for (const route of allRoutes.slice(1)) {
if (route.url.endsWith(".pdf")) {
continue;
}
// Remove landing page
allRoutes.slice(1).forEach((route) => {
if (route.url.endsWith(".pdf")) {
return;
}
test(`${route.url} is reachable and has a breadcrumb menu + title`, async ({
page,
}) => {
await page.goto(route.url, { waitUntil: "networkidle" });
await expect(page.getByTestId("breadcrumbs-menu")).toBeVisible();

Check failure on line 21 in packages/dito/tests/e2e/general.spec.ts

View workflow job for this annotation

GitHub Actions / check-test-build-deploy (dito) / check-and-test-shared / check-and-test

[chromium] › e2e/general.spec.ts:17:5 › test general availability › /unterstuetzung is reachable and has a breadcrumb menu + title

4) [chromium] › e2e/general.spec.ts:17:5 › test general availability › /unterstuetzung is reachable and has a breadcrumb menu + title Error: Timed out 5000ms waiting for expect(locator).toBeVisible() Locator: getByTestId('breadcrumbs-menu') Expected: visible Received: <element(s) not found> Call log: - expect.toBeVisible with timeout 5000ms - waiting for getByTestId('breadcrumbs-menu') 19 | }) => { 20 | await page.goto(route.url, { waitUntil: "networkidle" }); > 21 | await expect(page.getByTestId("breadcrumbs-menu")).toBeVisible(); | ^ 22 | await expect(page).toHaveTitle( 23 | /Digitalcheck: Digitaltaugliche Regelungen erarbeiten$/, 24 | ); at /home/runner/work/digitalcheck-apps/digitalcheck-apps/packages/dito/tests/e2e/general.spec.ts:21:58
await expect(page).toHaveTitle(
/Digitalcheck: Digitaltaugliche Regelungen erarbeiten$/,
);
}
});
});
});

Expand Down
54 changes: 54 additions & 0 deletions packages/dito/tests/playwright-snapshots.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { devices, PlaywrightTestConfig } from "@playwright/test";
import dotenv from "dotenv";
import path from "path";
import { fileURLToPath } from "url";
import baseConfig from "../../../playwright.config-base";

// Get the directory name of the current module
const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: path.resolve(__dirname, "../", ".env.test") });

const desktopViewport = { width: 1200, height: 4800 };

const config: PlaywrightTestConfig = {
...baseConfig,
projects: [
{
name: "Desktop Chrome",
use: {
...devices["Desktop Chrome"],
channel: "chrome",
viewport: desktopViewport,
},
},
{
name: "Desktop Firefox",
use: { ...devices["Desktop Firefox"], viewport: desktopViewport },
},
{
name: "Desktop Safari",
use: { ...devices["Desktop Safari"], viewport: desktopViewport },
},
{
name: "Mobile Chrome",
use: {
...devices["Pixel 7"],
viewport: { ...devices["Pixel 7"].viewport, height: 3200 },
},
},
{
name: "Mobile Safari",
use: {
...devices["iPhone 14 Pro"],
viewport: { ...devices["iPhone 14 Pro"].viewport, height: 3200 },
},
},
],
webServer: {
command: "npm run dev -- --port 5172",
port: 5172,
timeout: parseInt(process.env.WAIT_ON_TIMEOUT ?? `${5 * 1000}`),
},
};

export default config;
34 changes: 34 additions & 0 deletions packages/dito/tests/snapshots/general.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from "@playwright/test";

import allRoutes from "resources/allRoutes";

async function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

test.describe("compare snapshots", () => {
allRoutes
.filter((allRoute) => !allRoute.url.endsWith(".pdf"))
.forEach((route) => {
test(route.title, async ({ page }) => {
// Listen for redirects and update URL if needed
const response = await page.goto(route.url);

if (
(response !== null && response.status() === 302) ||
(response !== null && response.status() === 301)
) {
const redirectedUrl = response.headers()["location"];
await page.goto(redirectedUrl);
}

// wait to finish rendering
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();

// wait to make sure the page is fully rendered
await wait(100);

await expect(page).toHaveScreenshot();
});
});
});

0 comments on commit 6608476

Please sign in to comment.