Skip to content

Commit

Permalink
Rename matrix input
Browse files Browse the repository at this point in the history
  • Loading branch information
acra5y committed Apr 24, 2020
1 parent 45cb35b commit dae8f64
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/components/nDilation/Calculator.jsx
Expand Up @@ -2,7 +2,7 @@ import React, { useReducer } from "react";

import fetchNDilation from "../../lib/fetchNDilation";
import { useWindowContext } from "../WindowContext";
import MatrixInput from "./MatrixInput";
import DilationForm from "./DilationForm";
import Result from "./Result";

const initialState = { isLoading: false, dilation: null, error: null };
Expand Down Expand Up @@ -48,7 +48,7 @@ const Calculator = () => {

return (
<div>
<MatrixInput
<DilationForm
onSubmit={
window && createOnSubmitHandler(window.fetch, dispatch)
}
Expand Down
Expand Up @@ -65,7 +65,7 @@ const matrixRegex = /^(([+-]?\d+([.,]\d+)?),?\s*)+$/;
const isMatrix = matrixRegex.test.bind(matrixRegex);
const isSquare = number => number > 0 && Math.sqrt(number) % 1 === 0;

const MatrixInput = ({ onSubmit }) => {
const DilationForm = ({ onSubmit }) => {
const [input, setInput] = useState("");
const [degree, setDegree] = useState(2);

Expand Down Expand Up @@ -117,4 +117,4 @@ const MatrixInput = ({ onSubmit }) => {
);
};

export default MatrixInput;
export default DilationForm;
18 changes: 9 additions & 9 deletions app/components/nDilation/test/Calculator.test.jsx
@@ -1,7 +1,7 @@
import React from "react";
import { shallow } from "enzyme";

import MatrixInput from "../MatrixInput";
import DilationForm from "../DilationForm";
import Result from "../Result";
import * as WindowContext from "../../WindowContext";
import Calculator from "../Calculator";
Expand Down Expand Up @@ -33,11 +33,11 @@ describe("Calculator", () => {
});

describe("on client", () => {
it("call fetch when onSubmit on MatrixInput is called", async () => {
it("call fetch when onSubmit on DilationForm is called", async () => {
const window = createWindow();
const component = render(window);

await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();

expect(window.fetch.mock.calls.length).toEqual(1);
});
Expand All @@ -57,7 +57,7 @@ describe("Calculator", () => {

expect(component.find(Result).prop("isLoading")).toEqual(false);

await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();

expect(component.find(Result).prop("isLoading")).toEqual(false);
});
Expand All @@ -69,7 +69,7 @@ describe("Calculator", () => {
json: () => Promise.resolve({ value: dilation }),
};
const component = render(createWindow(response));
await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();
expect(component.find(Result).prop("dilation")).toEqual(dilation);
});

Expand All @@ -85,7 +85,7 @@ describe("Calculator", () => {
json: () => Promise.resolve(responseBody),
};
const component = render(createWindow(response));
await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();
expect(component.find(Result).prop("errorDetails")).toEqual(
responseBody
);
Expand All @@ -95,7 +95,7 @@ describe("Calculator", () => {
const error = new Error("Mock Error");
const fetch = jest.fn(() => Promise.reject(error));
const component = render(createWindow(null, fetch));
await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();
expect(component.find(Result).prop("errorDetails")).toEqual(
error
);
Expand All @@ -104,12 +104,12 @@ describe("Calculator", () => {
it("and not render dilation from a first fetch if a second fetch throws", async () => {
const window = createWindow();
const component = render(window);
await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();
const mockError = new Error("Mock Error");
window.fetch.mockImplementation(() =>
Promise.reject(mockError)
);
await component.find(MatrixInput).prop("onSubmit")();
await component.find(DilationForm).prop("onSubmit")();
const result = component.find(Result);
expect(result.prop("dilation")).toBe(null);
expect(result.prop("errorDetails")).toEqual(mockError);
Expand Down
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { shallow } from "enzyme";
import TextAreaAutosize from "react-textarea-autosize";

import MatrixInput from "../MatrixInput";
import DilationForm from "../DilationForm";

const defaultSubmitEvent = {
preventDefault: () => {},
Expand All @@ -12,9 +12,9 @@ const defaultProps = {
onSubmit: jest.fn(),
};

const render = () => shallow(<MatrixInput {...defaultProps} />);
const render = () => shallow(<DilationForm {...defaultProps} />);

describe("MatrixInput", () => {
describe("DilationForm", () => {
it("should render a form", () => {
const component = render();

Expand Down
Expand Up @@ -2,7 +2,7 @@

exports[`Calculator should render 1`] = `
<div>
<MatrixInput
<DilationForm
onSubmit={[Function]}
/>
<withAnimatedContentChange(Result)
Expand Down

0 comments on commit dae8f64

Please sign in to comment.