1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-08-03 20:13:28 +02:00

Resolve "Increment/decrement value in NumberInput when +/- button is kept pushed."

This commit is contained in:
Maciej Lenartowicz
2019-10-07 09:18:25 +00:00
parent 0af56ec84c
commit afa8c160a3
5 changed files with 53 additions and 21 deletions

View File

@@ -7,39 +7,39 @@
import React from "react";
import { render, fireEvent } from "customTestRender";
import { render, fireEvent, getByLabelText, wait } from "customTestRender";
import { NumberInput } from "../NumberInput";
describe("<NumberInput/>", () => {
const onChangeMock = jest.fn();
let container;
let getByLabelText;
let componentContainer;
beforeEach(() => {
({ container, getByLabelText } = render(
const { container } = render(
<NumberInput
label="Test label"
helpText="Some help text"
value={1}
onChange={onChangeMock}
/>
));
);
componentContainer = container;
});
it("Render number input", () => {
expect(container.firstChild).toMatchSnapshot();
expect(componentContainer.firstChild).toMatchSnapshot();
});
it("Increase number with button", () => {
const increaseButton = getByLabelText("Increase");
fireEvent.click(increaseButton);
expect(onChangeMock).toHaveBeenCalledWith({"target": {"value": 2}});
it("Increase number with button", async () => {
const increaseButton = getByLabelText(componentContainer, "Increase");
fireEvent.mouseDown(increaseButton);
await wait(() => expect(onChangeMock).toHaveBeenCalledWith({"target": {"value": 2}}));
});
it("Decrease number with button", () => {
const decreaseButton = getByLabelText("Decrease");
fireEvent.click(decreaseButton);
expect(onChangeMock).toHaveBeenCalledWith({"target": {"value": 0}});
it("Decrease number with button", async () => {
const decreaseButton = getByLabelText(componentContainer, "Decrease");
fireEvent.mouseDown(decreaseButton);
await wait(() => expect(onChangeMock).toHaveBeenCalledWith({"target": {"value": 0}}));
});
});