2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
2019-08-31 16:02:46 +07:00
|
|
|
import { mount } from 'enzyme';
|
2019-09-01 18:09:23 +07:00
|
|
|
import { MemoryRouter } from 'react-router';
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
import Versions, { LABEL_CURRENT_TAGS, LABEL_VERSION_HISTORY } from './Versions';
|
|
|
|
import data from './__partials__/data.json';
|
|
|
|
|
|
|
|
import { render, cleanup } from '@testing-library/react';
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const mockPackageMeta = jest.fn(() => ({
|
2019-09-01 18:09:23 +07:00
|
|
|
packageName: 'foo',
|
|
|
|
packageMeta: data,
|
2019-08-31 16:02:46 +07:00
|
|
|
}));
|
2019-08-24 21:57:51 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
jest.mock('../../pages/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
2019-09-01 18:09:23 +07:00
|
|
|
return component.children({ ...mockPackageMeta() });
|
2019-08-31 16:02:46 +07:00
|
|
|
},
|
|
|
|
}));
|
2019-08-24 21:57:51 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
describe('<Version /> component', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
2019-09-12 03:47:45 +07:00
|
|
|
// FIXME: this test is not deterministic (writes `N days ago` in the snapshot, where N is random number)
|
|
|
|
test.skip('should render the component in default state', () => {
|
2019-09-01 18:09:23 +07:00
|
|
|
const wrapper = mount(
|
|
|
|
<MemoryRouter>
|
|
|
|
<Versions />
|
|
|
|
</MemoryRouter>
|
|
|
|
);
|
2019-04-05 02:23:40 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-09-01 18:09:23 +07:00
|
|
|
|
|
|
|
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');
|
2019-04-05 02:23:40 +07:00
|
|
|
});
|