chore: adds unit test for <Author/> component

This commit is contained in:
Ayush Sharma 2019-07-02 21:37:36 +02:00
parent 4746f4070c
commit 531e7579a4
2 changed files with 70 additions and 3 deletions

View File

@ -1,10 +1,75 @@
import React from 'react';
import { shallow } from 'enzyme';
import Author from './Author';
describe('<Author /> component', () => {
beforeEach(() => {
jest.resetModules();
});
test('should render the component in default state', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
author: {
name: 'verdaccio user',
email: 'verdaccio.user@verdaccio.org',
url: '',
avatar: 'https://www.gravatar.com/avatar/000000',
},
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render the component when there is no author information available', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
expect(wrapper.html()).toEqual('');
});
test('should render the component when there is no author email', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
author: {
name: 'verdaccio user',
url: '',
avatar: 'https://www.gravatar.com/avatar/000000',
},
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
expect(wrapper.html()).toMatchSnapshot();
});

View File

@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Author /> component should render the component in default state 1`] = `""`;
exports[`<Author /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-padding-2 MuiList-subheader-4\\"><h3 class=\\"MuiTypography-root-5 MuiTypography-subheading-12 css-hyrz44 e1xuehjw0\\">Author</h3><li class=\\"MuiListItem-root-41 MuiListItem-default-44 MuiListItem-gutters-49 css-z8a2h0 e1xuehjw1\\"><a href=\\"mailto:verdaccio.user@verdaccio.org?subject=verdaccio@4.0.0\\" target=\\"_top\\"><div class=\\"MuiAvatar-root-53\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img-55\\"/></div></a><div class=\\"MuiListItemText-root-56\\"><span class=\\"MuiTypography-root-5 MuiTypography-subheading-12 MuiListItemText-primary-59\\">verdaccio user</span></div></li></ul>"`;
exports[`<Author /> component should render the component when there is no author email 1`] = `"<ul class=\\"MuiList-root-62 MuiList-padding-63 MuiList-subheader-65\\"><h3 class=\\"MuiTypography-root-66 MuiTypography-subheading-73 css-hyrz44 e1xuehjw0\\">Author</h3><li class=\\"MuiListItem-root-102 MuiListItem-default-105 MuiListItem-gutters-110 css-z8a2h0 e1xuehjw1\\"><div class=\\"MuiAvatar-root-114\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img-116\\"/></div><div class=\\"MuiListItemText-root-117\\"><span class=\\"MuiTypography-root-66 MuiTypography-subheading-73 MuiListItemText-primary-120\\">verdaccio user</span></div></li></ul>"`;