createCB tests
parent
22f90b08fa
commit
19c7ef2f36
|
@ -1,8 +1,9 @@
|
|||
import * as React from "react";
|
||||
import { testGrid } from "./generate_grid_test";
|
||||
import { GridInput, InputCell, InputCellProps } from "../grid_input";
|
||||
import { GridInput, InputCell, InputCellProps, createCB } from "../grid_input";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import { BlurableInput } from "../../../../ui/blurable_input";
|
||||
import { DeepPartial } from "redux";
|
||||
|
||||
describe("<GridInput/>", () => {
|
||||
it("renders", () => {
|
||||
|
@ -33,3 +34,18 @@ describe("<InputCell/>", () => {
|
|||
expect(p.onChange).toHaveBeenCalledWith(p.gridKey, 6);
|
||||
});
|
||||
});
|
||||
|
||||
describe("createCB", () => {
|
||||
it("creates a callback", () => {
|
||||
type E = React.ChangeEvent<HTMLInputElement>;
|
||||
const e: DeepPartial<E> = {
|
||||
currentTarget: {
|
||||
value: "7"
|
||||
}
|
||||
};
|
||||
const dispatch = jest.fn();
|
||||
const cb = createCB("numPlantsH", dispatch);
|
||||
cb(e as E);
|
||||
expect(dispatch).toHaveBeenCalledWith("numPlantsH", 7);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -67,11 +67,12 @@ const LABELS: Record<PlantGridKey, LabelData> = {
|
|||
},
|
||||
};
|
||||
|
||||
const createCB = (key: PlantGridKey, cb: GridInputProps["onChange"]) =>
|
||||
(x: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const number = parseInt(x.currentTarget.value, 10);
|
||||
(!isNaN(number)) && cb(key, number);
|
||||
};
|
||||
export const createCB =
|
||||
(key: PlantGridKey, cb: GridInputProps["onChange"]) =>
|
||||
(x: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const number = parseInt(x.currentTarget.value, 10);
|
||||
(!isNaN(number)) && cb(key, number);
|
||||
};
|
||||
|
||||
export function InputCell({ gridKey, onChange, grid, xy_swap }: InputCellProps) {
|
||||
const data = LABELS[gridKey];
|
||||
|
|
Loading…
Reference in New Issue