Skip to content

Commit

Permalink
feat: deque's axe-core ally testing plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 14, 2020
1 parent 58bf9f3 commit e05e65f
Show file tree
Hide file tree
Showing 37 changed files with 1,920 additions and 543 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- [Props info](#props-info)
- [@component-controls/react-docgen-info](#component-controlsreact-docgen-info)
- [@component-controls/react-docgen-typescript-info](#component-controlsreact-docgen-typescript-info)
- [Plugins](#plugins)
- [@component-controls/axe-plugin](#component-controlsaxe-plugin)
- [Miscellaneous](#miscellaneous)
- [@component-controls/storybook-custom-docs](#component-controlsstorybook-custom-docs)

Expand Down Expand Up @@ -330,6 +332,32 @@ Extract props info from react typescript components:

<!-- END-PACKAGE-SECTION -->

# Plugins

<package-section file="./misc/axe-plugin/README.md" section="overview" />

<!-- START-PACKAGE-SECTION -->

## [@component-controls/axe-plugin](https://github.com/ccontrols/component-controls/blob/master/misc/axe-plugin)

Axe ally plugin for component-contols

Accessibility testing plugin using the [axe-core](https://github.com/dequelabs/axe-core) library from [deque](https://www.deque.com/axe/)

Some of the design goals:

- Test at the component-level.
- Provide a dashboard view to quickly see the errors and tests for the compnnt.
- Ability to select and outline the sub-elements generating the errors.
- Ability to see details from the errors and passed rules.
- Ability to review the rendered story right next to the testing panels.

<p align="center">
<img src="https://github.com/ccontrols/component-controls/raw/master/misc/axe-plugin/images/axe-ally-testing.gif" alt="ally tests with axe plugin" width="738">
</p>

<!-- END-PACKAGE-SECTION -->

# Miscellaneous

<package-section file="./misc/storybook-custom-docs/README.md" section="overview" />
Expand Down
7 changes: 4 additions & 3 deletions core/instrument/src/babel/csf-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export const extractCSFStories = (
node.right.type === 'ObjectExpression'
) {
const storyName = node.left.object.name;
const attributes = extractAttributes(node.right);
const { name = storyName } = attributes;
const { name = storyName, ...attributes } = extractAttributes(
node.right,
);
globals[storyName] = {
...attributes,
name,
Expand All @@ -92,8 +93,8 @@ export const extractCSFStories = (
);
const story: Story = {
...attributes,
name,
...store.stories[storyName],
name,
};
if (attrComponents.length > 0) {
story.component = attrComponents[0];
Expand Down
7 changes: 5 additions & 2 deletions integrations/storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ _PropsTable [source code](https:/github.com/ccontrols/component-controls/tree/ma
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `extraColumns` | _Column&lt;{}>\[]_ | extra custom columns passed to the PropsTable. |
| `visibility` | _ComponentVisibility_ | by default will show both controls and props tables user setting can display only props table or only controls |
| `onSelect` | _((event: SyntheticEvent&lt;HTMLDivElement, Event>) => void) \| ((name: string, component: StoryComponent) => boolean \| void)_ | callback to be called when the tab changes if the function returns false, it can stop chabging to the new tab |
| `onSelect` | _((name: string, component: StoryComponent) => boolean \| void) \| ((event: SyntheticEvent&lt;HTMLDivElement, Event>) => void)_ | callback to be called when the tab changes if the function returns false, it can stop chabging to the new tab |
| `of` | _any_ | Specify the component(s), for which to have information displayed. The default, a value of \`"."\` will indicate to display information for the current component (associated with the current Story). If an array of components is specified, each component will be displayed in a separate tab. |
| `title` | _string_ | optional section title for the block. |
| `description` | _string_ | optional markdown description. |
Expand All @@ -582,9 +582,12 @@ _PropsTable [source code](https:/github.com/ccontrols/component-controls/tree/ma
| `itemsLabel` | _string_ | string label for 'items' - used in the filter placeholder and grouping header. |
| `groupBy` | _string\[]_ | field to be grouped by. |
| `hiddenColumns` | _string\[]_ | list of columns to hide. |
| `rowSelect` | _boolean_ | if true, will enable row selection |
| `initialSelected` | _Record&lt;number, boolean>_ | initially selected rows |
| `onSelectRowsChange` | _(selected: Record&lt;number, boolean>) => void_ | callback when selected rows change |
| `expanded` | _{ \[key: string]: boolean; }_ | object listing the initially expanded rows. |
| `skipPageReset` | _boolean_ | reset state update while update table data |
| `renderRowSubComponent` | _(props: { row: Row&lt;{}>; }) => ReactNode_ | |
| `renderRowSubComponent` | _(props: { row: Row&lt;{}>; }) => ReactNode_ | callback to render a SubComponent row |

## <ins>Stories</ins>

Expand Down
21 changes: 21 additions & 0 deletions misc/axe-plugin/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Atanas Stoyanov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
135 changes: 135 additions & 0 deletions misc/axe-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Table of contents

- [In action](#in-action)
- [Overview](#overview)
- [Getting Started](#getting-started)
- [Install](#install)
- [Configure](#configure)
- [Pages format](#pages-format)
- [Examples](#examples)
- [Simple page](#simple-page)
- [API](#api)
- [<ins>AxeAllyBlock</ins>](#insaxeallyblockins)

# In action

[Example site](https://components-storybook-6-no-docs.netlify.app)

# Overview

Accessibility testing plugin using the [axe-core](https://github.com/dequelabs/axe-core) library from [deque](https://www.deque.com/axe/)

Some of the design goals:

- Test at the component-level.
- Provide a dashboard view to quickly see the errors and tests for the compnnt.
- Ability to select and outline the sub-elements generating the errors.
- Ability to see details from the errors and passed rules.
- Ability to review the rendered story right next to the testing panels.

<p align="center">
<img src="https://github.com/ccontrols/component-controls/raw/master/misc/axe-plugin/images/axe-ally-testing.gif" alt="ally tests with axe plugin" width="738">
</p>

# Getting Started

## Install

```sh
yarn add @component-controls/axe-plugin --dev
```

## Configure

The axe-plugin is already installed part of [testing page](https://github.com/ccontrols/component-controls/blob/master/ui/pages/src/TestingPage/TestingPage.tsx) and you can also add it to any other documentation page:

```
import {...} from '@component-controls/blocks';
import { AxeAllyBlock } from '@component-controls/axe-plugin';
export const TestingCustomePage= () => (
<>
<EditPage />
<Title />
<Subtitle />
<Description />
<Playground title=".">
<Story id="." />
</Playground>
<PropsTable of="." title="Controls" visibility="controls" />
<AxeAllyBlock title="A11y tests" />
</>
);
```

## Pages format

The page definition files need to have a default export with the following fields

```js
import React from 'react';
export default {
// key used for navigation
key: string,
// title of the tab
title: string,
// react render function.
// active boolean - if the tab custom page is active
// storyId as a string
// Return an object that can be rendered from ReactDOM.render
render: ({ active, storyId }) => Element,
}
```

## Examples

### Simple page

```js
import React from 'react';
import { DocsContainer, Story} from '@storybook/addon-docs/blocks';
import { useContext, } from '@component-controls/storybook-custom-docs';

const Page = () => {
const context = useContext();
return (
<DocsContainer context={context}><Story id={storyId}/></DocsContainer>
)
}
export default {
key: 'docs-page',
title: 'Docs Page',
render: ({ active, storyId }) => {
return active ? <Page storyId={storyId} /> : null;
}
}
```

# API

<react-docgen-typescript path="./src" exclude="AllyDashboard.tsx,BaseAllyBlock.tsx,HighlightSelector.tsx,NodesTable.tsx,ResultsTable.tsx,SelectionContext.tsx" />

<!-- START-REACT-DOCGEN-TYPESCRIPT -->

## <ins>AxeAllyBlock</ins>

Story block container that displays displays the [axe](https://github.com/dequelabs/axe-core) ally test results

_AxeAllyBlock [source code](https:/github.com/ccontrols/component-controls/tree/master/misc/axe-plugin/src/index.tsx)_

### properties

| Name | Type | Description |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `axeOptions` | _Spec_ | |
| `id` | _string_ | id of the story optional id to be used for the block if no id is provided, one will be calculated automatically from the title. |
| `name` | _string_ | alternatively you can use the name of a story to load from an external file |
| `title` | _string_ | optional section title for the block. |
| `description` | _string_ | optional markdown description. |
| `collapsible` | _boolean_ | if false, will nothave a collapsible frame. |
| `sxStyle` | _SystemStyleObject_ | theme-ui styling object for Block Box |

<!-- END-REACT-DOCGEN-TYPESCRIPT -->
Binary file added misc/axe-plugin/images/axe-ally-testing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions misc/axe-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@component-controls/axe-plugin",
"version": "1.1.0",
"description": "Axe ally plugin for component-contols",
"keywords": [
"addon",
"storybook"
],
"main": "dist/index.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"files": [
"dist/",
"package.json",
"README.md",
"preset.js"
],
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
"dev": "yarn cross-env NODE_ENV=development rollup -cw",
"docs": "ts-node -O '{\"module\": \"commonjs\"}' ../../scripts/docs.ts",
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
"test": "yarn jest --passWithNoTests"
},
"homepage": "https://github.com/ccontrols/component-controls",
"bugs": {
"url": "https://github.com/ccontrols/component-controls/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/ccontrols/component-controls.git",
"directory": "misc/axe-plugin"
},
"license": "MIT",
"dependencies": {
"@component-controls/blocks": "^1.1.0",
"@component-controls/components": "^1.1.0",
"@primer/octicons-react": "^9.6.0",
"axe-core": "^3.5.3",
"react": "^16.12.0",
"react-google-charts": "^3.0.15",
"theme-ui": "^0.3.1"
},
"devDependencies": {
"@types/react": "^16.9.34",
"typescript": "^3.8.3"
},
"peerDependencies": {
"@component-controls/blocks": "*",
"react": "*",
"theme-ui": "*"
},
"publishConfig": {
"access": "public"
},
"authors": [
"Atanas Stoyanov"
],
"gitHead": "c5145d66c6b8a355839e53c3bca97fd361ce9377"
}
5 changes: 5 additions & 0 deletions misc/axe-plugin/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { config } from '../../rollup-config';

export default config({
input: ['./src/index.ts'],
});
Loading

0 comments on commit e05e65f

Please sign in to comment.