1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-27 21:45:33 +07:00
verdaccio-ui/src/components/Engines/Engines.test.tsx
Andrew Hughson 5cb47ed49e fix: convert Engine component to hooks (#233)
* refactor: convert Engine component to hooks

* inline engine test data only used by one test

* remove  from engines tests

* remove confusing test abstraction

* change tests to not use mutations
2019-10-31 22:17:16 +01:00

62 lines
1.6 KiB
TypeScript

import React from 'react';
import { mount } from 'enzyme';
import { DetailContext } from '../../pages/Version';
import { PackageMetaInterface } from '../../../types/packageMeta';
import Engine from './Engines';
jest.mock('./img/node.png', () => '');
jest.mock('../Install/img/npm.svg', () => '');
const mockPackageMeta = (engines?: PackageMetaInterface['latest']['engines']): PackageMetaInterface => ({
latest: {
name: 'verdaccio',
version: '0.0.0',
dist: {
fileCount: 1,
unpackedSize: 1,
},
...(engines && { engines }),
},
_uplinks: {},
});
describe('<Engines /> component', () => {
test('should render the component in default state', () => {
const packageMeta = mockPackageMeta({
node: '>= 0.1.98',
npm: '>3',
});
const wrapper = mount(
<DetailContext.Provider value={{ packageMeta }}>
<Engine />
</DetailContext.Provider>
);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render the component when there is no engine key in package meta', () => {
const packageMeta = mockPackageMeta();
const wrapper = mount(
<DetailContext.Provider value={{ packageMeta }}>
<Engine />
</DetailContext.Provider>
);
expect(wrapper.html()).toBeNull();
});
test('should render the component when there is no keys in engine in package meta', () => {
const packageMeta = mockPackageMeta({});
const wrapper = mount(
<DetailContext.Provider value={{ packageMeta }}>
<Engine />
</DetailContext.Provider>
);
expect(wrapper.html()).toBeNull();
});
});