-
Notifications
You must be signed in to change notification settings - Fork 0
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
Integrate axe-playwright into storybook/test-runner #828
base: main
Are you sure you want to change the base?
Changes from all commits
aff522a
6ce0603
0445c5a
08ab053
e7e470a
caf33a0
99d5ac0
eb9c48e
77cfc42
35dd260
914678e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { getStoryContext } = require('@storybook/test-runner'); | ||
const { injectAxe, checkA11y } = require('axe-playwright'); | ||
/* | ||
* See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api | ||
* to learn more about the test-runner hooks API. | ||
*/ | ||
module.exports = { | ||
async preVisit(page) { | ||
await injectAxe(page); | ||
}, | ||
async postVisit(page, context) { | ||
// Get the entire context of a story, including parameters, args, argTypes, etc. | ||
const storyContext = await getStoryContext(page, context); | ||
|
||
// Do not run a11y tests on disabled stories. | ||
if (storyContext.parameters?.a11y?.disable) { | ||
return; | ||
} | ||
await checkA11y( | ||
page, | ||
'#root', | ||
{ | ||
axeOptions: { | ||
rules: { | ||
// TODO: enable this rule again once all color contrast issues are fixed | ||
'color-contrast': { | ||
enabled: false, | ||
}, | ||
}, | ||
}, | ||
detailedReport: true, | ||
verbose: false, | ||
}, | ||
false, | ||
'v2' | ||
); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,8 +111,21 @@ DefaultOutline.parameters = { | |
], | ||
}; | ||
|
||
const baseTabArgs = { | ||
colorVariant: ['tab'], | ||
role: 'tab', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
|
||
const TabDecorator = (story) => { | ||
const decorator = document.createElement('ul'); | ||
decorator.setAttribute('role', 'tablist'); | ||
decorator.appendChild(story()); | ||
return decorator; | ||
}; | ||
|
||
export const DefaultTab = Template.bind({}); | ||
DefaultTab.args = { colorVariant: ['tab'] }; | ||
DefaultTab.decorators = [TabDecorator]; | ||
DefaultTab.args = { ...baseTabArgs }; | ||
DefaultTab.parameters = { | ||
zeplinLink: [ | ||
{ | ||
|
@@ -771,7 +784,8 @@ OutlinePressed.parameters = { | |
}; | ||
|
||
export const TabPressed = Template.bind({}); | ||
TabPressed.args = { colorVariant: ['tab'], ariaCurrent: 'page' }; | ||
TabPressed.decorators = [TabDecorator]; | ||
TabPressed.args = { ...baseTabArgs, ariaCurrent: 'page' }; | ||
TabPressed.parameters = { | ||
zeplinLink: | ||
'https://app.zeplin.io/styleguide/63079b90d0bf4a646c46c227/components?coid=640094b52890b84043f89ba4', | ||
|
@@ -815,7 +829,8 @@ OutlineDisabled.parameters = { | |
}; | ||
|
||
export const TabDisabled = Template.bind({}); | ||
TabDisabled.args = { colorVariant: ['tab'], disabled: true }; | ||
TabDisabled.decorators = [TabDecorator]; | ||
TabDisabled.args = { ...baseTabArgs, disabled: true }; | ||
TabDisabled.parameters = { | ||
zeplinLink: | ||
'https://app.zeplin.io/styleguide/63079b90d0bf4a646c46c227/components?coid=640094b30ee0b5408ad023fd', | ||
|
@@ -930,7 +945,8 @@ OutlineAnchor.parameters = { | |
}; | ||
|
||
export const TabAnchor = Template.bind({}); | ||
TabAnchor.args = { colorVariant: ['tab'], element: 'anchor' }; | ||
TabAnchor.decorators = [TabDecorator]; | ||
TabAnchor.args = { ...baseTabArgs, element: 'anchor' }; | ||
TabAnchor.parameters = { | ||
zeplinLink: [ | ||
{ | ||
|
@@ -949,8 +965,9 @@ TabAnchor.parameters = { | |
}; | ||
|
||
export const TabAnchorPressed = Template.bind({}); | ||
TabAnchorPressed.decorators = [TabDecorator]; | ||
TabAnchorPressed.args = { | ||
colorVariant: ['tab'], | ||
...baseTabArgs, | ||
element: 'anchor', | ||
ariaCurrent: 'page', | ||
}; | ||
|
@@ -1087,8 +1104,9 @@ OutlineAnchorDisabled.parameters = { | |
}; | ||
|
||
export const TabAnchorDisabled = Template.bind({}); | ||
TabAnchorDisabled.decorators = [TabDecorator]; | ||
TabAnchorDisabled.args = { | ||
colorVariant: ['tab'], | ||
...baseTabArgs, | ||
ariaDisabled: true, | ||
element: 'a', | ||
}; | ||
|
@@ -1144,8 +1162,9 @@ DangerOutlineAnchorDisabled.parameters = { | |
// ***** Icon-only tab buttons ****************** // | ||
|
||
export const TabIconOnlyBase = Template.bind({}); | ||
TabIconOnlyBase.decorators = [TabDecorator]; | ||
TabIconOnlyBase.args = { | ||
colorVariant: ['tab'], | ||
...baseTabArgs, | ||
shapeVariant: ['square'], | ||
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`, | ||
}; | ||
|
@@ -1167,8 +1186,9 @@ TabIconOnlyBase.parameters = { | |
}; | ||
|
||
export const TabIconOnlySelected = Template.bind({}); | ||
TabIconOnlySelected.decorators = [TabDecorator]; | ||
TabIconOnlySelected.args = { | ||
colorVariant: ['tab'], | ||
...baseTabArgs, | ||
shapeVariant: ['square'], | ||
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`, | ||
ariaSelected: true, | ||
|
@@ -1179,8 +1199,9 @@ TabIconOnlySelected.parameters = { | |
}; | ||
|
||
export const TabIconOnlyDisabled = Template.bind({}); | ||
TabIconOnlyDisabled.decorators = [TabDecorator]; | ||
TabIconOnlyDisabled.args = { | ||
colorVariant: ['tab'], | ||
...baseTabArgs, | ||
shapeVariant: ['square'], | ||
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`, | ||
disabled: true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ const menu = ` | |
colorVariant: ['transparent'], | ||
shapeVariant: ['menu'], | ||
children: 'Settings', | ||
element: 'a', | ||
classname: ['u-width-full'], | ||
}).outerHTML | ||
} | ||
</li> | ||
|
@@ -72,7 +72,7 @@ const menu = ` | |
colorVariant: ['transparent'], | ||
shapeVariant: ['menu'], | ||
children: 'Help', | ||
element: 'a', | ||
classname: ['u-width-full'], | ||
}).outerHTML | ||
} | ||
</li> | ||
|
@@ -82,18 +82,17 @@ const menu = ` | |
colorVariant: ['transparent'], | ||
shapeVariant: ['menu'], | ||
children: 'Privacy', | ||
element: 'a', | ||
classname: ['u-width-full'], | ||
}).outerHTML | ||
} | ||
</li> | ||
<li role="separator"></li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #829 |
||
<li> | ||
${ | ||
Button({ | ||
colorVariant: ['transparent'], | ||
shapeVariant: ['menu'], | ||
children: 'Sign out', | ||
element: 'a', | ||
classname: ['u-width-full'], | ||
}).outerHTML | ||
} | ||
</li> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be enbled when working on #814