diff --git a/src/components/Author/Author.test.tsx b/src/components/Author/Author.test.tsx index 6f8e162..02308b0 100644 --- a/src/components/Author/Author.test.tsx +++ b/src/components/Author/Author.test.tsx @@ -1,10 +1,75 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Author from './Author'; - describe(' 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(); + 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(); + 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(); expect(wrapper.html()).toMatchSnapshot(); }); diff --git a/src/components/Author/__snapshots__/Author.test.tsx.snap b/src/components/Author/__snapshots__/Author.test.tsx.snap index ceb99b2..2838593 100644 --- a/src/components/Author/__snapshots__/Author.test.tsx.snap +++ b/src/components/Author/__snapshots__/Author.test.tsx.snap @@ -1,3 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should render the component in default state 1`] = `""`; +exports[` component should render the component in default state 1`] = `"

    Author

  • \\"verdaccio
    verdaccio user
"`; + +exports[` component should render the component when there is no author email 1`] = `"

    Author

  • \\"verdaccio
    verdaccio user
"`;