Skip to content

Commit

Permalink
tests: more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xidedix committed Apr 19, 2018
1 parent 4efd464 commit 8bf613a
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 22 deletions.
16 changes: 13 additions & 3 deletions tests/Aside.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'

import { configure, mount } from 'enzyme'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy } from 'sinon'

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

describe('AppAside', () => {
it('renders aside with class="aside-menu"', () => {
expect(render(<AppAside fixed hidden display="lg">aside</AppAside>))
expect(render(<AppAside fixed hidden offCanvas display="lg">aside</AppAside>))
.toContain('<aside class="aside-menu">aside</aside>')
});
it('calls componentDidMount', () => {
Expand All @@ -21,4 +21,14 @@ describe('AppAside', () => {
const wrapper = mount(<AppAside fixed hidden display="lg" />);
expect(AppAside.prototype.componentDidMount.calledOnce).toEqual(true);
});
})
it('should call isHidden()', () => {
const isHidden = spy(AppAside.prototype, 'isHidden');
shallow(<AppAside />);
expect(isHidden.called).toBe(true);
});
it('should call isOffCanvas()', () => {
const isOffCanvas = spy(AppAside.prototype, 'isOffCanvas');
shallow(<AppAside offCanvas={false}/>);
expect(isOffCanvas.called).toBe(true);
});
})
10 changes: 8 additions & 2 deletions tests/Footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'

import { configure, mount } from 'enzyme'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy } from 'sinon'

Expand All @@ -21,4 +21,10 @@ describe('AppFooter', () => {
const wrapper = mount(<AppFooter fixed display="lg" />);
expect(AppFooter.prototype.componentDidMount.calledOnce).toEqual(true);
});
})
it('should call isFixed()', () => {
const isFixed = spy(AppFooter.prototype, 'isFixed');
shallow(<AppFooter />);
expect(isFixed.called).toBe(true);
});

})
10 changes: 8 additions & 2 deletions tests/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'

import { configure, mount } from 'enzyme'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy } from 'sinon'

import AppHeader from 'src/Header'
import AppFooter from '../src/Footer';

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

Expand All @@ -21,4 +22,9 @@ describe('AppHeader', () => {
const wrapper = mount(<AppHeader fixed/>);
expect(AppHeader.prototype.componentDidMount.calledOnce).toEqual(true);
});
})
it('should call isFixed()', () => {
const isFixed = spy(AppHeader.prototype, 'isFixed');
shallow(<AppHeader />);
expect(isFixed.called).toBe(true);
});
})
9 changes: 9 additions & 0 deletions tests/NavbarBrand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ describe('AppNavbarBrand', () => {
minimized={{ src: sygnet, width: 30, height: 30, alt: 'CoreUI Minimized' }}
/>)).toContain('class="navbar-brand"');
});
it('renders anchor with class="navbar-brand"', () => {
expect(render(<AppNavbarBrand
brand={{ }}
/>)).toContain('class="navbar-brand"');
});
it('renders anchor with class="navbar-brand"', () => {
expect(render(<AppNavbarBrand />)).toContain('class="navbar-brand"');
});

});
7 changes: 6 additions & 1 deletion tests/Sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'

import { configure, mount } from 'enzyme'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy } from 'sinon'

