unit-tests

This commit is contained in:
wrzesinski-hubert 2021-01-13 20:01:17 +01:00
parent b8ef87fc83
commit b06a6ec07e
4 changed files with 15907 additions and 9 deletions

15849
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
import React from 'react';
import { cleanup, fireEvent, waitForElement, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { customRender,customRenderCAS } from '../../customRender';
import {SelectMenu} from '../SelectMenu';
import { Select } from '@material-ui/core';
beforeAll(() => {
delete window.location;
window.location = { replace: jest.fn() };
});
afterAll(() => {
window.location = location;
});
test('not render component for student', async () => {
customRender(<SelectMenu/>);
expect(screen.queryByText(/przedmioty/i)).not.toBeInTheDocument();
});
test('not render component for deanery', async () => {
customRenderCAS(<SelectMenu/>);
expect(screen.queryByText(/przedmioty/i)).not.toBeInTheDocument();
});

View File

@ -18,12 +18,21 @@ test('renders component', async () => {
expect(screen.getByText(/plan na plan/i)).toBeInTheDocument();
});
// test('calculate results after user types value', async () => {
// const { getByLabelText, getByText, debug } = customRender(<Topbar handleTransfer={() => {}} />);
// const input = getByLabelText('xd');
// fireEvent.change(input, { target: { value: '122' } });
// console.log(debug());
// const textNode = await waitForElement(() => getByText('asdasdsa'));
// console.log(debug());
// expect(textNode).toBeInTheDocument();
// });
test('input should display default placeholder for student', async () => {
const { getByPlaceholderText, getByText, debug } = customRender(<Topbar handleTransfer={() => {}} />);
const input = getByPlaceholderText('Wyszukaj przedmioty...');
// fireEvent.change(input, { target: { value: '122' } });
// console.log(debug());
// const textNode = await waitForElement(() => getByText('asdasdsa'));
// console.log(debug());
expect(input).toBeInTheDocument();
});
test('input should display changed value', async () => {
const { getByPlaceholderText, getByText, debug } = customRender(<Topbar handleTransfer={() => {}} />);
const input = getByPlaceholderText('Wyszukaj przedmioty...');
fireEvent.change(input, { target: { value: '122' } });
// console.log(debug());
// console.log(debug());
expect(input.value).toBe("122");
});

View File

@ -16,3 +16,18 @@ export const customRender = (ui, CASValue = {}, studentsValue = {}, coursesValue
</SnackbarProvider>,
);
};
export const customRenderCAS = (ui, CASValue = {}, studentsValue = {}, coursesValue = {}) => {
const user={authorityRole: "DEANERY", email: "test@test.pl", id: "123"}
return render(
<SnackbarProvider>
<CASProvider value={{user}}>
<StudentsProvider value={50}>
<CoursesProvider value={100}>{ui}</CoursesProvider>
</StudentsProvider>
</CASProvider>
</SnackbarProvider>,
);
};