2017-11-30 08:14:40 -05:00
|
|
|
/**
|
|
|
|
* PackageList component
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2018-06-17 06:34:59 -05:00
|
|
|
import PackageList from '../../../../src/webui/src/components/PackageList/index';
|
|
|
|
import Help from '../../../../src/webui/src/components/Help/index';
|
|
|
|
import NoItems from '../../../../src/webui/src/components/NoItems/index';
|
2017-11-30 08:14:40 -05:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
|
|
|
|
|
|
describe('<PackageList /> component', () => {
|
|
|
|
it('should load the component with no packages', () => {
|
|
|
|
const props = {
|
|
|
|
packages: [],
|
|
|
|
help: true
|
|
|
|
};
|
|
|
|
const wrapper = mount(
|
|
|
|
<PackageList packages={props.packages} help={props.help} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
expect(instance.isTherePackages()).toBeFalsy();
|
|
|
|
expect(instance.renderHelp()).toBeTruthy();
|
|
|
|
expect(instance.renderOptions()).toEqual(<Help />);
|
|
|
|
expect(instance.renderTitle()).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should load the component with packages', () => {
|
|
|
|
const props = {
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'verdaccio',
|
|
|
|
version: '1.0.0',
|
2018-06-20 14:07:32 -05:00
|
|
|
time: new Date(),
|
2017-11-30 08:14:40 -05:00
|
|
|
description: 'Private NPM repository',
|
|
|
|
author: { name: 'Sam' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'abc',
|
|
|
|
version: '1.0.1',
|
2018-06-20 14:07:32 -05:00
|
|
|
time: new Date(),
|
2017-11-30 08:14:40 -05:00
|
|
|
description: 'abc description',
|
|
|
|
author: { name: 'Rose' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'xyz',
|
|
|
|
version: '1.1.0',
|
|
|
|
description: 'xyz description',
|
|
|
|
author: { name: 'Martin' }
|
|
|
|
}
|
|
|
|
],
|
|
|
|
help: false
|
|
|
|
};
|
|
|
|
const wrapper = mount(
|
|
|
|
<BrowserRouter>
|
|
|
|
<PackageList packages={props.packages} help={props.help} />
|
|
|
|
</BrowserRouter>
|
|
|
|
);
|
|
|
|
|
|
|
|
const instance = wrapper.find(PackageList).instance();
|
|
|
|
|
|
|
|
expect(instance.isTherePackages()).toBeTruthy();
|
|
|
|
expect(instance.renderHelp()).toBeUndefined();
|
|
|
|
expect(instance.renderTitle().props.children).toEqual('Available Packages');
|
|
|
|
expect(instance.renderNoItems()).toEqual(
|
2018-02-10 10:43:14 -05:00
|
|
|
<NoItems className="package-no-items" text="No items were found with that query" />
|
2017-11-30 08:14:40 -05:00
|
|
|
);
|
|
|
|
expect(instance.renderOptions()).toEqual(
|
2018-02-10 10:43:14 -05:00
|
|
|
<NoItems className="package-no-items" text="No items were found with that query" />
|
2017-11-30 08:14:40 -05:00
|
|
|
);
|
|
|
|
// package count
|
|
|
|
expect(wrapper.find('Package')).toHaveLength(3);
|
2017-12-02 09:01:06 -05:00
|
|
|
// match snapshot
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2017-11-30 08:14:40 -05:00
|
|
|
});
|
|
|
|
});
|