Lint and make App (Component) functional

This commit is contained in:
Nathan Barber
2021-04-07 15:36:17 -04:00
parent 1d705193cb
commit cadcb686c9
9 changed files with 82 additions and 123 deletions

View File

@@ -2,7 +2,7 @@ import React from "react";
import Enzyme, { mount, shallow } from "enzyme";
import GroupEdit from "./GroupEdit.pre";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import { HashRouter } from 'react-router-dom'
import { HashRouter } from "react-router-dom";
Enzyme.configure({ adapter: new Adapter() });
@@ -10,7 +10,7 @@ describe("GroupEdit Component: ", () => {
var mockAsync = () =>
jest.fn().mockImplementation(() => Promise.resolve({ key: "value" }));
var groupEditJsx = (callbackSpy) =>
var groupEditJsx = (callbackSpy) => (
<GroupEdit
location={{
state: {
@@ -25,38 +25,37 @@ describe("GroupEdit Component: ", () => {
history={{ push: (a) => callbackSpy }}
refreshGroupsData={() => {}}
/>
);
var deepGroupEditJsx = (callbackSpy) => (
<HashRouter>
{groupEditJsx(callbackSpy)}
</HashRouter>
<HashRouter>{groupEditJsx(callbackSpy)}</HashRouter>
);
it("Adds a newly selected user to group on submit", () => {
let callbackSpy = mockAsync(),
component = mount(deepGroupEditJsx(callbackSpy)),
unselected = component.find(".unselected"),
submit = component.find("#submit")
unselected.simulate("click")
submit.simulate("click")
expect(callbackSpy).toHaveBeenCalledWith(['bar'], "group")
})
submit = component.find("#submit");
unselected.simulate("click");
submit.simulate("click");
expect(callbackSpy).toHaveBeenCalledWith(["bar"], "group");
});
it("Removes a user from group on submit", () => {
let callbackSpy = mockAsync(),
component = mount(deepGroupEditJsx(callbackSpy)),
selected = component.find(".selected"),
submit = component.find("#submit")
selected.simulate("click")
submit.simulate("click")
expect(callbackSpy).toHaveBeenCalledWith(['foo'], "group")
})
submit = component.find("#submit");
selected.simulate("click");
submit.simulate("click");
expect(callbackSpy).toHaveBeenCalledWith(["foo"], "group");
});
it("Calls deleteGroup on button click", () => {
let callbackSpy = mockAsync(),
component = shallow(groupEditJsx(callbackSpy)),
deleteGroup = component.find("#delete-group").first()
deleteGroup.simulate("click")
expect(callbackSpy).toHaveBeenCalled()
})
deleteGroup = component.find("#delete-group").first();
deleteGroup.simulate("click");
expect(callbackSpy).toHaveBeenCalled();
});
});