1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-05 22:24:27 +07:00
verdaccio-ui/src/components/Versions/Versions.test.tsx
Juan Picado @jotadeveloper 1904179af3
feat: add browser features to browse by version (#125)
* feat: add browser features to browse by version

* chore: verify whether version exist

* chore: add link on versions

* chore: udpate imports

* chore: use mui links

* test: add unit test

* chore: Add todo list

* chore: remove imports
2019-09-01 04:09:23 -07:00

74 lines
1.7 KiB
TypeScript

import React from 'react';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router';
import Versions, { LABEL_CURRENT_TAGS, LABEL_VERSION_HISTORY } from './Versions';
import data from './__partials__/data.json';
import { render, cleanup } from '@testing-library/react';
const mockPackageMeta = jest.fn(() => ({
packageName: 'foo',
packageMeta: data,
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ ...mockPackageMeta() });
},
}));
describe('<Version /> component', () => {
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
cleanup();
});
test('should render the component in default state', () => {
const wrapper = mount(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render versions', () => {
const { getByText } = render(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(getByText(LABEL_VERSION_HISTORY)).toBeTruthy();
expect(getByText(LABEL_CURRENT_TAGS)).toBeTruthy();
// pick some versions
expect(getByText('2.3.0')).toBeTruthy();
expect(getByText('canary')).toBeTruthy();
});
test('should not render versions', () => {
const request = {
packageName: 'foo',
};
// @ts-ignore
mockPackageMeta.mockImplementation(() => request);
const { queryByText } = render(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(queryByText(LABEL_VERSION_HISTORY)).toBeFalsy();
expect(queryByText(LABEL_CURRENT_TAGS)).toBeFalsy();
});
test.todo('should click on version link');
});