Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatar component test #675

Merged
merged 4 commits into from
Jun 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions test/avatar/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* 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 Avatar from '../../src/avatar';
import getStyles from '../../src/avatar/get-styles';

chai.use(sinonChai);

describe('Avatar.index', () => {
const props = {
style: {},
status: '',
statusStyle: {},
image: 'imageurl'
};

beforeEach(() => {
global.navigator = { userAgent: 'all' };
});

afterEach(() => {
global.navigator = undefined;
});

it('should always render a section element', () => {
const wrapper = shallow(<Avatar {...props} />).dive();

expect(wrapper.find('section')).to.have.length(1);
});

it('should not render a div element if the status prop is not passed', () => {
const wrapper = shallow(<Avatar {...props} />).dive();

expect(wrapper.find('div')).to.have.length(0);
});

it('should render a div element if the status prop is passed', () => {
props.status = 'online';
const wrapper = shallow(<Avatar {...props} />).dive();

expect(wrapper.find('div')).to.have.length(1);
props.status = '';
});

it('should get root styles', () => {
const spy = sinon.spy(getStyles, 'root');

shallow(<Avatar {...props} />).dive();
expect(spy).to.have.been.calledWith(props.image, props.style);
});

it('should get status styles', () => {
props.status = 'online';
const spy = sinon.spy(getStyles, 'status');

shallow(<Avatar {...props} />).dive();
expect(spy).to.have.been.calledWith(props.status, props.statusStyle);
props.status = '';
});
});