move OptionsList to components; add launch prompt tests

This commit is contained in:
Keith Grant 2020-03-31 13:59:14 -07:00
parent 4f51c1d2c9
commit 7710ad2e57
16 changed files with 156 additions and 14 deletions

View File

@ -30,7 +30,9 @@ describe('LaunchButton', () => {
id: 1,
type: 'job_template',
};
afterEach(() => jest.clearAllMocks());
test('renders the expected content', () => {
const wrapper = mountWithContexts(
<LaunchButton resource={resource}>{children}</LaunchButton>

View File

@ -6,8 +6,7 @@ import { useField } from 'formik';
import { InventoriesAPI } from '@api';
import { getQSConfig, parseQueryString } from '@util/qs';
import useRequest from '@util/useRequest';
// TODO move OptionsList out of Lookup/shared
import { OptionsList } from '@components/Lookup';
import OptionsList from '@components/OptionsList';
import ContentLoading from '@components/ContentLoading';
const QS_CONFIG = getQSConfig('inventory', {

View File

@ -0,0 +1,40 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { Formik } from 'formik';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import InventoryStep from './InventoryStep';
import { InventoriesAPI } from '@api';
jest.mock('@api/models/Inventories');
const inventories = [
{ id: 1, name: 'inv one', url: '/inventories/1' },
{ id: 2, name: 'inv two', url: '/inventories/2' },
{ id: 3, name: 'inv three', url: '/inventories/3' },
];
describe('InventoryStep', () => {
beforeEach(() => {
InventoriesAPI.read.mockResolvedValue({
data: {
results: inventories,
count: 3,
},
});
});
test('should load inventories', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<Formik>
<InventoryStep />
</Formik>
);
});
wrapper.update();
expect(InventoriesAPI.read).toHaveBeenCalled();
expect(wrapper.find('OptionsList').prop('options')).toEqual(inventories);
});
});

View File

@ -84,4 +84,5 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
);
}
export { LaunchPrompt as _LaunchPrompt };
export default withI18n()(LaunchPrompt);

View File

@ -0,0 +1,100 @@
import React from 'react';
import { act, isElementOfType } from 'react-dom/test-utils';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import LaunchPrompt from './LaunchPrompt';
import InventoryStep from './InventoryStep';
import PreviewStep from './PreviewStep';
import { InventoriesAPI } from '@api';
jest.mock('@api/models/Inventories');
let config;
const resource = {
id: 1,
type: 'job_template',
};
const noop = () => {};
describe('LaunchPrompt', () => {
beforeEach(() => {
InventoriesAPI.read.mockResolvedValue({
data: {
results: [{ id: 1, name: 'foo', url: '/inventories/1' }],
count: 1,
},
});
config = {
can_start_without_user_input: false,
passwords_needed_to_start: [],
ask_scm_branch_on_launch: false,
ask_variables_on_launch: false,
ask_tags_on_launch: false,
ask_diff_mode_on_launch: false,
ask_skip_tags_on_launch: false,
ask_job_type_on_launch: false,
ask_limit_on_launch: false,
ask_verbosity_on_launch: false,
ask_inventory_on_launch: false,
ask_credential_on_launch: false,
survey_enabled: false,
variables_needed_to_start: [],
credential_needed_to_start: false,
inventory_needed_to_start: false,
job_template_data: { name: 'JT with prompts', id: 25, description: '' },
};
});
afterEach(() => jest.clearAllMocks());
test('should render Wizard with all steps', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<LaunchPrompt
config={{
...config,
ask_inventory_on_launch: true,
ask_credential_on_launch: true,
ask_scm_branch_on_launch: true,
survey_enabled: true,
}}
resource={resource}
onLaunch={noop}
onCancel={noop}
/>
);
});
const steps = wrapper.find('Wizard').prop('steps');
expect(steps).toHaveLength(5);
expect(steps[0].name).toEqual('Inventory');
expect(steps[1].name).toEqual('Credential');
expect(steps[2].name).toEqual('Other Prompts');
expect(steps[3].name).toEqual('Survey');
expect(steps[4].name).toEqual('Preview');
});
test('should add inventory step', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<LaunchPrompt
config={{
...config,
ask_inventory_on_launch: true,
}}
resource={resource}
onLaunch={noop}
onCancel={noop}
/>
);
});
const steps = wrapper.find('Wizard').prop('steps');
expect(steps).toHaveLength(2);
expect(steps[0].name).toEqual('Inventory');
expect(isElementOfType(steps[0].component, InventoryStep)).toEqual(true);
expect(isElementOfType(steps[1].component, PreviewStep)).toEqual(true);
});
});

