mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
* consistent error handling * Display server errors in InviteUserForm * Handle errors in Form component * Refactors query form * creates KolideAce component * Renders QueryForm from query page and manage hosts page * Moves ace editor and select targets dropdown to query form * Render base errors in Form HOC * LoginPage and ForgotPasswordPage server errors * Ensure unique key for user blocks * Adds base error to login form and forgot password form * Adds base error to query form * Adds base error to Pack Form * Adds errors to confirm invite form * Adds clearErrors action * clear errors when confirm invite page unmounts * Handle errors in the App Setting page * Handle server errors in the User Settings Page * Handle server errors in the User Management Page
45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import expect, { createSpy, restoreSpies } from 'expect';
|
|
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', () => {
|
|
afterEach(restoreSpies);
|
|
|
|
it('has the correct fields', () => {
|
|
const form = mount(<UserSettingsForm handleSubmit={noop} />);
|
|
|
|
itBehavesLikeAFormInputElement(form, 'email');
|
|
itBehavesLikeAFormInputElement(form, 'name');
|
|
itBehavesLikeAFormInputElement(form, 'username');
|
|
});
|
|
|
|
it('calls the handleSubmit props with form data', () => {
|
|
const handleSubmitSpy = createSpy();
|
|
const form = mount(<UserSettingsForm handleSubmit={handleSubmitSpy} />);
|
|
const expectedFormData = { email: 'email@example.com', name: 'Jim Example', username: 'jimmyexamples' };
|
|
const emailInput = form.find({ name: 'email' }).find('input');
|
|
const nameInput = form.find({ name: 'name' }).find('input');
|
|
const usernameInput = form.find({ name: 'username' }).find('input');
|
|
|
|
fillInFormInput(emailInput, expectedFormData.email);
|
|
fillInFormInput(nameInput, expectedFormData.name);
|
|
fillInFormInput(usernameInput, expectedFormData.username);
|
|
|
|
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', username: 'jimmyexamples' };
|
|
const form = mount(<UserSettingsForm formData={user} handleSubmit={noop} />);
|
|
|
|
expect(form.state().formData).toEqual(user);
|
|
});
|
|
});
|