fleet/frontend/components/forms/UserSettingsForm/UserSettingsForm.tests.jsx
RachelElysia aeb852e168
Remove username from UI (#1168)
* Remove username from UI code
* Remove username from tests
* Remove username from database
* Modify server endpoints for removing username
* Implement backend aspects of removing username
* Update API docs
* Add name to fleetctl
2021-06-24 13:42:29 -07:00

53 lines
1.6 KiB
JavaScript

import React from "react";
import { mount } from "enzyme";
import { noop } from "lodash";
import UserSettingsForm from "components/forms/UserSettingsForm";
import helpers from "test/helpers";
const { fillInFormInput, itBehavesLikeAFormInputElement } = helpers;
describe("UserSettingsForm - component", () => {
const defaultProps = {
handleSubmit: noop,
onCancel: noop,
};
it("has the correct fields", () => {
const form = mount(<UserSettingsForm {...defaultProps} />);
itBehavesLikeAFormInputElement(form, "email");
itBehavesLikeAFormInputElement(form, "name");
});
it("calls the handleSubmit props with form data", () => {
const handleSubmitSpy = jest.fn();
const props = { ...defaultProps, handleSubmit: handleSubmitSpy };
const form = mount(<UserSettingsForm {...props} />);
const expectedFormData = {
email: "email@example.com",
name: "Jim Example",
};
const emailInput = form.find({ name: "email" }).find("input");
const nameInput = form.find({ name: "name" }).find("input");
fillInFormInput(emailInput, expectedFormData.email);
fillInFormInput(nameInput, expectedFormData.name);
form.find("form").simulate("submit");
expect(handleSubmitSpy).toHaveBeenCalledWith(expectedFormData);
});
it("initializes the form with the users data", () => {
const user = {
email: "email@example.com",
name: "Jim Example",
};
const props = { ...defaultProps, formData: user };
const form = mount(<UserSettingsForm {...props} />);
expect(form.state().formData).toEqual(user);
});
});