diff --git a/src/components/ActionBar/ActionBar.test.tsx b/src/components/ActionBar/ActionBar.test.tsx new file mode 100644 index 0000000..8c22f84 --- /dev/null +++ b/src/components/ActionBar/ActionBar.test.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +describe(' component', () => { + beforeEach(() => { + jest.resetModules(); + }); + + test('should render the component in default state', () => { + const packageMeta = { + latest: { + homepage: 'https://verdaccio.tld', + bugs: { + url: 'https://verdaccio.tld/bugs', + }, + dist: { + tarball: 'https://verdaccio.tld/download' + }, + }, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const ActionBar = require('./ActionBar').default; + const wrapper = shallow(); + expect(wrapper.html()).toMatchSnapshot(); + }); + + test('when there is no action bar data', () => { + const packageMeta = { + latest: {}, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const ActionBar = require('./ActionBar').default; + const wrapper = shallow(); + expect(wrapper.html()).toEqual(''); + }); +}); diff --git a/src/components/ActionBar/ActionBar.tsx b/src/components/ActionBar/ActionBar.tsx index b8a0fbf..f034a17 100644 --- a/src/components/ActionBar/ActionBar.tsx +++ b/src/components/ActionBar/ActionBar.tsx @@ -44,7 +44,7 @@ class ActionBar extends Component { ); } - private renderActionBarListItems = packageMeta => { + private renderActionBar = ({ packageMeta }) => { // @ts-ignore const { latest: { bugs: { url: issue } = {}, homepage, dist: { tarball } = {} } = {} } = packageMeta; @@ -68,15 +68,15 @@ class ActionBar extends Component { return component; }, []); - return ( - <> - {renderList} - - ); - }; + if (renderList.length > 0) { + return ( + + {renderList} + + ); + } - private renderActionBar = ({ packageMeta = {} }) => { - return {this.renderActionBarListItems(packageMeta)}; + return null; }; } diff --git a/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap b/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap new file mode 100644 index 0000000..fd8ea2f --- /dev/null +++ b/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` component should render the component in default state 1`] = `"
"`;