forked from negomi/react-burger-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurgerIcon.spec.js
More file actions
154 lines (128 loc) · 4.78 KB
/
BurgerIcon.spec.js
File metadata and controls
154 lines (128 loc) · 4.78 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import { assert, expect } from 'chai';
import createShallowComponent from './utils/createShallowComponent';
import BurgerIcon from '../lib/BurgerIcon';
describe('BurgerIcon component', () => {
let component;
const mockStylesProp = {
bmBurgerButton: {
width: '40px'
},
bmBurgerBars: {
background: 'red'
}
};
it('exists and is not undefined', () => {
assert.isDefined(BurgerIcon, 'BurgerIcon component is defined');
});
describe('when rendered successfully', () => {
beforeEach(() => {
component = createShallowComponent(<BurgerIcon />);
});
it('contains three span elements', () => {
expect(component.props.children[0].props.children).to.have.length(3);
});
it('contains a button element', () => {
expect(component.props.children[1].type).to.equal('button');
});
});
describe('wrapper element', () => {
it('has the correct class', () => {
component = createShallowComponent(<BurgerIcon />);
expect(component.props.className).to.contain('bm-burger-button');
});
it('can be styled with props', () => {
component = createShallowComponent(<BurgerIcon styles={ mockStylesProp } />);
expect(component.props.style.width).to.equal('40px');
});
it('accepts an optional className', () => {
component = createShallowComponent(<BurgerIcon className={ 'custom-class' } />);
expect(component.props.className).to.contain('custom-class');
});
});
describe('visual icon', () => {
let icon;
beforeEach(() => {
component = createShallowComponent(<BurgerIcon />);
icon = component.props.children[0];
});
it('has the correct class', () => {
expect(icon.props.children[0].props.className).to.contain('bm-burger-bars');
expect(icon.props.children[1].props.className).to.contain('bm-burger-bars');
expect(icon.props.children[2].props.className).to.contain('bm-burger-bars');
});
it('accepts an optional barClassName', () => {
component = createShallowComponent(<BurgerIcon barClassName={ 'custom-class' } />);
icon = component.props.children[0];
expect(icon.props.children[0].props.className).to.contain('custom-class');
});
it('has the correct styles', () => {
const expected = {
position: 'absolute',
height: '20%',
top: '0%',
left: 0,
right: 0,
opacity: 1
};
expect(icon.props.children[0].props.style).to.deep.equal(expected);
});
it('can be styled with props', () => {
component = createShallowComponent(<BurgerIcon styles={ mockStylesProp } />);
icon = component.props.children[0];
expect(icon.props.children[0].props.style.background).to.equal('red');
expect(icon.props.children[1].props.style.background).to.equal('red');
expect(icon.props.children[2].props.style.background).to.equal('red');
});
it('can be a custom element', () => {
const element = <img src="icon.jpg" />;
component = createShallowComponent(<BurgerIcon customIcon={ element } />);
expect(component.props.children[0].type).to.equal('img');
expect(component.props.children[0].props.src).to.equal('icon.jpg');
});
});
describe('button', () => {
beforeEach(() => {
component = TestUtils.renderIntoDocument(<BurgerIcon />);
});
it('contains descriptive text', () => {
const button = TestUtils.findRenderedDOMComponentWithTag(component, 'button');
expect(button.innerHTML).to.equal('Open Menu');
});
it('responds to hover events', () => {
const button = TestUtils.findRenderedDOMComponentWithTag(component, 'button');
TestUtils.SimulateNative.mouseOver(button);
expect(component.state.hover).to.be.true;
TestUtils.SimulateNative.mouseOut(button);
expect(component.state.hover).to.be.false;
});
it('behaves correctly when clicked', () => {
let clickHandled = false;
function handleClick() { clickHandled = true; }
component = TestUtils.renderIntoDocument(<BurgerIcon onClick={ handleClick } />);
const button = TestUtils.findRenderedDOMComponentWithTag(component, 'button');
TestUtils.Simulate.click(button);
expect(clickHandled).to.be.true;
});
it('has the correct styles', () => {
component = createShallowComponent(<BurgerIcon />);
const button = component.props.children[1];
const expected = {
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%',
margin: 0,
padding: 0,
border: 'none',
opacity: 0,
fontSize: 8,
cursor: 'pointer'
};
expect(button.props.style).to.deep.equal(expected);
});
});
});