Skip to content

Commit 283464f

Browse files
authored
Merge pull request conventional-changelog#82 from verdaccio/4.x-adds-unit-test-for-author-component
chore: adds unit test for <Author/> component
2 parents 8e3e619 + 7c25447 commit 283464f

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

src/components/Author/Author.test.tsx

+67-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,75 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
33

4-
import Author from './Author';
5-
64
describe('<Author /> component', () => {
5+
beforeEach(() => {
6+
jest.resetModules();
7+
});
8+
79
test('should render the component in default state', () => {
10+
const packageMeta = {
11+
latest: {
12+
name: 'verdaccio',
13+
version: '4.0.0',
14+
author: {
15+
name: 'verdaccio user',
16+
17+
url: '',
18+
avatar: 'https://www.gravatar.com/avatar/000000',
19+
},
20+
},
21+
};
22+
23+
jest.doMock('../../pages/version/Version', () => ({
24+
DetailContextConsumer: component => {
25+
return component.children({ packageMeta });
26+
},
27+
}));
28+
29+
const Author = require('./Author').default;
30+
const wrapper = shallow(<Author />);
31+
expect(wrapper.html()).toMatchSnapshot();
32+
});
33+
34+
test('should render the component when there is no author information available', () => {
35+
const packageMeta = {
36+
latest: {
37+
name: 'verdaccio',
38+
version: '4.0.0',
39+
},
40+
};
41+
42+
jest.doMock('../../pages/version/Version', () => ({
43+
DetailContextConsumer: component => {
44+
return component.children({ packageMeta });
45+
},
46+
}));
47+
48+
const Author = require('./Author').default;
49+
const wrapper = shallow(<Author />);
50+
expect(wrapper.html()).toEqual('');
51+
});
52+
53+
test('should render the component when there is no author email', () => {
54+
const packageMeta = {
55+
latest: {
56+
name: 'verdaccio',
57+
version: '4.0.0',
58+
author: {
59+
name: 'verdaccio user',
60+
url: '',
61+
avatar: 'https://www.gravatar.com/avatar/000000',
62+
},
63+
},
64+
};
65+
66+
jest.doMock('../../pages/version/Version', () => ({
67+
DetailContextConsumer: component => {
68+
return component.children({ packageMeta });
69+
},
70+
}));
71+
72+
const Author = require('./Author').default;
873
const wrapper = shallow(<Author />);
974
expect(wrapper.html()).toMatchSnapshot();
1075
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<Author /> component should render the component in default state 1`] = `""`;
3+
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:[email protected][email protected]\\" 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>"`;
4+
5+
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>"`;

0 commit comments

Comments
 (0)