Skip to content

Commit

Permalink
Merge branch 'develop' into chore--vpat
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasialanz authored Jan 20, 2024
2 parents 9bc7d2c + 1346041 commit e5c48c2
Show file tree
Hide file tree
Showing 10 changed files with 1,465 additions and 1,137 deletions.
9 changes: 0 additions & 9 deletions packages/react/__tests__/axe.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/react/__tests__/axe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { JestAxe, configureAxe } from 'jest-axe';

const axe: JestAxe = configureAxe({
rules: {
region: { enabled: false }
}
});

export default axe;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import '@testing-library/jest-dom';
import 'jest-axe/extend-expect';

configure({ adapter: new Adapter() });
Expand Down
64 changes: 0 additions & 64 deletions packages/react/__tests__/src/components/Button/index.js

This file was deleted.

14 changes: 10 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@
"@rollup/plugin-dynamic-import-vars": "^1.4.2",
"@rollup/plugin-typescript": "^11.1.2",
"@svgr/rollup": "^6.1.2",
"@testing-library/react": "11.1.2",
"@testing-library/jest-dom": "^6.1.3",
"@types/classnames": "^2.2.10",
"@types/node": "^17.0.42",
"@types/react": "^18.0.12",
"@types/react-dom": "^18.0.5",
"@types/jest-axe": "^3.5.4",
"@types/jest": "^24.7.1",
"@types/react-syntax-highlighter": "^15.5.2",
"@types/enzyme-adapter-react-16": "^1.0.9",
"autoprefixer": "^9.7.6",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-transform-export-extensions": "^6.22.0",
Expand Down Expand Up @@ -85,21 +90,22 @@
"functions": 85,
"lines": 85,
"exclude": [
"dist",
"lib",
"coverage",
"test/**/*.js"
]
},
"jest": {
"setupFilesAfterEnv": [
"<rootDir>__tests__/setupTests.js"
"<rootDir>__tests__/setupTests.ts"
],
"testMatch": [
"**/__tests__/src/**/*.js",
"**/__tests__/demo/**/*.js"
"**/__tests__/demo/**/*.js",
"**/src/components/**/*.test.tsx"
],
"collectCoverageFrom": [
"**/src/**/*.{ts,tsx}"
"src/**/*.{ts,tsx}"
],
"moduleNameMapper": {
"\\.(css|less)$": "<rootDir>/__tests__/styleMock.js",
Expand Down
9 changes: 9 additions & 0 deletions packages/react/src/axe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { JestAxe, configureAxe } from 'jest-axe';

const axe: JestAxe = configureAxe({
rules: {
region: { enabled: false }
}
});

export default axe;
78 changes: 78 additions & 0 deletions packages/react/src/components/Button/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Button from '../../../src/components/Button';
import Icon from '../../../src/components/Icon';
import axe from '../../axe';

test('should render primary button', () => {
render(
<>
<Button>default primary</Button>
<Button variant="primary">variant primary</Button>
</>
);
expect(screen.getByRole('button', { name: 'default primary' })).toHaveClass(
'Button--primary'
);
expect(screen.getByRole('button', { name: 'variant primary' })).toHaveClass(
'Button--primary'
);
});

test('should render secondary button', () => {
render(<Button variant="secondary">secondary</Button>);
const SecondaryButton = screen.getByRole('button', { name: 'secondary' });
expect(SecondaryButton).toHaveClass('Button--secondary');
});

test('should render error button', () => {
render(<Button variant="error">error</Button>);
const ErrorButton = screen.getByRole('button', { name: 'error' });
expect(ErrorButton).toHaveClass('Button--error');
});

test('should render button as link', () => {
render(<Button variant="link">link</Button>);
const LinkButton = screen.getByRole('button', { name: 'link' });
expect(LinkButton).toHaveClass('Link');
});

test('should render button as tag', () => {
render(<Button variant="tag">tag</Button>);
const TagButton = screen.getByRole('button', { name: 'tag' });
expect(TagButton).toHaveClass('Tag');
});

test('should handle <Icon /> as child', () => {
render(
<Button>
<Icon type="trash" />
Delete
</Button>
);
const button = screen.getByRole('button', { name: 'Delete' }).firstChild;
expect(button).toHaveClass('Icon--trash');
});

test('should handle "thin" modifier', () => {
render(<Button thin>link</Button>);
const button = screen.getByRole('button', { name: 'link' });
expect(button).toHaveClass('Button--thin');
});

test('should return no axe violations', async () => {
const { container } = render(
<>
<Button>primary</Button>
<Button variant="primary">primary</Button>
<Button variant="link">link</Button>
<Button>
<Icon type="bolt" />
scan
</Button>
</>
);

const results = await axe(container);
expect(results).toHaveNoViolations();
});
2 changes: 1 addition & 1 deletion packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"],
"include": ["src/**/*", "__tests__/setupTests.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
"skipLibCheck": true
Expand Down
Loading

0 comments on commit e5c48c2

Please sign in to comment.