2019-08-25 19:34:27 +07:00
|
|
|
import React from 'react';
|
|
|
|
import { MemoryRouter } from 'react-router';
|
2019-10-08 03:19:18 +07:00
|
|
|
import { waitForElement } from '@testing-library/dom';
|
2019-08-25 19:34:27 +07:00
|
|
|
|
2019-11-23 19:41:14 +07:00
|
|
|
import { render } from '../../utils/test-react-testing-library';
|
2019-10-17 12:36:41 +07:00
|
|
|
import { NOT_FOUND_TEXT } from '../../components/NotFound';
|
2019-08-25 19:34:27 +07:00
|
|
|
|
|
|
|
import Version from './Version';
|
2019-10-17 12:36:41 +07:00
|
|
|
import { DetailContext } from './context';
|
|
|
|
import data from './__partials__/data.json';
|
2019-08-25 19:34:27 +07:00
|
|
|
|
|
|
|
// :-) we mock this otherways fails on render, some weird issue on material-ui
|
2019-10-06 23:30:05 +07:00
|
|
|
jest.mock('../../muiComponents/Avatar');
|
2019-08-25 19:34:27 +07:00
|
|
|
|
2019-10-17 12:36:41 +07:00
|
|
|
const detailContextValue = {
|
|
|
|
packageName: 'foo',
|
|
|
|
packageMeta: data,
|
|
|
|
readMe: 'Read me!',
|
|
|
|
enableLoading: jest.fn(),
|
|
|
|
isLoading: false,
|
|
|
|
hasNotBeenFound: false,
|
|
|
|
version: '1.0.0',
|
|
|
|
};
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
describe('test Version page', () => {
|
|
|
|
test('should render the version page', async () => {
|
|
|
|
const { getByTestId, getByText } = render(
|
2019-10-17 12:36:41 +07:00
|
|
|
<MemoryRouter>
|
|
|
|
<DetailContext.Provider value={detailContextValue}>
|
|
|
|
<Version />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
</MemoryRouter>
|
2019-08-25 19:34:27 +07:00
|
|
|
);
|
|
|
|
// we wait fetch response (mocked above)
|
|
|
|
await waitForElement(() => getByTestId('version-layout'));
|
|
|
|
// check whether readme was loaded
|
2019-10-17 12:36:41 +07:00
|
|
|
const hasReadme = getByText(detailContextValue.readMe);
|
2019-08-25 19:34:27 +07:00
|
|
|
expect(hasReadme).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should render 404 page if the resources are not found', async () => {
|
2019-10-17 12:36:41 +07:00
|
|
|
const { getByText } = render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<DetailContext.Provider
|
|
|
|
value={{
|
|
|
|
...detailContextValue,
|
|
|
|
hasNotBeenFound: true,
|
|
|
|
}}>
|
|
|
|
<Version />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
</MemoryRouter>
|
2019-08-25 19:34:27 +07:00
|
|
|
);
|
|
|
|
// we wait fetch response (mocked above)
|
2019-10-17 12:36:41 +07:00
|
|
|
const notFoundElement = await waitForElement(() => getByText(NOT_FOUND_TEXT));
|
|
|
|
expect(notFoundElement).toBeTruthy();
|
2019-08-25 19:34:27 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Wanna contribute? Here we some scenarios we need to test
|
|
|
|
|
|
|
|
test.todo('should test click on tabs');
|
|
|
|
test.todo('should check what is rendered int he sidebar is correct');
|
|
|
|
test.todo('should test click back home on 404');
|
|
|
|
test.todo('should test click on elements in the sidebar');
|
|
|
|
test.todo('should test other not consider scenarios');
|
|
|
|
});
|