Rename components and errors in setup flow (#1059)

This commit is contained in:
Zach Wasserman
2021-06-10 17:01:18 -07:00
committed by GitHub
parent 6040f88964
commit 0a22b9195e
10 changed files with 56 additions and 56 deletions
@@ -59,7 +59,7 @@ class ConfirmationPage extends Component {
handleSubmit,
formData: {
email,
server_url: kolideWebAddress,
server_url: fleetWebAddress,
org_name: orgName,
username,
},
@@ -91,9 +91,9 @@ class ConfirmationPage extends Component {
<td>
<span
className={`${baseClass}__table-url`}
title={kolideWebAddress}
title={fleetWebAddress}
>
{kolideWebAddress}
{fleetWebAddress}
</span>
</td>
</tr>
@@ -4,13 +4,13 @@ import PropTypes from "prop-types";
import Form from "components/forms/Form";
import formFieldInterface from "interfaces/form_field";
import Button from "components/buttons/Button";
import helpers from "components/forms/RegistrationForm/KolideDetails/helpers";
import helpers from "components/forms/RegistrationForm/FleetDetails/helpers";
import InputFieldWithIcon from "components/forms/fields/InputFieldWithIcon";
const formFields = ["server_url"];
const { validate } = helpers;
class KolideDetails extends Component {
class FleetDetails extends Component {
static propTypes = {
className: PropTypes.string,
currentPage: PropTypes.bool,
@@ -68,7 +68,7 @@ class KolideDetails extends Component {
}
}
export default Form(KolideDetails, {
export default Form(FleetDetails, {
fields: formFields,
validate,
});
@@ -2,20 +2,20 @@ import React from "react";
import { mount } from "enzyme";
import { noop } from "lodash";
import KolideDetails from "components/forms/RegistrationForm/KolideDetails";
import FleetDetails from "components/forms/RegistrationForm/FleetDetails";
import { fillInFormInput } from "test/helpers";
describe("KolideDetails - form", () => {
describe("kolide web address input", () => {
describe("FleetDetails - form", () => {
describe("fleet web address input", () => {
it("renders an input field", () => {
const form = mount(<KolideDetails handleSubmit={noop} />);
const kolideWebAddressField = form.find({ name: "server_url" });
const form = mount(<FleetDetails handleSubmit={noop} />);
const fleetWebAddressField = form.find({ name: "server_url" });
expect(kolideWebAddressField.length).toBeGreaterThan(0);
expect(fleetWebAddressField.length).toBeGreaterThan(0);
});
it("updates state when the field changes", () => {
const form = mount(<KolideDetails handleSubmit={noop} />);
const form = mount(<FleetDetails handleSubmit={noop} />);
const serverAddressField = form
.find({ name: "server_url" })
.find("input");
@@ -29,45 +29,45 @@ describe("KolideDetails - form", () => {
});
describe("submitting the form", () => {
it("validates the presence of the kolide web address field", () => {
it("validates the presence of the fleet web address field", () => {
const handleSubmitSpy = jest.fn();
const form = mount(<KolideDetails handleSubmit={handleSubmitSpy} />);
const form = mount(<FleetDetails handleSubmit={handleSubmitSpy} />);
const htmlForm = form.find("form");
htmlForm.simulate("submit");
expect(handleSubmitSpy).not.toHaveBeenCalled();
expect(form.state().errors).toMatchObject({
server_url: "Kolide web address must be completed",
server_url: "Fleet web address must be completed",
});
});
it("validates the kolide web address field starts with https://", () => {
it("validates the fleet web address field starts with https://", () => {
const handleSubmitSpy = jest.fn();
const form = mount(<KolideDetails handleSubmit={handleSubmitSpy} />);
const kolideWebAddressField = form
const form = mount(<FleetDetails handleSubmit={handleSubmitSpy} />);
const fleetWebAddressField = form
.find({ name: "server_url" })
.find("input");
const htmlForm = form.find("form");
fillInFormInput(kolideWebAddressField, "http://gnar.Fleet.co");
fillInFormInput(fleetWebAddressField, "http://gnar.Fleet.co");
htmlForm.simulate("submit");
expect(handleSubmitSpy).not.toHaveBeenCalled();
expect(form.state().errors).toMatchObject({
server_url: "Kolide web address must start with https://",
server_url: "Fleet web address must start with https://",
});
});
it("submits the form when valid", () => {
const handleSubmitSpy = jest.fn();
const form = mount(<KolideDetails handleSubmit={handleSubmitSpy} />);
const kolideWebAddressField = form
const form = mount(<FleetDetails handleSubmit={handleSubmitSpy} />);
const fleetWebAddressField = form
.find({ name: "server_url" })
.find("input");
const htmlForm = form.find("form");
fillInFormInput(kolideWebAddressField, "https://gnar.Fleet.co");
fillInFormInput(fleetWebAddressField, "https://gnar.Fleet.co");
htmlForm.simulate("submit");
expect(handleSubmitSpy).toHaveBeenCalled();
@@ -0,0 +1,20 @@
import { size, startsWith } from "lodash";
const validate = (formData) => {
const errors = {};
const { server_url: fleetWebAddress } = formData;
if (!fleetWebAddress) {
errors.server_url = "Fleet web address must be completed";
}
if (fleetWebAddress && !startsWith(fleetWebAddress, "https://")) {
errors.server_url = "Fleet web address must start with https://";
}
const valid = !size(errors);
return { valid, errors };
};
export default { validate };
@@ -0,0 +1 @@
export { default } from "./FleetDetails";
@@ -1,20 +0,0 @@
import { size, startsWith } from "lodash";
const validate = (formData) => {
const errors = {};
const { server_url: kolideWebAddress } = formData;
if (!kolideWebAddress) {
errors.server_url = "Kolide web address must be completed";
}
if (kolideWebAddress && !startsWith(kolideWebAddress, "https://")) {
errors.server_url = "Kolide web address must start with https://";
}
const valid = !size(errors);
return { valid, errors };
};
export default { validate };
@@ -1 +0,0 @@
export { default } from "./KolideDetails";
@@ -4,7 +4,7 @@ import classnames from "classnames";
import AdminDetails from "components/forms/RegistrationForm/AdminDetails";
import ConfirmationPage from "components/forms/RegistrationForm/ConfirmationPage";
import KolideDetails from "components/forms/RegistrationForm/KolideDetails";
import FleetDetails from "components/forms/RegistrationForm/FleetDetails";
import OrgDetails from "components/forms/RegistrationForm/OrgDetails";
const baseClass = "user-registration";
@@ -86,14 +86,14 @@ class RegistrationForm extends Component {
`${baseClass}__field-wrapper--org`
);
const kolideDetailsContainerClass = classnames(
const fleetDetailsContainerClass = classnames(
`${baseClass}__container`,
`${baseClass}__container--kolide`
`${baseClass}__container--fleet`
);
const kolideDetailsClass = classnames(
const fleetDetailsClass = classnames(
`${baseClass}__field-wrapper`,
`${baseClass}__field-wrapper--kolide`
`${baseClass}__field-wrapper--fleet`
);
const confirmationContainerClass = classnames(
@@ -138,12 +138,12 @@ class RegistrationForm extends Component {
currentPage={isCurrentPage(2)}
/>
</div>
<div className={kolideDetailsContainerClass}>
<div className={fleetDetailsContainerClass}>
<h2>Set Fleet URL</h2>
<KolideDetails
<FleetDetails
formData={formData}
handleSubmit={onPageFormSubmit}
className={kolideDetailsClass}
className={fleetDetailsClass}
currentPage={isCurrentPage(3)}
/>
</div>
@@ -18,10 +18,10 @@ describe("RegistrationForm - component", () => {
expect(form.text()).toContain("Organization details");
});
it("renders KolideDetails on the third page", () => {
it("renders FleetDetails on the third page", () => {
const form = mount(<RegistrationForm page={3} />);
expect(form.find("KolideDetails").length).toEqual(1);
expect(form.find("FleetDetails").length).toEqual(1);
expect(form.text()).toContain("Set Fleet URL");
});
@@ -8,5 +8,5 @@ export default PropTypes.shape({
org_name: PropTypes.string,
org_web_url: PropTypes.string,
org_logo_url: PropTypes.string,
kolide_web_address: PropTypes.string,
fleet_web_address: PropTypes.string,
});