2017-12-20 05:10:53 +01:00
|
|
|
/**
|
|
|
|
* Package Sidebar module
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2018-07-17 21:22:44 +02:00
|
|
|
import PackageSidebar from '../../../../../src/webui/components/PackageSidebar/index';
|
2017-12-20 05:10:53 +01:00
|
|
|
import { packageMeta } from '../store/packageMeta';
|
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
jest.mock('../../../../../src/webui/utils/api', () => ({
|
2018-03-21 21:44:19 +01:00
|
|
|
request: require('../__mocks__/api').default.request,
|
2017-12-20 05:10:53 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
console.error = jest.fn();
|
|
|
|
|
|
|
|
describe('<PackageSidebar /> component', () => {
|
2018-12-05 19:30:08 +01:00
|
|
|
test('should throw error for the required props', () => {
|
2017-12-20 05:10:53 +01:00
|
|
|
const wrapper = mount(<PackageSidebar />);
|
|
|
|
const { loadPackageData } = wrapper.instance();
|
2018-12-16 21:09:03 +01:00
|
|
|
expect(console.error).toHaveBeenCalled();
|
2018-12-16 21:27:20 +01:00
|
|
|
return loadPackageData().catch(response => {
|
2017-12-20 05:10:53 +01:00
|
|
|
expect(response).toBeUndefined();
|
|
|
|
expect(wrapper.state()).toEqual({ failed: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-05 19:30:08 +01:00
|
|
|
test('should load the packageMeta', () => {
|
2018-12-15 16:39:51 +01:00
|
|
|
const wrapper = mount(<PackageSidebar packageName={'verdaccio'} />);
|
2017-12-20 05:10:53 +01:00
|
|
|
const { loadPackageData } = wrapper.instance();
|
2018-12-16 21:27:20 +01:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
return loadPackageData('verdaccio').then(response => {
|
2017-12-20 05:10:53 +01:00
|
|
|
expect(wrapper.state('packageMeta')).toEqual(packageMeta);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|