Skip to content

Commit

Permalink
fix: wait for portals to be visible in a11y tests (#1006)
Browse files Browse the repository at this point in the history
* fix: wait for portals to be visible in a11y tests

* fix: undo local change
  • Loading branch information
Niznikr authored Sep 19, 2023
1 parent a570a53 commit b9d044e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
25 changes: 15 additions & 10 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isChromatic from 'chromatic';
import { MotionConfig } from 'framer-motion';
import React from 'react';

import '../packages/tokens/dist/index.css';
Expand Down Expand Up @@ -64,22 +65,26 @@ export const decorators = [
case 'side-by-side': {
document.documentElement.setAttribute('data-theme', 'default');
return (
<div style={{ display: 'flex', flexDirection: 'row', minHeight: '100vh' }}>
<div style={{ width: '50vw', padding: '1rem' }}>
<StoryFn />
</div>
<div data-theme="dark" style={{ width: '50vw', padding: '1rem' }}>
<StoryFn />
<MotionConfig reducedMotion="user">
<div style={{ display: 'flex', flexDirection: 'row', minHeight: '100vh' }}>
<div style={{ width: '50vw', padding: '1rem' }}>
<StoryFn />
</div>
<div data-theme="dark" style={{ width: '50vw', padding: '1rem' }}>
<StoryFn />
</div>
</div>
</div>
</MotionConfig>
);
}
default: {
document.documentElement.setAttribute('data-theme', theme);
return (
<div style={{ padding: '1rem' }}>
<StoryFn />
</div>
<MotionConfig reducedMotion="user">
<div style={{ padding: '1rem' }}>
<StoryFn />
</div>
</MotionConfig>
);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^6.0.0",
"fast-glob": "^3.3.0",
"framer-motion": "10.16.1",
"husky": "^8.0.1",
"jsdom": "^22.1.0",
"lint-staged": "^14.0.0",
Expand Down
4 changes: 4 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export default defineConfig({
use: devices['Desktop Chrome'],
},
],
use: {
screenshot: 'only-on-failure',
testIdAttribute: 'data-test-id',
},
});
18 changes: 18 additions & 0 deletions playwright/a11y.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ test.describe('Storybook a11y', async () => {

for (const story of stories) {
test(`${story}`, async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });

await page.goto(
`${process.env.STORYBOOK_URL}iframe.html?args=&globals=theme:side-by-side&id=${story}&viewMode=story`
);
Expand All @@ -35,6 +37,22 @@ test.describe('Storybook a11y', async () => {
const root = page.locator('#storybook-root');
await root.waitFor();

await page.waitForLoadState('domcontentloaded');

const portal = page.locator('[data-test-id="portal"]');

if ((await portal.count()) > 0) {
const content = page
.locator('[data-test-id="portal"] [style*="opacity"]:not([role="presentation"])')
.first();

await content.waitFor();

await expect
.poll(() => content.evaluate((node) => getComputedStyle(node).opacity))
.toBe('1');
}

const accessibilityScanResults = await new AxeBuilder({ page })
.options({
runOnly: {
Expand Down
18 changes: 6 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9d044e

Please sign in to comment.