2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-11-23 19:41:14 +07:00
|
|
|
import { mount } from '../../utils/test-enzyme';
|
2019-10-06 20:44:48 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
|
|
|
|
|
|
|
import Authors from './Author';
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const withAuthorComponent = (packageMeta: React.ContextType<typeof DetailContext>['packageMeta']): JSX.Element => (
|
|
|
|
<DetailContext.Provider value={{ packageMeta }}>
|
|
|
|
<Authors />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
);
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
describe('<Author /> component', () => {
|
2019-07-03 02:37:36 +07:00
|
|
|
beforeEach(() => {
|
2019-08-31 16:02:46 +07:00
|
|
|
jest.resetAllMocks();
|
2019-07-03 02:37:36 +07:00
|
|
|
});
|
|
|
|
|
2019-04-05 02:23:40 +07:00
|
|
|
test('should render the component in default state', () => {
|
2019-07-03 02:37:36 +07:00
|
|
|
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',
|
|
|
|
},
|
2019-10-06 20:44:48 +07:00
|
|
|
dist: { fileCount: 0, unpackedSize: 0 },
|
2019-07-03 02:37:36 +07:00
|
|
|
},
|
2019-10-06 20:44:48 +07:00
|
|
|
_uplinks: {},
|
2019-07-03 02:37:36 +07:00
|
|
|
};
|
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const wrapper = mount(withAuthorComponent(packageMeta));
|
2019-07-03 02:37:36 +07:00
|
|
|
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',
|
2019-10-06 20:44:48 +07:00
|
|
|
dist: { fileCount: 0, unpackedSize: 0 },
|
2019-07-03 02:37:36 +07:00
|
|
|
},
|
2019-10-06 20:44:48 +07:00
|
|
|
_uplinks: {},
|
2019-07-03 02:37:36 +07:00
|
|
|
};
|
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const wrapper = mount(withAuthorComponent(packageMeta));
|
|
|
|
expect(wrapper.html()).toBeNull();
|
2019-07-03 02:37:36 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
2019-10-06 20:44:48 +07:00
|
|
|
dist: { fileCount: 0, unpackedSize: 0 },
|
2019-07-03 02:37:36 +07:00
|
|
|
},
|
2019-10-06 20:44:48 +07:00
|
|
|
_uplinks: {},
|
2019-07-03 02:37:36 +07:00
|
|
|
};
|
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const wrapper = mount(withAuthorComponent(packageMeta));
|
2019-04-05 02:23:40 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|