Skip to content

Commit

Permalink
Issue #552 Component test card header (#674)
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
tomoversluizen authored and Sjaak Luthart committed Jun 12, 2017
1 parent 2d97399 commit ad3502b
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/card-header/index.test.js
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 = '';
});
});

0 comments on commit ad3502b

Please sign in to comment.