2017-11-30 14:14:40 +01:00
|
|
|
/**
|
|
|
|
* Package component
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2018-06-17 13:34:59 +02:00
|
|
|
import Package from '../../../../src/webui/src/components/Package/index';
|
2017-11-30 14:14:40 +01:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
|
|
|
2018-06-18 23:31:38 +02:00
|
|
|
/**
|
|
|
|
* Generates one month back date from current time
|
|
|
|
* @return {object} date object
|
|
|
|
*/
|
|
|
|
const dateOneMonthAgo = () => {
|
|
|
|
const date = new Date();
|
|
|
|
date.setMonth(date.getMonth() - 1);
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2017-11-30 14:14:40 +01:00
|
|
|
describe('<Package /> component', () => {
|
|
|
|
it('should load the component', () => {
|
|
|
|
const props = {
|
|
|
|
name: 'verdaccio',
|
|
|
|
version: '1.0.0',
|
2018-06-18 23:31:38 +02:00
|
|
|
time: dateOneMonthAgo(),
|
2018-06-04 06:39:24 +02:00
|
|
|
license: 'MIT',
|
2017-11-30 14:14:40 +01:00
|
|
|
description: 'Private NPM repository',
|
|
|
|
author: { name: 'Sam' }
|
|
|
|
};
|
|
|
|
const wrapper = mount(
|
|
|
|
<BrowserRouter>
|
|
|
|
<Package package={props} />
|
|
|
|
</BrowserRouter>
|
|
|
|
);
|
|
|
|
|
|
|
|
// renderAuthor method
|
|
|
|
const renderAuthor = wrapper.find(Package).instance().renderAuthor;
|
|
|
|
expect(renderAuthor({ author: {} })).toBeUndefined();
|
|
|
|
expect(renderAuthor({ author: { name: 'sam' } })).toBeDefined();
|
|
|
|
|
|
|
|
// integration expectations
|
|
|
|
expect(wrapper.find('a').prop('href')).toEqual('detail/verdaccio');
|
2018-06-04 06:39:24 +02:00
|
|
|
expect(wrapper.find('h1').text()).toEqual('verdaccio v1.0.0');
|
2017-11-30 14:14:40 +01:00
|
|
|
expect(wrapper.find('.el-tag--gray').text()).toEqual('v1.0.0');
|
|
|
|
expect(
|
2018-06-04 06:39:24 +02:00
|
|
|
wrapper.find('div').filterWhere(n => n.prop('role') === 'author')
|
2017-11-30 14:14:40 +01:00
|
|
|
.text()
|
|
|
|
).toEqual('By: Sam');
|
|
|
|
expect(wrapper.find('p').text()).toEqual('Private NPM repository');
|
2018-06-04 06:39:24 +02:00
|
|
|
expect(wrapper.find('.license').text()).toMatch(/MIT/);
|
2018-06-18 23:34:29 +02:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2017-11-30 14:14:40 +01:00
|
|
|
});
|
|
|
|
});
|