-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.spec.js
executable file
·60 lines (55 loc) · 1.7 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from 'react';
import { shallow, mount } from 'enzyme';
import MenuBar from '.';
const menuOptions = (onClick, onOptionClick = jest.fn()) => [
{
title: 'file',
options: [
{ title: 'open', onClick, className: 'testButton' },
{
title: 'find',
onOptionClick,
className: 'testOption',
options: [{ title: 'test', onClick }],
},
],
},
];
describe('MenuBar', () => {
it('renders', () => {
const wrapper = shallow(<MenuBar />);
expect(wrapper.find('menu').length).toBeTruthy();
});
it('renders button and standard menu if passed props', () => {
const options = menuOptions(jest.fn());
const wrapper = mount(<MenuBar className="MenuBar" options={options} />);
expect(wrapper.find('AbstractButton').length).toBeTruthy();
expect(wrapper.find('StandardMenu').length).toBeTruthy();
});
it('cant call onclick on button with option', () => {
const func = jest.fn();
const options = menuOptions(jest.fn(), func);
const wrapper = mount(<MenuBar className="MenuBar" options={options} />);
expect(wrapper.find('.testOption').length).toBeTruthy();
wrapper
.find('.testButton')
.at(0)
.find('button')
.at(0)
.simulate('click');
expect(func).not.toHaveBeenCalled();
});
it('can call onclick prop child option', () => {
const func = jest.fn();
const options = menuOptions(func);
const wrapper = mount(<MenuBar className="MenuBar" options={options} />);
expect(wrapper.find('.testButton').length).toBeTruthy();
wrapper
.find('.testButton')
.at(0)
.find('button')
.at(0)
.simulate('click');
expect(func).toHaveBeenCalled();
});
});