Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Check code examples with axe #3168

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TabletIcon,
} from "@navikt/aksel-icons";
import { HStack } from "@navikt/ds-react";
import { SEO } from "../seo/SEO";
import styles from "./examples.module.css";

type withDsT = {
Expand Down Expand Up @@ -75,23 +76,26 @@ export const withDsExample = (
};

return (
<div
className={cl(styles.container, {
[styles.containerDefault]: !variant,
[styles.containerStatic]: variant === "static",
[styles.containerFull]: variant === "full",
[styles.containerStaticFull]: variant === "static-full",
})}
style={{ background: getBg(background) }}
>
{showBreakpoints && <BreakpointText />}
<div
id="ds-example"
className={variant === "static" ? styles.exampleStatic : undefined}
<>
<SEO title="Kodeeksempel" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SEO manglet kanskje her? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La til den fordi axe klaget på at <title> manglet.

<main
className={cl(styles.container, {
[styles.containerDefault]: !variant,
[styles.containerStatic]: variant === "static",
[styles.containerFull]: variant === "full",
[styles.containerStaticFull]: variant === "static-full",
})}
style={{ background: getBg(background) }}
>
<Component {...props} />
</div>
</div>
{showBreakpoints && <BreakpointText />}
<div
id="ds-example"
className={variant === "static" ? styles.exampleStatic : undefined}
>
<Component {...props} />
</div>
</main>
</>
);
};

Expand Down
37 changes: 32 additions & 5 deletions aksel.nav.no/website/e2e/axe.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
import AxeBuilder from "@axe-core/playwright";
import { expect, test } from "@playwright/test";
import urls from "./sitemap-urls.json";
import { getDirectories } from "../scripts/update-examples/parts/get-directories";
import { getFiles } from "../scripts/update-examples/parts/get-files";

//import urls from "./sitemap-urls.json";

const examples = getDirectories("eksempler");

test.describe("Axe a11y", () => {
for (const url of urls) {
for (const example of examples) {
const testFiles = getFiles(example.path, "eksempler");

for (const testFile of testFiles.files) {
const url = `/eksempler/${example.path}/${testFile.replace(".tsx", "")}`;

test(`Check page ${url}`, async ({ page }) => {
await page.goto(`http://localhost:3000${url}`);
//await page.waitForLoadState("domcontentloaded");
const a11yScanResults = await new AxeBuilder({
page,
})
.disableRules(["page-has-heading-one"])
.analyze();
expect(a11yScanResults.violations).toEqual([]);
});
}
}

// TODO: Ser ikke ut som axe plukker opp page-attributtet på button i Pagination...
// TODO: Templates

/* for (const url of urls) {
test(`Check page ${url}`, async ({ page }) => {
await page.goto(`http://localhost:3000${url}`);
await page.waitForLoadState("domcontentloaded");
const accessibilityScanResults = await new AxeBuilder({ page })
const a11yScanResults = await new AxeBuilder({ page })
.disableRules(["definition-list", "scrollable-region-focusable"])
.exclude("iframe")
.exclude("#aksel-expansioncard")
.exclude("#toc-scroll")
.exclude("#toc-scroll")
.exclude(".aksel-codesnippet")
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
expect(a11yScanResults.violations).toEqual([]);
});
}
} */
});

/*
Expand Down
7 changes: 5 additions & 2 deletions aksel.nav.no/website/pages/eksempler/pagination/sizes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ const Example = () => {
count={9}
boundaryCount={1}
siblingCount={1}
aria-label="Paginering medium"
/>

<Pagination
size="small"
page={pageState}
onPageChange={setPageState}
count={9}
boundaryCount={1}
siblingCount={1}
size="small"
aria-label="Paginering small"
/>

<Pagination
size="xsmall"
page={pageState}
onPageChange={setPageState}
count={9}
boundaryCount={1}
siblingCount={1}
size="xsmall"
aria-label="Paginering xsmall"
/>
</VStack>
);
Expand Down
11 changes: 6 additions & 5 deletions aksel.nav.no/website/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";
import path from "path";

const smoketestMatcher = /smoketest(-\w+)?\.test\.ts/;
//const smoketestMatcher = /smoketest(-\w+)?\.test\.ts/;
/**
* See https://playwright.dev/docs/test-configuration.
*/
Expand Down Expand Up @@ -46,10 +46,11 @@ const config: PlaywrightTestConfig = {
...devices["Desktop Chrome"],
},
...(process.env.FULL_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to have the same test suite run for both cases, we could also just remove this FULL_TEST env var.

? { testMatch: [/.*\.e2e\.(ts|tsx)/] }
: { testMatch: [smoketestMatcher, /search.e2e.ts/] }),
? { testMatch: [/axe\.e2e\.(ts|tsx)/] }
: { testMatch: [/axe.e2e.ts/] }),
},
{
// TODO: Revert all changes to this file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this is WIP stuff? (there's a lot of comments that we could probably strip as well before this goes live / un-draft the PR) :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this branch is WIP and not ready for review. But ideas/suggestions are welcome!

/* {
name: "Safari",
use: {
...devices["Desktop Safari"],
Expand All @@ -62,7 +63,7 @@ const config: PlaywrightTestConfig = {
...devices["iPhone 12"],
},
testMatch: [smoketestMatcher],
},
}, */

/* {
name: "firefox",
Expand Down
Loading