-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* created component test for card-header * Created Card-header component test * Updated test card-header * Updated component test card-header * created component test for card-header * updated card header component test
- Loading branch information
1 parent
2d97399
commit ad3502b
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-env mocha */ | ||
/* eslint react/jsx-filename-extension: [0] */ | ||
import React from 'react'; | ||
import chai, { expect } from 'chai'; | ||
import { shallow } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import CardHeader from '../../src/card-header'; | ||
import getStyles from '../../src/card-header/get-styles'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('CardHeader', () => { | ||
const props = { | ||
style: {}, | ||
titleStyle: {}, | ||
subtitleStyle: {}, | ||
subtitle: null, | ||
avatar: '', | ||
avatarStyle: {} | ||
}; | ||
|
||
beforeEach(() => { | ||
global.navigator = { userAgent: 'all' }; | ||
}); | ||
|
||
afterEach(() => { | ||
global.navigator = undefined; | ||
}); | ||
|
||
it('should always render a header element', () => { | ||
const wrapper = shallow(<CardHeader {...props} />).dive(); | ||
|
||
expect(wrapper.find('header')).to.have.length(1); | ||
}); | ||
|
||
it('should always render a div element', () => { | ||
const wrapper = shallow(<CardHeader {...props} />).dive(); | ||
|
||
expect(wrapper.find('div')).to.have.length(1); | ||
}); | ||
|
||
it('should always render a h1 element', () => { | ||
const wrapper = shallow(<CardHeader {...props} />).dive(); | ||
|
||
expect(wrapper.find('h1')).to.have.length(1); | ||
}); | ||
|
||
it('should not render a h2 element if the subtitle prop is not passed', () => { | ||
const wrapper = shallow(<CardHeader {...props} />).dive(); | ||
|
||
expect(wrapper.find('h2')).to.have.length(0); | ||
}); | ||
|
||
it('should render a h2 element if the subtitle prop is passed', () => { | ||
props.subtitle = 'text'; | ||
const wrapper = shallow(<CardHeader {...props} />).dive(); | ||
|
||
expect(wrapper.find('h2')).to.have.length(1); | ||
expect(wrapper.containsMatchingElement(<h2>text</h2>)).to.equal(true); | ||
props.subtitle = ''; | ||
}); | ||
|
||
it('should get root styles', () => { | ||
const spy = sinon.spy(getStyles, 'root'); | ||
|
||
shallow(<CardHeader {...props} />).dive(); | ||
expect(spy).to.have.been.calledWith(props.style); | ||
}); | ||
|
||
it('should get title styles', () => { | ||
const spy = sinon.spy(getStyles, 'title'); | ||
|
||
shallow(<CardHeader {...props} />).dive(); | ||
expect(spy).to.have.been.calledWith(props.style); | ||
}); | ||
|
||
it('should get subtitle styles', () => { | ||
const spy = sinon.spy(getStyles, 'subtitle'); | ||
props.subtitle = 'text'; | ||
|
||
shallow(<CardHeader {...props} />).dive(); | ||
expect(spy).to.have.been.calledWith(props.subtitleStyle); | ||
props.subtitle = ''; | ||
}); | ||
}); |