Combine API props, update tests for redux hooks

This commit is contained in:
Nathan Barber
2021-04-08 18:28:49 -04:00
parent 21f4988f24
commit 51deaa36f3
18 changed files with 347 additions and 222 deletions

View File

@@ -1,30 +1,52 @@
import React from "react";
import Enzyme, { mount, shallow } from "enzyme";
import CreateGroup from "./CreateGroup.pre";
import Enzyme, { mount } from "enzyme";
import CreateGroup from "./CreateGroup";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import { Provider, useDispatch } from "react-redux";
import { createStore } from "redux";
import { HashRouter } from "react-router-dom";
Enzyme.configure({ adapter: new Adapter() });
jest.mock("react-redux", () => ({
...jest.requireActual("react-redux"),
useDispatch: jest.fn(),
}));
describe("CreateGroup Component: ", () => {
var mockAsync = () =>
jest.fn().mockImplementation(() => Promise.resolve({ key: "value" }));
var createGroupJsx = (callbackSpy) => (
<CreateGroup
createGroup={callbackSpy}
refreshGroupsData={callbackSpy}
history={{ push: () => {} }}
/>
<Provider store={createStore(() => {}, {})}>
<HashRouter>
<CreateGroup
createGroup={callbackSpy}
refreshGroupsData={callbackSpy}
history={{ push: () => {} }}
/>
</HashRouter>
</Provider>
);
beforeEach(() => {
useDispatch.mockImplementation((callback) => {
return () => {};
});
});
afterEach(() => {
useDispatch.mockClear();
});
it("Renders", () => {
let component = shallow(createGroupJsx());
let component = mount(createGroupJsx());
expect(component.find(".container").length).toBe(1);
});
it("Calls createGroup and refreshGroupsData on submit", () => {
let callbackSpy = mockAsync(),
component = shallow(createGroupJsx(callbackSpy)),
component = mount(createGroupJsx(callbackSpy)),
input = component.find("input").first(),
submit = component.find("#submit").first();
input.simulate("change", { target: { value: "" } });