mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
* API client to create and get an app license * Fixes unhandled promise rejection errors in redux config * License Page and Form * Adds getLicense action * Adds License key area to App Settings Form * Use license.token instead of license.license * Implement API client * Adds key icon to License Form * Adds License Success component * Render License Success on License Page when there is a license * Adds persistent flash actions and reducer to redux * Adds nag message middleware * Moves FlashMessage component to flash_message directory * Adds Persistent Flash component * Renders Persistent Flash component from Core Layout * Adds Kyle's styles * Change license validation message * Finishing touches for app config form license area * Handle revoked licenses * License Page hits setup endpoint * Display server errors on license form * Changes 0 allowed hosts to unlimited * Trims JWT token before sending to the server * GET setup page after submitting license
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import React from 'react';
|
|
import expect, { createSpy, restoreSpies } from 'expect';
|
|
import { mount } from 'enzyme';
|
|
import { noop } from 'lodash';
|
|
|
|
import { fillInFormInput, itBehavesLikeAFormInputElement } from 'test/helpers';
|
|
import LicenseForm from 'components/forms/LicenseForm';
|
|
|
|
const defaultProps = {
|
|
handleSubmit: noop,
|
|
};
|
|
|
|
describe('LicenseForm - component', () => {
|
|
describe('rendering', () => {
|
|
it('renders', () => {
|
|
expect(mount(<LicenseForm {...defaultProps} />).length).toEqual(1);
|
|
});
|
|
});
|
|
|
|
describe('license input', () => {
|
|
const Form = mount(<LicenseForm {...defaultProps} />);
|
|
|
|
it('renders an input field', () => {
|
|
itBehavesLikeAFormInputElement(Form, 'license', 'textarea');
|
|
});
|
|
});
|
|
|
|
describe('submitting the form', () => {
|
|
afterEach(restoreSpies);
|
|
|
|
it('calls the handleSubmit prop when valid', () => {
|
|
const spy = createSpy();
|
|
const props = { handleSubmit: spy };
|
|
const Form = mount(<LicenseForm {...props} />);
|
|
const LicenseField = Form.find({ name: 'license' }).find('textarea');
|
|
const jwtToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ';
|
|
|
|
fillInFormInput(LicenseField, jwtToken);
|
|
|
|
Form.simulate('submit');
|
|
|
|
expect(spy).toHaveBeenCalledWith({ license: jwtToken });
|
|
});
|
|
|
|
it('does not submit when invalid', () => {
|
|
const spy = createSpy();
|
|
const props = { handleSubmit: spy };
|
|
const Form = mount(<LicenseForm {...props} />);
|
|
const LicenseField = Form.find({ name: 'license' }).find('textarea');
|
|
const jwtToken = 'invalid.token';
|
|
|
|
fillInFormInput(LicenseField, jwtToken);
|
|
|
|
Form.simulate('submit');
|
|
|
|
expect(spy).toNotHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|