Skip to content

Commit 8bf613a

Browse files
committed
tests: more coverage
1 parent 4efd464 commit 8bf613a

9 files changed

+116
-22
lines changed

Diff for: tests/Aside.test.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect'
22
import React from 'react'
33
import {renderToStaticMarkup as render} from 'react-dom/server'
44

5-
import { configure, mount } from 'enzyme'
5+
import { configure, mount, shallow } from 'enzyme'
66
import Adapter from 'enzyme-adapter-react-16'
77
import { spy } from 'sinon'
88

@@ -12,7 +12,7 @@ configure({ adapter: new Adapter() });
1212

1313
describe('AppAside', () => {
1414
it('renders aside with class="aside-menu"', () => {
15-
expect(render(<AppAside fixed hidden display="lg">aside</AppAside>))
15+
expect(render(<AppAside fixed hidden offCanvas display="lg">aside</AppAside>))
1616
.toContain('<aside class="aside-menu">aside</aside>')
1717
});
1818
it('calls componentDidMount', () => {
@@ -21,4 +21,14 @@ describe('AppAside', () => {
2121
const wrapper = mount(<AppAside fixed hidden display="lg" />);
2222
expect(AppAside.prototype.componentDidMount.calledOnce).toEqual(true);
2323
});
24-
})
24+
it('should call isHidden()', () => {
25+
const isHidden = spy(AppAside.prototype, 'isHidden');
26+
shallow(<AppAside />);
27+
expect(isHidden.called).toBe(true);
28+
});
29+
it('should call isOffCanvas()', () => {
30+
const isOffCanvas = spy(AppAside.prototype, 'isOffCanvas');
31+
shallow(<AppAside offCanvas={false}/>);
32+
expect(isOffCanvas.called).toBe(true);
33+
});
34+
})

Diff for: tests/Footer.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect'
22
import React from 'react'
33
import {renderToStaticMarkup as render} from 'react-dom/server'
44

5-
import { configure, mount } from 'enzyme'
5+
import { configure, mount, shallow } from 'enzyme'
66
import Adapter from 'enzyme-adapter-react-16'
77
import { spy } from 'sinon'
88

@@ -21,4 +21,10 @@ describe('AppFooter', () => {
2121
const wrapper = mount(<AppFooter fixed display="lg" />);
2222
expect(AppFooter.prototype.componentDidMount.calledOnce).toEqual(true);
2323
});
24-
})
24+
it('should call isFixed()', () => {
25+
const isFixed = spy(AppFooter.prototype, 'isFixed');
26+
shallow(<AppFooter />);
27+
expect(isFixed.called).toBe(true);
28+
});
29+
30+
})

Diff for: tests/Header.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import expect from 'expect'
22
import React from 'react'
33
import {renderToStaticMarkup as render} from 'react-dom/server'
44

5-
import { configure, mount } from 'enzyme'
5+
import { configure, mount, shallow } from 'enzyme'
66
import Adapter from 'enzyme-adapter-react-16'
77
import { spy } from 'sinon'
88

99
import AppHeader from 'src/Header'
10+
import AppFooter from '../src/Footer';
1011

1112
configure({ adapter: new Adapter() });
1213

@@ -21,4 +22,9 @@ describe('AppHeader', () => {
2122
const wrapper = mount(<AppHeader fixed/>);
2223
expect(AppHeader.prototype.componentDidMount.calledOnce).toEqual(true);
2324
});
24-
})
25+
it('should call isFixed()', () => {
26+
const isFixed = spy(AppHeader.prototype, 'isFixed');
27+
shallow(<AppHeader />);
28+
expect(isFixed.called).toBe(true);
29+
});
30+
})

Diff for: tests/NavbarBrand.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ describe('AppNavbarBrand', () => {
1515
minimized={{ src: sygnet, width: 30, height: 30, alt: 'CoreUI Minimized' }}
1616
/>)).toContain('class="navbar-brand"');
1717
});
18+
it('renders anchor with class="navbar-brand"', () => {
19+
expect(render(<AppNavbarBrand
20+
brand={{ }}
21+
/>)).toContain('class="navbar-brand"');
22+
});
23+
it('renders anchor with class="navbar-brand"', () => {
24+
expect(render(<AppNavbarBrand />)).toContain('class="navbar-brand"');
25+
});
26+
1827
});

Diff for: tests/Sidebar.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect'
22
import React from 'react'
33
import {renderToStaticMarkup as render} from 'react-dom/server'
44

5-
import { configure, mount } from 'enzyme'
5+
import { configure, mount, shallow } from 'enzyme'
66
import Adapter from 'enzyme-adapter-react-16'
77
import { spy } from 'sinon'
88

@@ -21,4 +21,9 @@ describe('AppSidebar', () => {
2121
const wrapper = mount(<AppSidebar fixed display="lg" compact minimized offCanvas />);
2222
expect(AppSidebar.prototype.componentDidMount.calledOnce).toBe(true);
2323
});
24+
it('should call isFixed()', () => {
25+
const isFixed = spy(AppSidebar.prototype, 'isFixed');
26+
shallow(<AppSidebar />);
27+
expect(isFixed.called).toBe(true);
28+
});
2429
})

