1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-02 01:25:05 +07:00
verdaccio-ui/src/components/Dist/Dist.test.tsx

91 lines
2.0 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { mount } from 'enzyme';
import Dist from './Dist';
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('<Dist /> component', () => {
beforeEach(() => {
jest.resetModules();
});
test('should render the component in default state', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
dist: {
fileCount: 7,
unpackedSize: 10,
},
license: '',
},
};
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render the component with license as string', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
dist: {
fileCount: 7,
unpackedSize: 10,
},
license: 'MIT',
},
};
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render the component with license as object', () => {
const packageMeta = {
latest: {
name: 'verdaccio',
version: '4.0.0',
dist: {
fileCount: 7,
unpackedSize: 10,
},
license: {
type: 'MIT',
url: 'https://www.opensource.org/licenses/mit-license.php',
},
},
};
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
});