Skip to content

Commit

Permalink
disable some incorrect a11y tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Jun 11, 2024
1 parent f711776 commit 491de28
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: yarn check:i18n-en-fr
- name: Type check
run: yarn typescript
- name: Build Storybook
- name: Run unit tests
run: yarn unit
- name: Build Storybook
run: yarn build-storybook --quiet
Expand Down
38 changes: 2 additions & 36 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import locationFieldHandlers from "../packages/location-field/src/mocks/handlers
import itineraryBodyHandlers from "../packages/itinerary-body/src/__mocks__/handlers";
import geocoderHandlers from "../packages/geocoder/src/test-fixtures/handlers";
import tileLayerHandlers from '../packages/otp2-tile-overlay/src/mocks/handlers'
import parameters from './previewParameters'

import { reactIntl } from './react-intl.ts';
import { Preview } from "@storybook/react";
Expand All @@ -20,42 +21,7 @@ if (typeof global.process === "undefined") {
worker.start({ onUnhandledRequest: "bypass" });
}

export const parameters = {
a11y: {
config: {
rules: [
{
// moved to technical backlog
id: "aria-required-parent",
reviewOnFail: true,
},
{
// Appears to be a story bug
id: "duplicate-id",
reviewOnFail: true
},
{
// Appears to be a story bug
id: "duplicate-id-aria",
reviewOnFail: true
},
{
// Not really applicable to stories and causes problems with the WithMap decorator
id: "landmark-unique",
enabled: false
}
],
},
},
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
reactIntl
};
export { parameters }

const preview: Preview = {
decorators: [mockDateDecorator],
Expand Down
40 changes: 40 additions & 0 deletions .storybook/previewParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { reactIntl } from './react-intl.ts';

const parameters = {
a11y: {
config: {
rules: [
{
// moved to technical backlog
id: "aria-required-parent",
reviewOnFail: true,
},
{
// Appears to be a story bug
id: "duplicate-id",
reviewOnFail: true
},
{
// Appears to be a story bug
id: "duplicate-id-aria",
reviewOnFail: true
},
{
// Not really applicable to stories and causes problems with the WithMap decorator
id: "landmark-unique",
enabled: false
}
],
},
},
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
reactIntl
};

export default parameters;
17 changes: 13 additions & 4 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TestRunnerConfig } from '@storybook/test-runner';
import { injectAxe, checkA11y } from 'axe-playwright';
import { getStoryContext, TestContext, type TestRunnerConfig } from '@storybook/test-runner';
import { injectAxe, checkA11y, configureAxe } from 'axe-playwright';
import { Page } from 'playwright-core'
import parameters from './previewParameters';

const ONLY_RUN = process.env.ONLY_RUN

Expand All @@ -10,7 +11,15 @@ async function runSnapshots(page: Page) {
expect(innerHTML).toMatchSnapshot();
}

async function runA11yTest(page: Page) {
async function runA11yTest(page: Page, context: TestContext) {
// Get the entire context of a story, including parameters, args, argTypes, etc.
const storyContext = await getStoryContext(page, context);

const globalOverrides = parameters.a11y
// Apply story-level a11y rules
await configureAxe(page, {
rules: [...storyContext.parameters?.a11y?.config?.rules, ...globalOverrides.config.rules],
});
await checkA11y(page, '#storybook-root', {
detailedReport: true,
detailedReportOptions: {
Expand All @@ -29,7 +38,7 @@ const config: TestRunnerConfig = {
await runSnapshots(page);
}
if (!ONLY_RUN || ONLY_RUN === "A11Y") {
await runA11yTest(page);
await runA11yTest(page, context);
}
},
};
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"yaml-sort": "^2.0.0"
},
"scripts": {
"a11y-test": "yarn build-storybook && jest --testPathIgnorePatterns packages storybook",
"bootstrap": "lerna bootstrap --use-workspaces",
"build:cjs": "lerna exec --parallel -- babel --extensions '.js,.ts,.tsx' --ignore **/*.story.js,**/*.story.ts,**/*.story.d.ts,**/*.story.tsx,**/*.spec.js,**/*.spec.ts,**/*.test.js,**/*.test.ts,**/__tests__/**,**/__unpublished__/** --root-mode upward --source-maps true src -d lib",
"build:esm": "lerna exec --parallel -- cross-env BABEL_ENV=esm babel --extensions '.js,.ts,.tsx' --ignore **/*.story.js,**/*.story.ts,**/*.story.d.ts,**/*.story.tsx,**/*.spec.js,**/*.spec.ts,**/*.test.js,**/*.test.ts,**/__tests__/**,**/__unpublished__/** --root-mode upward --source-maps true src -d esm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ function OtpRRItineraryBodyWrapper({
export default {
title: "ItineraryBody/otp-react-redux",
component: ItineraryBody,
parameters: { date: new Date("March 10, 2021 10:00:00") }
parameters: {
date: new Date("March 10, 2021 10:00:00"),
a11y: { config: { rules: [{ id: "link-in-text-block", enabled: false }] } }
}
} as Meta;

export const WalkOnlyItinerary = (): ReactElement => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const a11yOverrideParameters = {
export default {
title: "ItineraryBody/otp-ui",
component: ItineraryBody,
parameters: { date: new Date("March 10, 2021 10:00:00") }
parameters: {
date: new Date("March 10, 2021 10:00:00"),
a11y: { config: { rules: [{ id: "link-in-text-block", enabled: false }] } }
}
} as Meta;

export const WalkOnlyItinerary = (): ReactElement => (
Expand Down
8 changes: 6 additions & 2 deletions packages/location-field/src/stories/Desktop.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ const invalidKeyGeocoderConfig = {
const a11yOverrideParameters = {
a11y: {
config: {
// This is a story issue, not a production issue
rules: [{ id: "label", enabled: false }]
rules: [
// This is a story issue, not a production issue
{ id: "label", enabled: false },
// The options don't appear until click
{ id: "aria-required-children", enabled: false }
]
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion packages/stop-viewer-overlay/src/StopViewerOverlay.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const WithCustomMarker = (): JSX.Element => (
const disableA11yParameters = {
a11y: {
config: {
rules: [{ id: "aria-allowed-attr", enabled: false }]
rules: [
{ id: "aria-allowed-attr", enabled: false },
{ id: "aria-prohibited-attr", enabled: false }
]
}
}
};
Expand Down

0 comments on commit 491de28

Please sign in to comment.