mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 22:37:41 -02:30
move OptionsList to components; add launch prompt tests
This commit is contained in:
@@ -30,7 +30,9 @@ describe('LaunchButton', () => {
|
|||||||
id: 1,
|
id: 1,
|
||||||
type: 'job_template',
|
type: 'job_template',
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => jest.clearAllMocks());
|
afterEach(() => jest.clearAllMocks());
|
||||||
|
|
||||||
test('renders the expected content', () => {
|
test('renders the expected content', () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<LaunchButton resource={resource}>{children}</LaunchButton>
|
<LaunchButton resource={resource}>{children}</LaunchButton>
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import { useField } from 'formik';
|
|||||||
import { InventoriesAPI } from '@api';
|
import { InventoriesAPI } from '@api';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import useRequest from '@util/useRequest';
|
import useRequest from '@util/useRequest';
|
||||||
// TODO move OptionsList out of Lookup/shared
|
import OptionsList from '@components/OptionsList';
|
||||||
import { OptionsList } from '@components/Lookup';
|
|
||||||
import ContentLoading from '@components/ContentLoading';
|
import ContentLoading from '@components/ContentLoading';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('inventory', {
|
const QS_CONFIG = getQSConfig('inventory', {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -84,4 +84,5 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { LaunchPrompt as _LaunchPrompt };
|
||||||
export default withI18n()(LaunchPrompt);
|
export default withI18n()(LaunchPrompt);
|
||||||
|
|||||||
100
awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx
Normal file
100
awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.test.jsx
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,7 +9,7 @@ import { getQSConfig, parseQueryString, mergeParams } from '@util/qs';
|
|||||||
import { FieldTooltip } from '@components/FormField';
|
import { FieldTooltip } from '@components/FormField';
|
||||||
import { FormGroup } from '@patternfly/react-core';
|
import { FormGroup } from '@patternfly/react-core';
|
||||||
import Lookup from '@components/Lookup';
|
import Lookup from '@components/Lookup';
|
||||||
import OptionsList from './shared/OptionsList';
|
import OptionsList from '@components/OptionsList';
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('credentials', {
|
const QS_CONFIG = getQSConfig('credentials', {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import { FormGroup } from '@patternfly/react-core';
|
|||||||
import { InstanceGroupsAPI } from '@api';
|
import { InstanceGroupsAPI } from '@api';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import { FieldTooltip } from '@components/FormField';
|
import { FieldTooltip } from '@components/FormField';
|
||||||
|
import OptionsList from '@components/OptionsList';
|
||||||
import Lookup from './Lookup';
|
import Lookup from './Lookup';
|
||||||
import OptionsList from './shared/OptionsList';
|
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('instance_groups', {
|
const QS_CONFIG = getQSConfig('instance_groups', {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import { t } from '@lingui/macro';
|
|||||||
import { InventoriesAPI } from '@api';
|
import { InventoriesAPI } from '@api';
|
||||||
import { Inventory } from '@types';
|
import { Inventory } from '@types';
|
||||||
import Lookup from '@components/Lookup';
|
import Lookup from '@components/Lookup';
|
||||||
|
import OptionsList from '@components/OptionsList';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import OptionsList from './shared/OptionsList';
|
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('inventory', {
|
const QS_CONFIG = getQSConfig('inventory', {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { ToolbarItem, Alert } from '@patternfly/react-core';
|
|||||||
import { CredentialsAPI, CredentialTypesAPI } from '@api';
|
import { CredentialsAPI, CredentialTypesAPI } from '@api';
|
||||||
import AnsibleSelect from '@components/AnsibleSelect';
|
import AnsibleSelect from '@components/AnsibleSelect';
|
||||||
import CredentialChip from '@components/CredentialChip';
|
import CredentialChip from '@components/CredentialChip';
|
||||||
|
import OptionsList from '@components/OptionsList';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import Lookup from './Lookup';
|
import Lookup from './Lookup';
|
||||||
import OptionsList from './shared/OptionsList';
|
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('credentials', {
|
const QS_CONFIG = getQSConfig('credentials', {
|
||||||
page: 1,
|
page: 1,
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import { OrganizationsAPI } from '@api';
|
|||||||
import { Organization } from '@types';
|
import { Organization } from '@types';
|
||||||
import { FormGroup } from '@patternfly/react-core';
|
import { FormGroup } from '@patternfly/react-core';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
|
import OptionsList from '@components/OptionsList';
|
||||||
import Lookup from './Lookup';
|
import Lookup from './Lookup';
|
||||||
import OptionsList from './shared/OptionsList';
|
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('organizations', {
|
const QS_CONFIG = getQSConfig('organizations', {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { FormGroup } from '@patternfly/react-core';
|
|||||||
import { ProjectsAPI } from '@api';
|
import { ProjectsAPI } from '@api';
|
||||||
import { Project } from '@types';
|
import { Project } from '@types';
|
||||||
import { FieldTooltip } from '@components/FormField';
|
import { FieldTooltip } from '@components/FormField';
|
||||||
|
import OptionsList from '@components/OptionsList';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import Lookup from './Lookup';
|
import Lookup from './Lookup';
|
||||||
import OptionsList from './shared/OptionsList';
|
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('project', {
|
const QS_CONFIG = getQSConfig('project', {
|
||||||
|
|||||||
@@ -3,4 +3,3 @@ export { default as InstanceGroupsLookup } from './InstanceGroupsLookup';
|
|||||||
export { default as InventoryLookup } from './InventoryLookup';
|
export { default as InventoryLookup } from './InventoryLookup';
|
||||||
export { default as ProjectLookup } from './ProjectLookup';
|
export { default as ProjectLookup } from './ProjectLookup';
|
||||||
export { default as MultiCredentialsLookup } from './MultiCredentialsLookup';
|
export { default as MultiCredentialsLookup } from './MultiCredentialsLookup';
|
||||||
export { default as OptionsList } from './shared/OptionsList';
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import {
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import SelectedList from '../../SelectedList';
|
import SelectedList from '../SelectedList';
|
||||||
import PaginatedDataList from '../../PaginatedDataList';
|
import PaginatedDataList from '../PaginatedDataList';
|
||||||
import CheckboxListItem from '../../CheckboxListItem';
|
import CheckboxListItem from '../CheckboxListItem';
|
||||||
import DataListToolbar from '../../DataListToolbar';
|
import DataListToolbar from '../DataListToolbar';
|
||||||
import { QSConfig, SearchColumns, SortColumns } from '@types';
|
import { QSConfig, SearchColumns, SortColumns } from '@types';
|
||||||
|
|
||||||
const ModalList = styled.div`
|
const ModalList = styled.div`
|
||||||
1
awx/ui_next/src/components/OptionsList/index.js
Normal file
1
awx/ui_next/src/components/OptionsList/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './OptionsList';
|
||||||
@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
|
|||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Button, Modal } from '@patternfly/react-core';
|
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 useRequest from '@util/useRequest';
|
||||||
import { getQSConfig, parseQueryString } from '@util/qs';
|
import { getQSConfig, parseQueryString } from '@util/qs';
|
||||||
import useSelected from '@util/useSelected';
|
import useSelected from '@util/useSelected';
|
||||||
|
|||||||
Reference in New Issue
Block a user