forked from sombochea/verdaccio-ui
67d7188cf5
* chore: update material-ui@4.x * test: update test for ActionBar and TestField * chore: add types * chore: update types * test: update test for Author * chore: fixed bunch of unit test * chore: remove unused import * chore: remove comments * chore: replace shallow my mount * chore: update git hooks * chore: fix styles * chore: update dependencies * chore: remove types material-ui
74 lines
1.6 KiB
TypeScript
74 lines
1.6 KiB
TypeScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
import Engine from './Engines';
|
|
|
|
jest.mock('./img/node.png', () => '');
|
|
jest.mock('../Install/img/npm.svg', () => '');
|
|
|
|
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() });
|
|
},
|
|
}));
|
|
|
|
describe('<Engines /> component', () => {
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
test('should render the component in default state', () => {
|
|
const packageMeta = {
|
|
latest: {
|
|
engines: {
|
|
node: '>= 0.1.98',
|
|
npm: '>3',
|
|
},
|
|
},
|
|
};
|
|
|
|
// @ts-ignore
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
|
|
|
const wrapper = mount(<Engine />);
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
});
|
|
|
|
test('should render the component when there is no engine key in package meta', () => {
|
|
const packageMeta = {
|
|
latest: {},
|
|
};
|
|
|
|
// @ts-ignore
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
|
|
|
const wrapper = mount(<Engine />);
|
|
expect(wrapper.html()).toEqual('');
|
|
});
|
|
|
|
test('should render the component when there is no keys in engine in package meta', () => {
|
|
const packageMeta = {
|
|
latest: {
|
|
engines: {},
|
|
},
|
|
};
|
|
|
|
// @ts-ignore
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
|
|
|
const wrapper = mount(<Engine />);
|
|
expect(wrapper.html()).toEqual('');
|
|
});
|
|
});
|