1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-03 18:11:36 +07:00
verdaccio-ui/src/pages/Version/Version.test.tsx
Priscila Oliveira 42d3bb8508 feat: login Dialog Component - Replaced class by func. comp + added react-hook-form (#341)
* refactor: convert class to func

* refactor: changed login form logic

* refactor: conver to testing-library tests

* refactor: moved dependency

* refactor: replaced uglifyjs-webpack-plugin by terser-webpack-plugin

* fix: fixed e2e errors

* fix: fixed e2e test

* Delete settings.json

* fix: vscode settings rollback

* refactor: rollback webpack config

* refactor: updated eslint rule

* fix: removed --fix

* refactor: incresed the bundle size
2019-12-06 18:09:01 +01:00

66 lines
2.1 KiB
TypeScript

import React from 'react';
import { MemoryRouter } from 'react-router';
import { waitForElement } from '@testing-library/dom';
import { render } from '../../utils/test-react-testing-library';
import { NOT_FOUND_TEXT } from '../../components/NotFound';
import Version from './Version';
import { DetailContext } from './context';
import data from './__partials__/data.json';
// :-) we mock this otherways fails on render, some weird issue on material-ui
jest.mock('../../muiComponents/Avatar');
const detailContextValue = {
packageName: 'foo',
packageMeta: data,
readMe: 'Read me!',
enableLoading: jest.fn(),
isLoading: false,
hasNotBeenFound: false,
version: '1.0.0',
};
describe('test Version page', () => {
test('should render the version page', async () => {
const { getByTestId, getByText } = render(
<MemoryRouter>
<DetailContext.Provider value={detailContextValue}>
<Version />
</DetailContext.Provider>
</MemoryRouter>
);
// we wait fetch response (mocked above)
await waitForElement(() => getByTestId('version-layout'));
// check whether readme was loaded
const hasReadme = getByText(detailContextValue.readMe);
expect(hasReadme).toBeTruthy();
});
test('should render 404 page if the resources are not found', async () => {
const { getByText } = render(
<MemoryRouter>
<DetailContext.Provider
value={{
...detailContextValue,
hasNotBeenFound: true,
}}>
<Version />
</DetailContext.Provider>
</MemoryRouter>
);
// we wait fetch response (mocked above)
const notFoundElement = await waitForElement(() => getByText(NOT_FOUND_TEXT));
expect(notFoundElement).toBeTruthy();
});
// 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');
});