View File

@ -9,7 +9,7 @@ import { getQSConfig, parseQueryString, mergeParams } from '@util/qs';
import { FieldTooltip } from '@components/FormField';
import { FormGroup } from '@patternfly/react-core';
import Lookup from '@components/Lookup';
import OptionsList from './shared/OptionsList';
import OptionsList from '@components/OptionsList';
import LookupErrorMessage from './shared/LookupErrorMessage';
const QS_CONFIG = getQSConfig('credentials', {

View File

@ -7,8 +7,8 @@ import { FormGroup } from '@patternfly/react-core';
import { InstanceGroupsAPI } from '@api';
import { getQSConfig, parseQueryString } from '@util/qs';
import { FieldTooltip } from '@components/FormField';
import OptionsList from '@components/OptionsList';
import Lookup from './Lookup';
import OptionsList from './shared/OptionsList';
import LookupErrorMessage from './shared/LookupErrorMessage';
const QS_CONFIG = getQSConfig('instance_groups', {

View File

@ -6,8 +6,8 @@ import { t } from '@lingui/macro';
import { InventoriesAPI } from '@api';
import { Inventory } from '@types';
import Lookup from '@components/Lookup';
import OptionsList from '@components/OptionsList';
import { getQSConfig, parseQueryString } from '@util/qs';
import OptionsList from './shared/OptionsList';
import LookupErrorMessage from './shared/LookupErrorMessage';
const QS_CONFIG = getQSConfig('inventory', {

View File

@ -7,9 +7,9 @@ import { ToolbarItem, Alert } from '@patternfly/react-core';
import { CredentialsAPI, CredentialTypesAPI } from '@api';
import AnsibleSelect from '@components/AnsibleSelect';
import CredentialChip from '@components/CredentialChip';
import OptionsList from '@components/OptionsList';
import { getQSConfig, parseQueryString } from '@util/qs';
import Lookup from './Lookup';
import OptionsList from './shared/OptionsList';
const QS_CONFIG = getQSConfig('credentials', {
page: 1,

View File

@ -7,8 +7,8 @@ import { OrganizationsAPI } from '@api';
import { Organization } from '@types';
import { FormGroup } from '@patternfly/react-core';
import { getQSConfig, parseQueryString } from '@util/qs';
import OptionsList from '@components/OptionsList';
import Lookup from './Lookup';
import OptionsList from './shared/OptionsList';
import LookupErrorMessage from './shared/LookupErrorMessage';
const QS_CONFIG = getQSConfig('organizations', {

View File

@ -7,9 +7,9 @@ import { FormGroup } from '@patternfly/react-core';
import { ProjectsAPI } from '@api';
import { Project } from '@types';
import { FieldTooltip } from '@components/FormField';
import OptionsList from '@components/OptionsList';
import { getQSConfig, parseQueryString } from '@util/qs';
import Lookup from './Lookup';
import OptionsList from './shared/OptionsList';
import LookupErrorMessage from './shared/LookupErrorMessage';
const QS_CONFIG = getQSConfig('project', {

View File

@ -3,4 +3,3 @@ export { default as InstanceGroupsLookup } from './InstanceGroupsLookup';
export { default as InventoryLookup } from './InventoryLookup';
export { default as ProjectLookup } from './ProjectLookup';
export { default as MultiCredentialsLookup } from './MultiCredentialsLookup';
export { default as OptionsList } from './shared/OptionsList';

View File

@ -11,10 +11,10 @@ import {
import styled from 'styled-components';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import SelectedList from '../../SelectedList';
import PaginatedDataList from '../../PaginatedDataList';
import CheckboxListItem from '../../CheckboxListItem';
import DataListToolbar from '../../DataListToolbar';
import SelectedList from '../SelectedList';
import PaginatedDataList from '../PaginatedDataList';
import CheckboxListItem from '../CheckboxListItem';
import DataListToolbar from '../DataListToolbar';
import { QSConfig, SearchColumns, SortColumns } from '@types';
const ModalList = styled.div`

View File

@ -0,0 +1 @@
export { default } from './OptionsList';

View File

@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import { Button, Modal } from '@patternfly/react-core';
import OptionsList from '@components/Lookup/shared/OptionsList';
import OptionsList from '@components/OptionsList';
import useRequest from '@util/useRequest';
import { getQSConfig, parseQueryString } from '@util/qs';
import useSelected from '@util/useSelected';