Expand All @@ -21,4 +21,9 @@ describe('AppSidebar', () => {
const wrapper = mount(<AppSidebar fixed display="lg" compact minimized offCanvas />);
expect(AppSidebar.prototype.componentDidMount.calledOnce).toBe(true);
});
it('should call isFixed()', () => {
const isFixed = spy(AppSidebar.prototype, 'isFixed');
shallow(<AppSidebar />);
expect(isFixed.called).toBe(true);
});
})
6 changes: 5 additions & 1 deletion tests/SidebarFooter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ describe('SidebarFooter', () => {
expect(render(<SidebarFooter>test</SidebarFooter>))
.toContain('<div class="sidebar-footer">test</div>')
})
})
it('renders no div with class="sidebar-footer"', () => {
expect(render(<SidebarFooter></SidebarFooter>))
.toNotContain('<div class="sidebar-footer"></div>')
})
})
6 changes: 5 additions & 1 deletion tests/SidebarForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ describe('AppSidebarForm', () => {
expect(render(<AppSidebarForm>test</AppSidebarForm>))
.toContain('<div class="sidebar-form">test</div>')
})
})
it('renders no div with class="sidebar-form"', () => {
expect(render(<AppSidebarForm></AppSidebarForm>))
.toNotContain('<div class="sidebar-form"></div>')
})
})
6 changes: 5 additions & 1 deletion tests/SidebarHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ describe('AppSidebarHeader', () => {
expect(render(<AppSidebarHeader>test</AppSidebarHeader>))
.toContain('<div class="sidebar-header">test</div>')
})
})
it('renders no div with class="sidebar-header"', () => {
expect(render(<AppSidebarHeader></AppSidebarHeader>))
.toNotContain('<div class="sidebar-header"></div>')
})
})
68 changes: 57 additions & 11 deletions tests/Switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'

import { configure, mount } from 'enzyme'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy } from 'sinon'
import { spy, mock } from 'sinon'

import AppSwitch from 'src/Switch'

Expand All @@ -15,14 +15,60 @@ describe('AppSwitch', () => {
expect(render(<AppSwitch />))
.toContain('<label class="switch')
});
it('should call toggle', () => {
const onChange = spy(AppSwitch.prototype, 'toggle');
const event = {target: { checked: true }};
const wrapper = mount(<AppSwitch outlineAlt label pill size="lg" />);
expect(wrapper.find('input').props().checked).toBe(false);
wrapper.find('input').simulate('change', event)
expect(onChange.called).toBe(true);
expect(wrapper.find('input').props().checked).toBe(true);
it('should render with switch class', () => {
const wrapper = shallow(<AppSwitch />);
expect(wrapper.hasClass('switch')).toBe(true);
});
it('should render with outline class', () => {
const wrapper = shallow(<AppSwitch outline />);
expect(wrapper.hasClass('switch-outline-secondary')).toBe(true);
});
it('should render with outline alt class', () => {
const wrapper = shallow(<AppSwitch outline={'alt'} />);
expect(wrapper.hasClass('switch-outline-secondary-alt')).toBe(true);
});
it('should render with outline alt class', () => {
const wrapper = shallow(<AppSwitch outline color="primary-alt" />);
expect(wrapper.hasClass('switch-outline-primary-alt')).toBe(true);
});
it('should render with info class', () => {
const wrapper = shallow(<AppSwitch color="info" />);
expect(wrapper.hasClass('switch-info')).toBe(true);
});
it('should render with pill class', () => {
const wrapper = shallow(<AppSwitch variant="pill" />);
expect(wrapper.hasClass('switch-pill')).toBe(true);
});
it('should render with 3d class', () => {
const wrapper = shallow(<AppSwitch variant="3d" />);
expect(wrapper.hasClass('switch-3d')).toBe(true);
});
it('should render with lg class', () => {
const wrapper = shallow(<AppSwitch size="lg" />);
expect(wrapper.hasClass('switch-lg')).toBe(true);
});
it('should render with label class', () => {
const wrapper = shallow(<AppSwitch label />);
expect(wrapper.hasClass('switch-label')).toBe(true);
});

describe('onChange', () => {
it('calls props.onChange if it exists', () => {
const onChangeMock = mock()
const wrapper = mount(<AppSwitch onChange={onChangeMock} />);
wrapper.find('input').hostNodes().simulate('change');
expect(onChangeMock.called).toBe(true);
});

})
it('should call onChange()', () => {
const onChange = spy(AppSwitch.prototype, 'onChange');
const event = { target: { checked: true } };
const wrapper = shallow(<AppSwitch label size="lg" />);
expect(wrapper.find('input').props().checked).toBe(false);
wrapper.find('input').simulate('change', event)
expect(onChange.called).toBe(true);
expect(wrapper.find('input').props().checked).toBe(true);
})
}
)
})

0 comments on commit 8bf613a

Please sign in to comment.