mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-10 19:43:01 +00:00
Add React Admin and modify AdminHandler
This commit is contained in:
56
jsx/src/components/AddUser/AddUser.test.js
Normal file
56
jsx/src/components/AddUser/AddUser.test.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from "react";
|
||||
import Enzyme, { shallow } from "enzyme";
|
||||
import { AddUser } from "./AddUser.pre";
|
||||
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
|
||||
|
||||
Enzyme.configure({ adapter: new Adapter() });
|
||||
|
||||
describe("AddUser Component: ", () => {
|
||||
var mockAsync = () =>
|
||||
jest.fn().mockImplementation(() => Promise.resolve({ key: "value" }));
|
||||
|
||||
var addUserJsx = (callbackSpy) => (
|
||||
<AddUser
|
||||
addUsers={callbackSpy}
|
||||
failRegexEvent={callbackSpy}
|
||||
refreshUserData={callbackSpy}
|
||||
history={{ push: (a) => {} }}
|
||||
/>
|
||||
);
|
||||
|
||||
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("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("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);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user