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-10-03 15:27:08 +07:00
|
|
|
import { DetailContext, DetailContextProps } from '../../pages/Version';
|
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-10-03 15:27:08 +07:00
|
|
|
const detailContextValue: Partial<DetailContextProps> = {
|
2019-09-01 18:09:23 +07:00
|
|
|
packageName: 'foo',
|
|
|
|
packageMeta: data,
|
2019-10-03 15:27:08 +07:00
|
|
|
};
|
2019-08-24 21:57:51 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
const ComponentToBeRendered: React.FC<{ contextValue: Partial<DetailContextProps> }> = ({ contextValue }) => (
|
|
|
|
<MemoryRouter>
|
|
|
|
<DetailContext.Provider value={contextValue}>
|
|
|
|
<Versions />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
</MemoryRouter>
|
|
|
|
);
|
2019-08-24 21:57:51 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
describe('<Version /> component', () => {
|
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-10-03 15:27:08 +07:00
|
|
|
const wrapper = mount(<ComponentToBeRendered contextValue={detailContextValue} />);
|
2019-04-05 02:23:40 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-09-01 18:09:23 +07:00
|
|
|
|
|
|
|
test('should render versions', () => {
|
2019-10-03 15:27:08 +07:00
|
|
|
const { getByText } = render(<ComponentToBeRendered contextValue={detailContextValue} />);
|
2019-09-01 18:09:23 +07:00
|
|
|
|
|
|
|
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', () => {
|
2019-10-03 15:27:08 +07:00
|
|
|
const { queryByText } = render(<ComponentToBeRendered contextValue={{ packageName: detailContextValue.packageName }} />);
|
2019-09-01 18:09:23 +07:00
|
|
|
|
|
|
|
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
|
|
|
});
|