1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-06-16 13:46:16 +02:00

Fix lint.

This commit is contained in:
Bogdan Bodnar
2019-08-27 16:09:18 +02:00
parent 18e8e20206
commit c0d742b13b
36 changed files with 620 additions and 831 deletions

View File

@ -5,22 +5,25 @@
* See /LICENSE for more information.
*/
import React from 'react';
import {render} from 'customTestRender';
import React from "react";
import { render } from "customTestRender";
import {STATES, SubmitButton} from '../components/SubmitButton';
import SubmitButton, { STATES } from "../components/SubmitButton";
describe('<SubmitButton/>', () => {
it('Render ready', () => {
const {container} = render(<SubmitButton state={STATES.READY}/>);
expect(container).toMatchSnapshot();
describe("<SubmitButton/>", () => {
it("Render ready", () => {
const { container } = render(<SubmitButton state={STATES.READY}/>);
expect(container)
.toMatchSnapshot();
});
it('Render saving', () => {
const {container} = render(<SubmitButton state={STATES.SAVING}/>);
expect(container).toMatchSnapshot();
it("Render saving", () => {
const { container } = render(<SubmitButton state={STATES.SAVING}/>);
expect(container)
.toMatchSnapshot();
});
it('Render load', () => {
const {container} = render(<SubmitButton state={STATES.LOAD}/>);
expect(container).toMatchSnapshot();
it("Render load", () => {
const { container } = render(<SubmitButton state={STATES.LOAD}/>);
expect(container)
.toMatchSnapshot();
});
});

View File

@ -5,6 +5,7 @@ exports[`<SubmitButton/> Render load 1`] = `
<button
class="btn btn-primary offset-lg-8 col-lg-3 col-sm-12"
disabled=""
type="button"
>
<span
aria-hidden="true"
@ -23,6 +24,7 @@ exports[`<SubmitButton/> Render ready 1`] = `
<div>
<button
class="btn btn-primary offset-lg-8 col-lg-3 col-sm-12"
type="button"
>
@ -36,6 +38,7 @@ exports[`<SubmitButton/> Render saving 1`] = `
<button
class="btn btn-primary offset-lg-8 col-lg-3 col-sm-12"
disabled=""
type="button"
>
<span
aria-hidden="true"

View File

@ -9,8 +9,8 @@ import React from 'react';
import {act, fireEvent, render, waitForElement} from 'customTestRender';
import mockAxios from 'jest-mock-axios';
import ForisForm from "../components/ForisForm";
import {ForisForm} from '../components/ForisForm';
// It's possible to unittest each hooks via react-hooks-testing-library.
// But it's better and easier to test it by test components which uses this hooks.
@ -76,39 +76,39 @@ describe('useForm hook.', () => {
expect(Child.mock.calls[1][0].formErrors).toMatchObject({field: 'Error'});
});
// it('Update text value.', () => {
// fireEvent.change(input, {target: {value: 'newValue', type: 'text'}})
// expect(input.value).toBe('newValue');
// });
//
// it('Update text value.', () => {
// fireEvent.change(input, {target: {value: 123, type: 'number'}})
// expect(input.value).toBe('123');
// });
//
// it('Update checkbox value.', () => {
// fireEvent.change(input, {target: {checked: true, type: 'checkbox'}})
// expect(input.checked).toBe(true);
// });
//
// it('Fetch data.', () => {
// expect(mockAxios.get).toHaveBeenCalledWith('/api/wan', expect.anything());
// expect(mockPrepData).toHaveBeenCalledTimes(1);
// expect(Child.mock.calls[0][0].formData).toMatchObject({field: 'preparedData'});
// });
//
// it('Submit.', () => {
// expect(mockAxios.get).toHaveBeenCalledTimes(1);
// expect(mockPrepDataToSubmit).toHaveBeenCalledTimes(0);
//
// fireEvent.submit(form);
//
// expect(mockPrepDataToSubmit).toHaveBeenCalledTimes(1);
// expect(mockAxios.post).toHaveBeenCalledTimes(1);
// expect(mockAxios.post).toHaveBeenCalledWith(
// '/api/wan',
// {'field': 'preparedDataToSubmit'},
// expect.anything(),
// );
// });
it('Update text value.', () => {
fireEvent.change(input, {target: {value: 'newValue', type: 'text'}})
expect(input.value).toBe('newValue');
});
it('Update text value.', () => {
fireEvent.change(input, {target: {value: 123, type: 'number'}})
expect(input.value).toBe('123');
});
it('Update checkbox value.', () => {
fireEvent.change(input, {target: {checked: true, type: 'checkbox'}})
expect(input.checked).toBe(true);
});
it('Fetch data.', () => {
expect(mockAxios.get).toHaveBeenCalledWith('testEndpoint', expect.anything());
expect(mockPrepData).toHaveBeenCalledTimes(1);
expect(Child.mock.calls[0][0].formData).toMatchObject({field: 'preparedData'});
});
it('Submit.', () => {
expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockPrepDataToSubmit).toHaveBeenCalledTimes(0);
fireEvent.submit(form);
expect(mockPrepDataToSubmit).toHaveBeenCalledTimes(1);
expect(mockAxios.post).toHaveBeenCalledTimes(1);
expect(mockAxios.post).toHaveBeenCalledWith(
'testEndpoint',
{'field': 'preparedDataToSubmit'},
expect.anything(),
);
});
});