Skip to content

Commit

Permalink
fix: tests without locale prefix and trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviareichl committed Sep 3, 2024
1 parent 4393015 commit 6547ad0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion e2e/lib/fixtures/imprint-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ImprintPage {
this.page = page;
this.locale = locale;
this.i18n = i18n;
this.url = `/${locale}/imprint`;
this.url = `/imprint`;
this.mainContent = page.getByRole("main");
this.title = page.getByRole("heading", { level: 1 });
this.skipLink = page.getByRole("link", { name: i18n.t("DefaultLayout.skip-to-main-content") });
Expand Down
2 changes: 1 addition & 1 deletion e2e/lib/fixtures/index-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class IndexPage {
this.page = page;
this.locale = locale;
this.i18n = i18n;
this.url = `/${locale}`;
this.url = `/`;
this.mainContent = page.getByRole("main");
this.title = page.getByRole("heading", { level: 1 });
this.skipLink = page.getByRole("link", { name: i18n.t("DefaultLayout.skip-to-main-content") });
Expand Down
15 changes: 6 additions & 9 deletions e2e/tests/app/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createUrl } from "@acdh-oeaw/lib";

import { locales } from "@/config/i18n.config";
import { expect, test } from "@/e2e/lib/test";
import { ensureTrailingSlash } from "@/utils/ensure-trailing-slash";
import { escape } from "@/utils/safe-json-ld-replacer";

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -12,10 +13,9 @@ test("should set a canonical url", async ({ createIndexPage }) => {
const { indexPage } = await createIndexPage(locale);
await indexPage.goto();

const canonicalUrl = indexPage.page.locator('link[rel="canonical"]');
await expect(canonicalUrl).toHaveAttribute(
"href",
String(createUrl({ baseUrl, pathname: `/${locale}` })),
const canonicalUrl = await indexPage.page.locator('link[rel="canonical"]').getAttribute("href");
expect(ensureTrailingSlash(String(canonicalUrl))).toBe(
String(createUrl({ baseUrl, pathname: `/` })),
);
}
});
Expand Down Expand Up @@ -74,11 +74,8 @@ test("should set page metadata", async ({ createIndexPage }) => {
const ogDescription = page.locator('meta[property="og:description"]');
await expect(ogDescription).toHaveAttribute("content", i18n.t("Metadata.description"));

const ogUrl = page.locator('meta[property="og:url"]');
await expect(ogUrl).toHaveAttribute(
"content",
String(createUrl({ baseUrl, pathname: `/${locale}` })),
);
const ogUrl = await page.locator('meta[property="og:url"]').getAttribute("content");
expect(ensureTrailingSlash(String(ogUrl))).toBe(String(createUrl({ baseUrl, pathname: `/` })));

const ogLocale = page.locator('meta[property="og:locale"]');
await expect(ogLocale).toHaveAttribute("content", locale);
Expand Down
3 changes: 3 additions & 0 deletions utils/ensure-trailing-slash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function ensureTrailingSlash(url: string): string {
return url.endsWith("/") ? url : `${url}/`;
}

0 comments on commit 6547ad0

Please sign in to comment.