2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-11-23 19:41:14 +07:00
|
|
|
import { shallow } from '../../utils/test-enzyme';
|
2019-06-20 19:37:28 +07:00
|
|
|
import Tag from '../Tag';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
|
|
|
import Package from './Package';
|
2019-06-20 19:37:28 +07:00
|
|
|
import { WrapperLink, Description, OverviewItem } from './styles';
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates one month back date from current time
|
|
|
|
* @return {object} date object
|
|
|
|
*/
|
2019-06-25 05:01:13 +07:00
|
|
|
const dateOneMonthAgo = (): Date => new Date(1544377770747);
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
describe('<Package /> component', () => {
|
|
|
|
test.skip('should load the component', () => {
|
|
|
|
const props = {
|
|
|
|
name: 'verdaccio',
|
|
|
|
version: '1.0.0',
|
2019-06-20 19:37:28 +07:00
|
|
|
time: String(dateOneMonthAgo()),
|
2019-04-05 02:23:40 +07:00
|
|
|
license: 'MIT',
|
|
|
|
description: 'Private NPM repository',
|
|
|
|
author: {
|
2019-06-20 19:37:28 +07:00
|
|
|
name: 'Sam',
|
2019-04-05 02:23:40 +07:00
|
|
|
},
|
2019-06-20 19:37:28 +07:00
|
|
|
keywords: ['verdaccio'],
|
2019-04-05 02:23:40 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = shallow(
|
2019-10-27 21:49:30 +07:00
|
|
|
<Package
|
|
|
|
author={props.author}
|
|
|
|
description={props.description}
|
|
|
|
license={props.license}
|
|
|
|
name={props.name}
|
|
|
|
time={props.time}
|
|
|
|
version={props.version}
|
|
|
|
/>
|
2019-04-05 02:23:40 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
// integration expectations
|
|
|
|
|
|
|
|
// check link
|
|
|
|
expect(wrapper.find(WrapperLink).prop('to')).toEqual(`detail/${props.name}`);
|
|
|
|
|
|
|
|
// check version
|
2019-06-20 19:37:28 +07:00
|
|
|
expect(wrapper.find(OverviewItem).prop('children')).toHaveReturnedWith(`v${props.version}`);
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
// TODO - REWRITE THE TEST
|
2019-06-20 19:37:28 +07:00
|
|
|
// expect(wrapper.find(Author).dive())
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
// check description
|
2019-06-20 19:37:28 +07:00
|
|
|
expect(wrapper.find(Description).prop('children')).toHaveReturnedWith(props.description);
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
// check license
|
|
|
|
expect(wrapper.find(OverviewItem).someWhere(n => n.get(0).props.children[1] === props.license)).toBe(true);
|
|
|
|
|
|
|
|
// check keyword
|
|
|
|
expect(wrapper.find(Tag).prop('children')).toEqual(props.keywords[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.skip('should load the component without author', () => {
|
|
|
|
const props = {
|
|
|
|
name: 'verdaccio',
|
|
|
|
version: '1.0.0',
|
2019-06-20 19:37:28 +07:00
|
|
|
time: String(dateOneMonthAgo()),
|
2019-04-05 02:23:40 +07:00
|
|
|
license: 'MIT',
|
|
|
|
author: {
|
|
|
|
name: 'Anonymous',
|
|
|
|
email: '',
|
2019-06-20 19:37:28 +07:00
|
|
|
avatar: '',
|
2019-04-05 02:23:40 +07:00
|
|
|
},
|
2019-06-20 19:37:28 +07:00
|
|
|
description: 'Private NPM repository',
|
2019-04-05 02:23:40 +07:00
|
|
|
};
|
|
|
|
const wrapper = shallow(
|
2019-10-27 21:49:30 +07:00
|
|
|
<Package
|
|
|
|
author={props.author}
|
|
|
|
description={props.description}
|
|
|
|
license={props.license}
|
|
|
|
name={props.name}
|
|
|
|
time={props.time}
|
|
|
|
version={props.version}
|
|
|
|
/>
|
2019-04-05 02:23:40 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
// integration expectations
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|