mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 09:18:59 +00:00
ff74ba2233
* Moves LabelForm outside of the QueryForm component * Render LabelForm in ManageHostsPage * API client to update labels * Edit button styles
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
import React from 'react';
|
|
import expect, { createSpy, restoreSpies } from 'expect';
|
|
import { mount } from 'enzyme';
|
|
import { noop } from 'lodash';
|
|
|
|
import LabelForm from 'components/forms/LabelForm';
|
|
import {
|
|
fillInFormInput,
|
|
itBehavesLikeAFormDropdownElement,
|
|
itBehavesLikeAFormInputElement,
|
|
} from 'test/helpers';
|
|
|
|
describe('LabelForm - form', () => {
|
|
afterEach(restoreSpies);
|
|
|
|
const defaultProps = {
|
|
handleSubmit: noop,
|
|
isEdit: false,
|
|
onCancel: noop,
|
|
};
|
|
|
|
describe('inputs', () => {
|
|
const form = mount(<LabelForm {...defaultProps} />);
|
|
|
|
describe('name input', () => {
|
|
it('renders an input field', () => {
|
|
itBehavesLikeAFormInputElement(form, 'name');
|
|
});
|
|
});
|
|
|
|
describe('description input', () => {
|
|
it('renders an input field', () => {
|
|
itBehavesLikeAFormInputElement(form, 'description', 'textarea');
|
|
});
|
|
});
|
|
|
|
describe('platform input', () => {
|
|
it('renders an input field', () => {
|
|
itBehavesLikeAFormDropdownElement(form, 'platform');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('submitting the form', () => {
|
|
it('validates the name field', () => {
|
|
const spy = createSpy();
|
|
const props = { ...defaultProps, handleSubmit: spy };
|
|
const form = mount(<LabelForm {...props} />);
|
|
const htmlForm = form.find('form');
|
|
|
|
|
|
htmlForm.simulate('submit');
|
|
|
|
expect(spy).toNotHaveBeenCalled();
|
|
expect(form.state('errors')).toInclude({
|
|
name: 'Label title must be present',
|
|
});
|
|
});
|
|
|
|
it('submits the form when valid', () => {
|
|
const spy = createSpy();
|
|
const props = { ...defaultProps, handleSubmit: spy, formData: { query: 'select * from users' } };
|
|
const form = mount(<LabelForm {...props} />);
|
|
const nameField = form.find({ name: 'name' }).find('input');
|
|
const descriptionField = form.find({ name: 'description' }).find('textarea');
|
|
const htmlForm = form.find('form');
|
|
|
|
fillInFormInput(nameField, 'My new label');
|
|
fillInFormInput(descriptionField, 'This is my new label');
|
|
itBehavesLikeAFormDropdownElement(form, 'platform');
|
|
htmlForm.simulate('submit');
|
|
|
|
expect(spy).toHaveBeenCalledWith({
|
|
name: 'My new label',
|
|
description: 'This is my new label',
|
|
platform: '',
|
|
query: 'select * from users',
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|