Diff for: tests/SidebarFooter.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ describe('SidebarFooter', () => {
99
expect(render(<SidebarFooter>test</SidebarFooter>))
1010
.toContain('<div class="sidebar-footer">test</div>')
1111
})
12-
})
12+
it('renders no div with class="sidebar-footer"', () => {
13+
expect(render(<SidebarFooter></SidebarFooter>))
14+
.toNotContain('<div class="sidebar-footer"></div>')
15+
})
16+
})

Diff for: tests/SidebarForm.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ describe('AppSidebarForm', () => {
99
expect(render(<AppSidebarForm>test</AppSidebarForm>))
1010
.toContain('<div class="sidebar-form">test</div>')
1111
})
12-
})
12+
it('renders no div with class="sidebar-form"', () => {
13+
expect(render(<AppSidebarForm></AppSidebarForm>))
14+
.toNotContain('<div class="sidebar-form"></div>')
15+
})
16+
})

Diff for: tests/SidebarHeader.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ describe('AppSidebarHeader', () => {
99
expect(render(<AppSidebarHeader>test</AppSidebarHeader>))
1010
.toContain('<div class="sidebar-header">test</div>')
1111
})
12-
})
12+
it('renders no div with class="sidebar-header"', () => {
13+
expect(render(<AppSidebarHeader></AppSidebarHeader>))
14+
.toNotContain('<div class="sidebar-header"></div>')
15+
})
16+
})

Diff for: tests/Switch.test.js

+57-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import expect from 'expect'
22
import React from 'react'
33
import {renderToStaticMarkup as render} from 'react-dom/server'
44

5-
import { configure, mount } from 'enzyme'
5+
import { configure, mount, shallow } from 'enzyme'
66
import Adapter from 'enzyme-adapter-react-16'
7-
import { spy } from 'sinon'
7+
import { spy, mock } from 'sinon'
88

99
import AppSwitch from 'src/Switch'
1010

@@ -15,14 +15,60 @@ describe('AppSwitch', () => {
1515
expect(render(<AppSwitch />))
1616
.toContain('<label class="switch')
1717
});
18-
it('should call toggle', () => {
19-
const onChange = spy(AppSwitch.prototype, 'toggle');
20-
const event = {target: { checked: true }};
21-
const wrapper = mount(<AppSwitch outlineAlt label pill size="lg" />);
22-
expect(wrapper.find('input').props().checked).toBe(false);
23-
wrapper.find('input').simulate('change', event)
24-
expect(onChange.called).toBe(true);
25-
expect(wrapper.find('input').props().checked).toBe(true);
18+
it('should render with switch class', () => {
19+
const wrapper = shallow(<AppSwitch />);
20+
expect(wrapper.hasClass('switch')).toBe(true);
21+
});
22+
it('should render with outline class', () => {
23+
const wrapper = shallow(<AppSwitch outline />);
24+
expect(wrapper.hasClass('switch-outline-secondary')).toBe(true);
25+
});
26+
it('should render with outline alt class', () => {
27+
const wrapper = shallow(<AppSwitch outline={'alt'} />);
28+
expect(wrapper.hasClass('switch-outline-secondary-alt')).toBe(true);
29+
});
30+
it('should render with outline alt class', () => {
31+
const wrapper = shallow(<AppSwitch outline color="primary-alt" />);
32+
expect(wrapper.hasClass('switch-outline-primary-alt')).toBe(true);
33+
});
34+
it('should render with info class', () => {
35+
const wrapper = shallow(<AppSwitch color="info" />);
36+
expect(wrapper.hasClass('switch-info')).toBe(true);
37+
});
38+
it('should render with pill class', () => {
39+
const wrapper = shallow(<AppSwitch variant="pill" />);
40+
expect(wrapper.hasClass('switch-pill')).toBe(true);
41+
});
42+
it('should render with 3d class', () => {
43+
const wrapper = shallow(<AppSwitch variant="3d" />);
44+
expect(wrapper.hasClass('switch-3d')).toBe(true);
45+
});
46+
it('should render with lg class', () => {
47+
const wrapper = shallow(<AppSwitch size="lg" />);
48+
expect(wrapper.hasClass('switch-lg')).toBe(true);
49+
});
50+
it('should render with label class', () => {
51+
const wrapper = shallow(<AppSwitch label />);
52+
expect(wrapper.hasClass('switch-label')).toBe(true);
53+
});
54+
55+
describe('onChange', () => {
56+
it('calls props.onChange if it exists', () => {
57+
const onChangeMock = mock()
58+
const wrapper = mount(<AppSwitch onChange={onChangeMock} />);
59+
wrapper.find('input').hostNodes().simulate('change');
60+
expect(onChangeMock.called).toBe(true);
61+
});
2662

27-
})
63+
it('should call onChange()', () => {
64+
const onChange = spy(AppSwitch.prototype, 'onChange');
65+
const event = { target: { checked: true } };
66+
const wrapper = shallow(<AppSwitch label size="lg" />);
67+
expect(wrapper.find('input').props().checked).toBe(false);
68+
wrapper.find('input').simulate('change', event)
69+
expect(onChange.called).toBe(true);
70+
expect(wrapper.find('input').props().checked).toBe(true);
71+
})
72+
}
73+
)
2874
})

0 commit comments

Comments
 (0)