Reconfigure tests to work with hook approach

This commit is contained in:
Nathan Barber
2021-04-07 15:25:21 -04:00
parent b230745d64
commit 4768751125
13 changed files with 129 additions and 87 deletions

View File

@@ -18,39 +18,28 @@ describe("AddUser Component: ", () => {
/>
);
it("Updates state.users on textbox blur", () => {
let component = shallow(addUserJsx(mockAsync())),
textarea = component.find("textarea");
textarea.simulate("blur", { target: { value: "foo" } });
expect(JSON.stringify(component.state("users"))).toBe('["foo"]');
});
it("Renders", () => {
let component = shallow(addUserJsx(mockAsync()))
expect(component.find(".container").length).toBe(1)
})
it("Can separate newline spaced names into an array", () => {
let component = shallow(addUserJsx(mockAsync())),
textarea = component.find("textarea");
textarea.simulate("blur", { target: { value: "foo\nbar\nsoforth" } });
expect(JSON.stringify(component.state("users"))).toBe(
'["foo","bar","soforth"]'
);
});
it("Removes users when they fail Regex", () => {
let callbackSpy = mockAsync(),
component = shallow(addUserJsx(callbackSpy)),
textarea = component.find("textarea").first()
textarea.simulate("blur", { target: { value: "foo\nbar\n!!*&*"}})
let submit = component.find("#submit")
submit.simulate("click")
expect(callbackSpy).toHaveBeenCalledWith(["foo", "bar"], false)
})
it("Deliminates names with special / less than 3 characters", () => {
let component = shallow(addUserJsx(mockAsync())),
textarea = component.find("textarea"),
submit = component.find("#submit");
textarea.simulate("blur", {
target: { value: "foo\nbar\nb%%%\n$andy\nhalfdecent" },
});
submit.simulate("click");
expect(JSON.stringify(component.state("users"))).toBe(
'["foo","bar","halfdecent"]'
);
});
it("Recognizes admin user selection", () => {
let component = shallow(addUserJsx(mockAsync())),
admin = component.find("#admin-check");
admin.simulate("change", { target: { checked: true } });
expect(component.state("admin")).toBe(true);
});
it("Correctly submits admin", () => {
let callbackSpy = mockAsync(),
component = shallow(addUserJsx(callbackSpy)),
input = component.find("input").first()
input.simulate("change", { target: { checked: true }})
let submit = component.find("#submit")
submit.simulate("click")
expect(callbackSpy).toHaveBeenCalledWith([], true)
})
});