forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(*): add a11y tests and some a11y fix
- Loading branch information
Showing
10 changed files
with
302 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import Checkbox from '../../src/checkbox/index'; | ||
import { unmount, testReact } from '../util/a11y/validate'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
/* eslint-disable no-undef, react/jsx-filename-extension */ | ||
describe('Checkbox A11y', () => { | ||
let wrapper; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = null; | ||
} | ||
unmount(); | ||
}); | ||
|
||
it('should not have any violations for grouped checkbox with children', async () => { | ||
wrapper = await testReact( | ||
<Checkbox.Group value={['pear', 'watermelon']}> | ||
<Checkbox id="apple" value="apple" className="apple"> | ||
苹果 | ||
</Checkbox> | ||
<Checkbox id="pear" value="pear"> | ||
梨子 | ||
</Checkbox> | ||
<Checkbox id="watermelon" value="watermelon"> | ||
西瓜 | ||
</Checkbox> | ||
</Checkbox.Group> | ||
); | ||
return wrapper; | ||
}); | ||
|
||
it('should not have any violations for grouped checkbox with datasource', async () => { | ||
const list = [ | ||
{ | ||
value: 'apple', | ||
label: '苹果', | ||
}, | ||
{ | ||
value: 'pear', | ||
label: '梨', | ||
}, | ||
{ | ||
value: 'orange', | ||
label: '橙子', | ||
}, | ||
]; | ||
wrapper = await testReact( | ||
<Checkbox.Group value={['pear']} dataSource={list} /> | ||
); | ||
return wrapper; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import assert from 'power-assert'; | ||
import Grid from '../../src/grid'; | ||
import { unmount, testReact } from '../util/a11y/validate'; | ||
|
||
/* eslint-disable react/jsx-filename-extension */ | ||
/* global describe it beforeEach afterEach */ | ||
|
||
const { Row, Col } = Grid; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Row a11y', () => { | ||
let wrapper; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = null; | ||
} | ||
unmount(); | ||
}); | ||
|
||
it('should not have any violations', async () => { | ||
wrapper = await testReact( | ||
<div role="grid"> | ||
<Row> | ||
<Col span={6}>1</Col> | ||
<Col span={6}>2</Col> | ||
<Col span={6}>3</Col> | ||
<Col span={6}>4</Col> | ||
</Row> | ||
<Row> | ||
<Col span={6} offset={6}> | ||
1 | ||
</Col> | ||
<Col span={6} offset={6}> | ||
2 | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
return wrapper; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import ReactTestUtils from 'react-dom/test-utils'; | ||
import Enzyme, { mount, shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import simulateEvent from 'simulate-event'; | ||
import assert from 'power-assert'; | ||
import sinon from 'sinon'; | ||
import Range from '../../src/range/index'; | ||
import { unmount, testReact } from '../util/a11y/validate'; | ||
|
||
/* eslint-disable react/no-multi-comp */ | ||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Range A11y', () => { | ||
let wrapper; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = null; | ||
} | ||
unmount(); | ||
}); | ||
it('should not have any violations for range without tips', async () => { | ||
wrapper = await testReact( | ||
<div> | ||
<Range | ||
defaultValue={10} | ||
hasTip={false} | ||
tooltipVisible={false} | ||
/> | ||
</div> | ||
); | ||
return wrapper; | ||
}); | ||
|
||
/** | ||
* TODO: 'aria-expanded' is added by 'Overlay' by default which conflicts with `role = slider` with respect to a11y standards. | ||
* To fix this will require structural change, ignore temporarily. | ||
*/ | ||
it.skip('should not have any violations for range with tips', async () => { | ||
wrapper = await testReact( | ||
<div> | ||
<Range | ||
defaultValue={512} | ||
hasTip={true} | ||
tooltipVisible={true} | ||
min={0} | ||
max={1024} | ||
step={128} | ||
marks={[0, 1024]} | ||
/> | ||
</div> | ||
); | ||
return wrapper; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import sinon from 'sinon'; | ||
import assert from 'power-assert'; | ||
import Switch from '../../src/switch/index'; | ||
import { unmount, testReact } from '../util/a11y/validate'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Switch A11y', () => { | ||
let wrapper; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = null; | ||
} | ||
unmount(); | ||
}); | ||
it('should not have any violations for different states', async () => { | ||
wrapper = await testReact( | ||
<div> | ||
<Switch checked /> | ||
<Switch defaultChecked={false} size="small" /> | ||
</div> | ||
); | ||
return wrapper; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount, render } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import Tab from '../../src/tab/index'; | ||
import '../../src/tab/style.js'; | ||
import { unmount, testReact } from '../util/a11y/validate'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Tab a11y', () => { | ||
let wrapper; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
wrapper = null; | ||
} | ||
unmount(); | ||
}); | ||
it('should not have any violations for tab with children', async () => { | ||
wrapper = await testReact( | ||
<Tab> | ||
<Tab.Item title="foo" /> | ||
</Tab> | ||
); | ||
return wrapper; | ||
}); | ||
it('should not have any violations for tab with datasource', async () => { | ||
const panes = [1, 2, 3, 4, 5].map((item, index) => ( | ||
<Tab.Item title={`item ${item}`} key={index} /> | ||
)); | ||
wrapper = await testReact(<Tab animation={false}>{panes}</Tab>); | ||
return wrapper; | ||
}); | ||
}); |