Skip to content

Commit f6e62d9

Browse files
authored
chore: adds tests for action bar component (conventional-changelog#88)
1 parent b6b0ecd commit f6e62d9

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
describe('<ActionBar /> component', () => {
5+
beforeEach(() => {
6+
jest.resetModules();
7+
});
8+
9+
test('should render the component in default state', () => {
10+
const packageMeta = {
11+
latest: {
12+
homepage: 'https://verdaccio.tld',
13+
bugs: {
14+
url: 'https://verdaccio.tld/bugs',
15+
},
16+
dist: {
17+
tarball: 'https://verdaccio.tld/download'
18+
},
19+
},
20+
};
21+
22+
jest.doMock('../../pages/version/Version', () => ({
23+
DetailContextConsumer: component => {
24+
return component.children({ packageMeta });
25+
},
26+
}));
27+
28+
const ActionBar = require('./ActionBar').default;
29+
const wrapper = shallow(<ActionBar />);
30+
expect(wrapper.html()).toMatchSnapshot();
31+
});
32+
33+
test('when there is no action bar data', () => {
34+
const packageMeta = {
35+
latest: {},
36+
};
37+
38+
jest.doMock('../../pages/version/Version', () => ({
39+
DetailContextConsumer: component => {
40+
return component.children({ packageMeta });
41+
},
42+
}));
43+
44+
const ActionBar = require('./ActionBar').default;
45+
const wrapper = shallow(<ActionBar />);
46+
expect(wrapper.html()).toEqual('');
47+
});
48+
});

src/components/ActionBar/ActionBar.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ActionBar extends Component {
4444
);
4545
}
4646

47-
private renderActionBarListItems = packageMeta => {
47+
private renderActionBar = ({ packageMeta }) => {
4848
// @ts-ignore
4949
const { latest: { bugs: { url: issue } = {}, homepage, dist: { tarball } = {} } = {} } = packageMeta;
5050

@@ -68,15 +68,15 @@ class ActionBar extends Component {
6868
return component;
6969
}, []);
7070

71-
return (
72-
<>
73-
<ActionListItem alignItems={'flex-start'}>{renderList}</ActionListItem>
74-
</>
75-
);
76-
};
71+
if (renderList.length > 0) {
72+
return (
73+
<List>
74+
<ActionListItem alignItems={'flex-start'}>{renderList}</ActionListItem>
75+
</List>
76+
);
77+
}
7778

78-
private renderActionBar = ({ packageMeta = {} }) => {
79-
return <List>{this.renderActionBarListItems(packageMeta)}</List>;
79+
return null;
8080
};
8181
}
8282

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<ActionBar /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-padding-2\\"><li class=\\"MuiListItem-root-5 MuiListItem-default-8 MuiListItem-gutters-13 MuiListItem-alignItemsFlexStart-10 css-9q3x3c eux6shq0\\"><a href=\\"https://verdaccio.tld\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z\\"></path><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path></svg></span></button></a><a href=\\"https://verdaccio.tld/bugs\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z\\"></path></svg></span></button></a><a href=\\"https://verdaccio.tld/download\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z\\"></path></svg></span></button></a></li></ul>"`;

0 commit comments

Comments
 (0)