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

Orbit Storybook - a11y issues #4497

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
name: Visual Regression Tests
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.44.1-jammy
image: mcr.microsoft.com/playwright:v1.48.2-jammy
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-visual-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
update-visual-tests:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.44.1-jammy
image: mcr.microsoft.com/playwright:v1.48.2-jammy
Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed the PW version based on this error log.
https://github.com/kiwicom/orbit/actions/runs/11632651461/job/32396199861?pr=4497

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I had to update visual tests as they were failing.

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ cypress/videos
/test-results/
/playwright-report/
/playwright/.cache/
artifacts/
27 changes: 27 additions & 0 deletions packages/orbit-components/.storybook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# About
Copy link
Member Author

@sarkaaa sarkaaa Nov 1, 2024

Choose a reason for hiding this comment

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

I created this file to document somewhere information on how to run test-runner and that's important to run this script once the storybook local server is running as well.

This could be as a point of discussion if we want to have this file, ofc.


Storybook included the list of Orbit components.

URL: https://kiwicom.github.io/orbit/

## Run

**Install dependencies:**

```
yarn install
```

**Run Storybook:**

```
yarn storybook
```

**Run a11y tests:**

This will run test-runner script and generates HTML files with the list of a11y issues. Be aware that the local storybook server must be running as well (`yarn storybook`).

```
yarn test-storybook
```
13 changes: 12 additions & 1 deletion packages/orbit-components/.storybook/orbitDecorator.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this issue still relevant? Do we have problems with the Orbit storybook?

I remember Nitro's Storybook being problematic but Orbit one was working correctly, wasn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, Orbit also has an issue with no-updating a11y issues when switching the stories. however, Orbit is working well after this change, but Nitro is still problematic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's working for me now (Chrome) on master... 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it seems we have different behaviors on different machines and different browsers. What do you think about closing this PR for the time being? We can always re-open it if this becomes annoying again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Recording of my experience:

Screen.Recording.2024-11-14.at.15.43.51.mov

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";
import type { Decorator } from "@storybook/react";
import jsxToString from "react-element-to-jsx-string";
import { Highlight, themes } from "prism-react-renderer";
import { addons } from "@storybook/preview-api";

import defaultTheme from "../src/defaultTheme";
import OrbitProvider from "../src/OrbitProvider";
Expand All @@ -15,8 +16,18 @@ const OrbitDecorator: Decorator = (storyFn, context) => {
React.useEffect(() => {
const html = document.querySelector("html");
if (html && !html.getAttribute("dir")) html.setAttribute("dir", "ltr");
const componentForceRerender = () => {
// Invokes Storybook's addon API method event to trigger a UI refresh.
// Ensures that a11y addons is refreshed and shows the correct list of component accessibility issues.
console.log("Component is being rerendered.");
addons.getChannel().emit("forceReRender");
Copy link
Member Author

Choose a reason for hiding this comment

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

An explanation of the function is described here.

};

componentForceRerender();
return () => {
if (html) html.removeAttribute("dir");
if (html) {
html.removeAttribute("dir");
}
};
}, []);

Expand Down
32 changes: 32 additions & 0 deletions packages/orbit-components/.storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { TestRunnerConfig } from "@storybook/test-runner";
import { injectAxe, checkA11y } from "axe-playwright";

/*
* See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api
Copy link
Member Author

Choose a reason for hiding this comment

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

Using the test-runner and depended packages, we are able to run a11y SB checks and generate an HTML report.

* to learn more about the test-runner hooks API.
*/
const config: TestRunnerConfig = {
async preVisit(page) {
await injectAxe(page);
},
async postVisit(page, story) {
const fileName = story.name.replace(/\s+/g, "");
await checkA11y(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We agreed we don't need the HTML reports for Orbit components, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was done before I was struggling with Nitro, and then we agreed we won't generate HTML reports. I thought that the "agreement" was only for Nitro, anyway, but I can remove it from Orbit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I recall correctly, the final conclusion is that HTML reports were not bringing that much value at this period as problems will be detected with the general Accessibility audits.

I really value your proactivity on exploring this idea, great work! I believe these fine-grained reports could have more utility in the future when we have a higher accessibility score on all the Kiwi.com pages, so we can get more into the details to find problems we don't see at first sight. What do you think?

page,
".story-content",
{
detailedReport: true,
detailedReportOptions: {
html: true,
},
},
undefined,
"html",
{
reportFileName: `${fileName}-result.html`,
},
);
},
};

export default config;
8 changes: 6 additions & 2 deletions packages/orbit-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"storybook": "storybook dev -p 6007 -c .storybook --ci",
"test-storybook": "test-storybook --url http://127.0.0.1:6007",
"cy:dev": "vite cypress/integration --logLevel silent",
"cy:run": "start-server-and-test cy:dev http-get://localhost:3000 'cypress run'",
"cy:open": "start-server-and-test cy:dev http-get://localhost:3000 'cypress open'",
Expand Down Expand Up @@ -89,7 +90,7 @@
"@emotion/core": "^11.0.0",
"@nanostores/react": "^0.2.0",
"@nanostores/router": "^0.3.1",
"@playwright/experimental-ct-react": "^1.44.1",
"@playwright/experimental-ct-react": "^1.48.1",
"@size-limit/webpack-why": "^11.1.4",
"@storybook/addon-a11y": "^8.2.4",
"@storybook/addon-controls": "^8.2.4",
Expand All @@ -102,6 +103,7 @@
"@storybook/react-webpack5": "^8.2.4",
"@storybook/storybook-deployer": "^2.8.16",
"@storybook/theming": "^8.2.1",
"@storybook/test-runner": "^0.19.1",
"@svgr/core": "^6.3.1",
"@svgr/plugin-jsx": "^6.3.1",
"@svgr/plugin-prettier": "^6.3.1",
Expand Down Expand Up @@ -142,6 +144,8 @@
"ttf2woff2": "^4.0.1",
"vite": "^4.5.5",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"axe-playwright": "^2.0.3",
"@playwright/test": "^1.44.1"
}
}
Loading
Loading