2019-07-09 05:10:56 +07:00
|
|
|
import React from 'react';
|
2019-08-31 16:02:46 +07:00
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import Engine from './Engines';
|
2019-07-09 05:10:56 +07:00
|
|
|
|
|
|
|
jest.mock('./img/node.png', () => '');
|
|
|
|
jest.mock('../Install/img/npm.svg', () => '');
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const mockPackageMeta = jest.fn(() => ({
|
|
|
|
latest: {
|
|
|
|
homepage: 'https://verdaccio.tld',
|
|
|
|
bugs: {
|
|
|
|
url: 'https://verdaccio.tld/bugs',
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
tarball: 'https://verdaccio.tld/download',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../pages/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta: mockPackageMeta() });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2019-07-09 05:10:56 +07:00
|
|
|
describe('<Engines /> component', () => {
|
|
|
|
beforeEach(() => {
|
2019-08-31 16:02:46 +07:00
|
|
|
jest.resetAllMocks();
|
2019-07-09 05:10:56 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in default state', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
engines: {
|
|
|
|
node: '>= 0.1.98',
|
|
|
|
npm: '>3',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
// @ts-ignore
|
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-09 05:10:56 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Engine />);
|
2019-07-09 05:10:56 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component when there is no engine key in package meta', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
// @ts-ignore
|
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-09 05:10:56 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Engine />);
|
2019-07-09 05:10:56 +07:00
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component when there is no keys in engine in package meta', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
engines: {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
// @ts-ignore
|
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-09 05:10:56 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Engine />);
|
2019-07-09 05:10:56 +07:00
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
|
|
|
});
|