Skip to content

Commit 0c42294

Browse files
committed
✅ add accessibility tests to drawer
improves coverage
1 parent cf882d1 commit 0c42294

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-disable jsx-a11y/no-static-element-interactions */
2+
/* eslint-disable jsx-a11y/click-events-have-key-events */
3+
import React from 'react';
4+
import { expect } from 'chai';
5+
import { mount } from 'enzyme';
6+
import sinon from 'sinon';
7+
import Drawer from '..';
8+
9+
/* eslint-disable no-undef */
10+
describe('Drawer render tests.', () => {
11+
let wrappedComponent;
12+
let expectedValueBefore;
13+
let expectedValueAfter;
14+
let actualValue;
15+
16+
class Demo extends React.Component {
17+
state = { open: false }
18+
19+
handleDrawer(open) {
20+
this.setState({
21+
open,
22+
});
23+
}
24+
25+
render() {
26+
return (
27+
<div>
28+
<button id="drawerButton" onClick={() => this.handleDrawer(true)}>
29+
click me
30+
</button>
31+
<Drawer open={this.state.open} onClose={() => this.handleDrawer(false)} position="right">
32+
<div>content</div>
33+
</Drawer>
34+
</div>
35+
);
36+
}
37+
}
38+
39+
beforeEach(() => {
40+
wrappedComponent = mount(<Demo />);
41+
});
42+
43+
it('Should close drawer on blur', () => {
44+
expectedValueBefore = true;
45+
expectedValueAfter = false;
46+
actualValue = () => wrappedComponent.find(Drawer).prop('open');
47+
wrappedComponent.find('button#drawerButton').simulate('click');
48+
expect(actualValue()).equal(expectedValueBefore);
49+
wrappedComponent.find(Drawer).simulate('blur');
50+
expect(actualValue()).equal(expectedValueAfter);
51+
});
52+
53+
it('Should get a callback for onClose prop', () => {
54+
expectedValueBefore = 0;
55+
expectedValueAfter = 1;
56+
const onClose = sinon.spy();
57+
wrappedComponent = mount(<Drawer />);
58+
wrappedComponent.setProps({ onClose });
59+
expect(onClose).to.have.property('callCount', expectedValueBefore);
60+
wrappedComponent.find(Drawer).simulate('blur');
61+
expect(onClose).to.have.property('callCount', expectedValueAfter);
62+
});
63+
});

0 commit comments

Comments
 (0)