Skip to content

Commit

Permalink
feat: data-driven testing for components
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed May 7, 2021
1 parent 806b16a commit 7a24899
Show file tree
Hide file tree
Showing 92 changed files with 16,699 additions and 367 deletions.
2 changes: 1 addition & 1 deletion ui/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"fix": "yarn lint --fix",
"lint": "yarn eslint . --ext mdx,ts,tsx",
"prepare": "yarn build",
"test:create": "cc-cli -g doc -c ./.config -w",
"test:create": "cc-cli -g doc -c ./.config -w -d 5",
"test": "yarn jest"
},
"homepage": "https://github.com/ccontrols/component-controls",
Expand Down
9 changes: 9 additions & 0 deletions ui/components/src/ActionBar/ActionBar.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
overview: {
'0': {},
'1': {},
'2': {},
'3': {},
'4': {},
},
};
28 changes: 18 additions & 10 deletions ui/components/src/ActionBar/ActionBar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,36 @@ import { render, act } from '@testing-library/react';
import { renderErr } from '@component-controls/test-renderers';

import * as examples from './ActionBar.stories';
import data from './ActionBar.data';

describe('ActionBar', () => {
const configPath = path.resolve(__dirname, '../../.config');
const config = loadConfigurations(configPath);
let renderedExamples: ReturnType<typeof renderDocument> = [];
act(() => {
renderedExamples = renderDocument(examples, config);
renderedExamples = renderDocument(examples, config, data);
});
if (!renderedExamples) {
renderErr();
return;
}
renderedExamples.forEach(({ name, rendered }) => {
renderedExamples.forEach(({ name, rendered, dataId, values }) => {
describe(name, () => {
it('snapshot', () => {
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
it('accessibility', async () => {
const axeResults = await reactRunDOM<AxeResults>(rendered, run);
expect(axeResults).toHaveNoAxeViolations();
});
const runTests = () => {
it('snapshot', () => {
const { asFragment } = render(rendered);
expect(asFragment()).toMatchSnapshot();
});
it('accessibility', async () => {
const axeResults = await reactRunDOM<AxeResults>(rendered, run);
expect(axeResults).toHaveNoAxeViolations();
});
};
if (values) {
describe(dataId, runTests);
} else {
runTests();
}
});
});
});
Loading

0 comments on commit 7a24899

Please sign in to comment.