2017-12-20 05:10:53 +01:00
|
|
|
/**
|
|
|
|
* Package Sidebar module
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import PackageSidebar from '../../../../src/webui/src/components/PackageSidebar';
|
|
|
|
import { packageMeta } from '../store/packageMeta';
|
|
|
|
|
|
|
|
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', () => {
|
|
|
|
it('should throw error for the required props', () => {
|
|
|
|
const wrapper = mount(<PackageSidebar />);
|
|
|
|
const { loadPackageData } = wrapper.instance();
|
|
|
|
expect(console.error).toBeCalled();
|
2018-03-21 21:44:19 +01:00
|
|
|
loadPackageData().catch(response => {
|
2017-12-20 05:10:53 +01:00
|
|
|
expect(response).toBeUndefined();
|
|
|
|
expect(wrapper.state()).toEqual({ failed: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should load the packageMeta', () => {
|
|
|
|
const wrapper = mount(<PackageSidebar packageName={'verdaccio'} />);
|
|
|
|
const { loadPackageData } = wrapper.instance();
|
|
|
|
loadPackageData('verdaccio').then(response => {
|
|
|
|
expect(wrapper.state('packageMeta')).toEqual(packageMeta);
|
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|