mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Adds tests
This commit is contained in:
committed by
Jeff Bradberry
parent
5d3a19e542
commit
d2c63a9b36
@@ -8,17 +8,11 @@ function InstanceAdd() {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [formError, setFormError] = useState();
|
const [formError, setFormError] = useState();
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values) => {
|
||||||
const { instanceGroups, executionEnvironment } = values;
|
|
||||||
values.execution_environment = executionEnvironment?.id;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { id },
|
data: { id },
|
||||||
} = await InstancesAPI.create();
|
} = await InstancesAPI.create(values);
|
||||||
|
|
||||||
for (const group of instanceGroups) {
|
|
||||||
await InstancesAPI.associateInstanceGroup(id, group.id);
|
|
||||||
}
|
|
||||||
history.push(`/instances/${id}/details`);
|
history.push(`/instances/${id}/details`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setFormError(err);
|
setFormError(err);
|
||||||
|
|||||||
53
awx/ui/src/screens/Instances/InstanceAdd/InstanceAdd.test.js
Normal file
53
awx/ui/src/screens/Instances/InstanceAdd/InstanceAdd.test.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
import { createMemoryHistory } from 'history';
|
||||||
|
import { InstancesAPI } from 'api';
|
||||||
|
import {
|
||||||
|
mountWithContexts,
|
||||||
|
waitForElement,
|
||||||
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
|
|
||||||
|
import InstanceAdd from './InstanceAdd';
|
||||||
|
|
||||||
|
jest.mock('../../../api');
|
||||||
|
|
||||||
|
describe('<InstanceAdd />', () => {
|
||||||
|
let wrapper;
|
||||||
|
let history;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
history = createMemoryHistory({ initialEntries: ['/instances'] });
|
||||||
|
InstancesAPI.create.mockResolvedValue({ data: { id: 13 } });
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(<InstanceAdd />, {
|
||||||
|
context: { router: { history } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Initially renders successfully', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
});
|
||||||
|
test('handleSubmit should call the api and redirect to details page', async () => {
|
||||||
|
await waitForElement(wrapper, 'isLoading', (el) => el.length === 0);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('InstanceForm').prop('handleSubmit')({
|
||||||
|
name: 'new Foo',
|
||||||
|
node_type: 'hop',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
expect(InstancesAPI.create).toHaveBeenCalledWith({
|
||||||
|
name: 'new Foo',
|
||||||
|
node_type: 'hop',
|
||||||
|
});
|
||||||
|
expect(history.location.pathname).toBe('/instances/13/details');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handleCancel should return the user back to the instances list', async () => {
|
||||||
|
await waitForElement(wrapper, 'isLoading', (el) => el.length === 0);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('Button[aria-label="Cancel"]').simulate('click');
|
||||||
|
});
|
||||||
|
expect(history.location.pathname).toEqual('/instances');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -10,12 +10,14 @@ import PaginatedTable, {
|
|||||||
HeaderRow,
|
HeaderRow,
|
||||||
HeaderCell,
|
HeaderCell,
|
||||||
getSearchableKeys,
|
getSearchableKeys,
|
||||||
|
ToolbarAddButton,
|
||||||
} from 'components/PaginatedTable';
|
} from 'components/PaginatedTable';
|
||||||
import AlertModal from 'components/AlertModal';
|
import AlertModal from 'components/AlertModal';
|
||||||
import ErrorDetail from 'components/ErrorDetail';
|
import ErrorDetail from 'components/ErrorDetail';
|
||||||
|
import { useConfig } from 'contexts/Config';
|
||||||
import useRequest, { useDismissableError } from 'hooks/useRequest';
|
import useRequest, { useDismissableError } from 'hooks/useRequest';
|
||||||
import useSelected from 'hooks/useSelected';
|
import useSelected from 'hooks/useSelected';
|
||||||
import { InstancesAPI } from 'api';
|
import { InstancesAPI, SettingsAPI } from 'api';
|
||||||
import { getQSConfig, parseQueryString } from 'util/qs';
|
import { getQSConfig, parseQueryString } from 'util/qs';
|
||||||
import HealthCheckButton from 'components/HealthCheckButton';
|
import HealthCheckButton from 'components/HealthCheckButton';
|
||||||
import InstanceListItem from './InstanceListItem';
|
import InstanceListItem from './InstanceListItem';
|
||||||
@@ -28,21 +30,24 @@ const QS_CONFIG = getQSConfig('instance', {
|
|||||||
|
|
||||||
function InstanceList() {
|
function InstanceList() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const { me } = useConfig();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
result: { instances, count, relatedSearchableKeys, searchableKeys },
|
result: { instances, count, relatedSearchableKeys, searchableKeys, isK8 },
|
||||||
error: contentError,
|
error: contentError,
|
||||||
isLoading,
|
isLoading,
|
||||||
request: fetchInstances,
|
request: fetchInstances,
|
||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
const params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
const [response, responseActions] = await Promise.all([
|
const [response, responseActions, sysSettings] = await Promise.all([
|
||||||
InstancesAPI.read(params),
|
InstancesAPI.read(params),
|
||||||
InstancesAPI.readOptions(),
|
InstancesAPI.readOptions(),
|
||||||
|
SettingsAPI.readCategory('system'),
|
||||||
]);
|
]);
|
||||||
return {
|
return {
|
||||||
instances: response.data.results,
|
instances: response.data.results,
|
||||||
|
isK8: sysSettings.data.IS_K8S,
|
||||||
count: response.data.count,
|
count: response.data.count,
|
||||||
actions: responseActions.data.actions,
|
actions: responseActions.data.actions,
|
||||||
relatedSearchableKeys: (
|
relatedSearchableKeys: (
|
||||||
@@ -57,6 +62,7 @@ function InstanceList() {
|
|||||||
actions: {},
|
actions: {},
|
||||||
relatedSearchableKeys: [],
|
relatedSearchableKeys: [],
|
||||||
searchableKeys: [],
|
searchableKeys: [],
|
||||||
|
isK8: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -89,6 +95,7 @@ function InstanceList() {
|
|||||||
|
|
||||||
const { expanded, isAllExpanded, handleExpand, expandAll } =
|
const { expanded, isAllExpanded, handleExpand, expandAll } =
|
||||||
useExpanded(instances);
|
useExpanded(instances);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageSection>
|
<PageSection>
|
||||||
@@ -135,6 +142,15 @@ function InstanceList() {
|
|||||||
onExpandAll={expandAll}
|
onExpandAll={expandAll}
|
||||||
qsConfig={QS_CONFIG}
|
qsConfig={QS_CONFIG}
|
||||||
additionalControls={[
|
additionalControls={[
|
||||||
|
...(isK8 && me.is_superuser
|
||||||
|
? [
|
||||||
|
<ToolbarAddButton
|
||||||
|
ouiaId="instances-add-button"
|
||||||
|
key="add"
|
||||||
|
linkTo="/instances/add"
|
||||||
|
/>,
|
||||||
|
]
|
||||||
|
: []),
|
||||||
<HealthCheckButton
|
<HealthCheckButton
|
||||||
onClick={handleHealthCheck}
|
onClick={handleHealthCheck}
|
||||||
selectedItems={selected}
|
selectedItems={selected}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { act } from 'react-dom/test-utils';
|
|||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import { createMemoryHistory } from 'history';
|
import { createMemoryHistory } from 'history';
|
||||||
|
|
||||||
import { InstancesAPI } from 'api';
|
import { InstancesAPI, SettingsAPI } from 'api';
|
||||||
import {
|
import {
|
||||||
mountWithContexts,
|
mountWithContexts,
|
||||||
waitForElement,
|
waitForElement,
|
||||||
@@ -111,6 +111,7 @@ describe('<InstanceList/>', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
InstancesAPI.readOptions.mockResolvedValue(options);
|
InstancesAPI.readOptions.mockResolvedValue(options);
|
||||||
|
SettingsAPI.readCategory.mockResolvedValue({ data: { IS_K8S: false } });
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/instances/1'],
|
initialEntries: ['/instances/1'],
|
||||||
});
|
});
|
||||||
@@ -190,4 +191,52 @@ describe('<InstanceList/>', () => {
|
|||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('AlertModal')).toHaveLength(1);
|
expect(wrapper.find('AlertModal')).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
test('Should not show Add button', () => {
|
||||||
|
expect(wrapper.find('Button[ouiaId="instances-add-button"]')).toHaveLength(
|
||||||
|
0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('InstanceList should show Add button', () => {
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
|
const options = { data: { actions: { POST: true } } };
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
InstancesAPI.read.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
count: instances.length,
|
||||||
|
results: instances,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
InstancesAPI.readOptions.mockResolvedValue(options);
|
||||||
|
SettingsAPI.readCategory.mockResolvedValue({ data: { IS_K8S: true } });
|
||||||
|
const history = createMemoryHistory({
|
||||||
|
initialEntries: ['/instances/1'],
|
||||||
|
});
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Route path="/instances/:id">
|
||||||
|
<InstanceList />
|
||||||
|
</Route>,
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
router: { history, route: { location: history.location } },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should show Add button', () => {
|
||||||
|
expect(wrapper.find('Button[ouiaId="instances-add-button"]')).toHaveLength(
|
||||||
|
1
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import ScreenHeader from 'components/ScreenHeader';
|
|||||||
import PersistentFilters from 'components/PersistentFilters';
|
import PersistentFilters from 'components/PersistentFilters';
|
||||||
import { InstanceList } from './InstanceList';
|
import { InstanceList } from './InstanceList';
|
||||||
import Instance from './Instance';
|
import Instance from './Instance';
|
||||||
|
import InstanceAdd from './InstanceAdd';
|
||||||
|
|
||||||
function Instances() {
|
function Instances() {
|
||||||
const [breadcrumbConfig, setBreadcrumbConfig] = useState({
|
const [breadcrumbConfig, setBreadcrumbConfig] = useState({
|
||||||
'/instances': t`Instances`,
|
'/instances': t`Instances`,
|
||||||
|
'/instances/add': t`Create new Instance`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildBreadcrumbConfig = useCallback((instance) => {
|
const buildBreadcrumbConfig = useCallback((instance) => {
|
||||||
@@ -27,6 +29,9 @@ function Instances() {
|
|||||||
<>
|
<>
|
||||||
<ScreenHeader streamType="instance" breadcrumbConfig={breadcrumbConfig} />
|
<ScreenHeader streamType="instance" breadcrumbConfig={breadcrumbConfig} />
|
||||||
<Switch>
|
<Switch>
|
||||||
|
<Route path="/instances/add">
|
||||||
|
<InstanceAdd />
|
||||||
|
</Route>
|
||||||
<Route path="/instances/:id">
|
<Route path="/instances/:id">
|
||||||
<Instance setBreadcrumb={buildBreadcrumbConfig} />
|
<Instance setBreadcrumb={buildBreadcrumbConfig} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -1,40 +1,36 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Formik, useField } from 'formik';
|
import { Formik, useField } from 'formik';
|
||||||
import { Form, FormGroup, CardBody } from '@patternfly/react-core';
|
import {
|
||||||
|
Form,
|
||||||
|
FormGroup,
|
||||||
|
CardBody,
|
||||||
|
Switch,
|
||||||
|
Popover,
|
||||||
|
} from '@patternfly/react-core';
|
||||||
import { FormColumnLayout } from 'components/FormLayout';
|
import { FormColumnLayout } from 'components/FormLayout';
|
||||||
import FormField, { FormSubmitError } from 'components/FormField';
|
import FormField, { FormSubmitError } from 'components/FormField';
|
||||||
import FormActionGroup from 'components/FormActionGroup';
|
import FormActionGroup from 'components/FormActionGroup';
|
||||||
import { required } from 'util/validators';
|
import { required } from 'util/validators';
|
||||||
import AnsibleSelect from 'components/AnsibleSelect';
|
import AnsibleSelect from 'components/AnsibleSelect';
|
||||||
import {
|
|
||||||
ExecutionEnvironmentLookup,
|
|
||||||
InstanceGroupsLookup,
|
|
||||||
} from 'components/Lookup';
|
|
||||||
|
|
||||||
// This is hard coded because the API does not have the ability to send us a list that contains
|
// This is hard coded because the API does not have the ability to send us a list that contains
|
||||||
// only the types of instances that can be added. Control and Hybrid instances cannot be added.
|
// only the types of instances that can be added. Control and Hybrid instances cannot be added.
|
||||||
|
|
||||||
const INSTANCE_TYPES = [
|
const INSTANCE_TYPES = [
|
||||||
{ id: 2, name: t`Execution`, value: 'execution' },
|
{ id: 'execution', name: t`Execution` },
|
||||||
{ id: 3, name: t`Hop`, value: 'hop' },
|
{ id: 'hop', name: t`Hop` },
|
||||||
];
|
];
|
||||||
|
|
||||||
function InstanceFormFields() {
|
function InstanceFormFields() {
|
||||||
const [instanceType, , instanceTypeHelpers] = useField('type');
|
const [instanceType, , instanceTypeHelpers] = useField('node_type');
|
||||||
const [instanceGroupsField, , instanceGroupsHelpers] =
|
const [enabled, , enabledHelpers] = useField('enabled');
|
||||||
useField('instanceGroups');
|
|
||||||
const [
|
|
||||||
executionEnvironmentField,
|
|
||||||
executionEnvironmentMeta,
|
|
||||||
executionEnvironmentHelpers,
|
|
||||||
] = useField('executionEnvironment');
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormField
|
<FormField
|
||||||
id="instance-name"
|
id="name"
|
||||||
label={t`Name`}
|
label={t`Name`}
|
||||||
name="name"
|
name="hostname"
|
||||||
type="text"
|
type="text"
|
||||||
validate={required(null)}
|
validate={required(null)}
|
||||||
isRequired
|
isRequired
|
||||||
@@ -45,6 +41,20 @@ function InstanceFormFields() {
|
|||||||
name="description"
|
name="description"
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
|
<FormField
|
||||||
|
id="instance-state"
|
||||||
|
label={t`Instance State`}
|
||||||
|
name="node_state"
|
||||||
|
type="text"
|
||||||
|
isDisabled
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
id="instance-port"
|
||||||
|
label={t`Listener Port`}
|
||||||
|
name="listener_port"
|
||||||
|
type="number"
|
||||||
|
isRequired
|
||||||
|
/>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
fieldId="instanceType"
|
fieldId="instanceType"
|
||||||
label={t`Instance Type`}
|
label={t`Instance Type`}
|
||||||
@@ -57,9 +67,8 @@ function InstanceFormFields() {
|
|||||||
id="instanceType-select"
|
id="instanceType-select"
|
||||||
data={INSTANCE_TYPES.map((type) => ({
|
data={INSTANCE_TYPES.map((type) => ({
|
||||||
key: type.id,
|
key: type.id,
|
||||||
value: type.value,
|
value: type.id,
|
||||||
label: type.name,
|
label: type.name,
|
||||||
isDisabled: false,
|
|
||||||
}))}
|
}))}
|
||||||
value={instanceType.value}
|
value={instanceType.value}
|
||||||
onChange={(e, opt) => {
|
onChange={(e, opt) => {
|
||||||
@@ -67,25 +76,27 @@ function InstanceFormFields() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<InstanceGroupsLookup
|
<FormGroup
|
||||||
value={instanceGroupsField.value}
|
label={t`Enable Instance`}
|
||||||
onChange={(value) => {
|
aria-label={t`Enable Instance`}
|
||||||
instanceGroupsHelpers.setValue(value);
|
labelIcon={
|
||||||
}}
|
<Popover
|
||||||
fieldName="instanceGroups"
|
content={t`If enabled, the instance will be ready to accept work.`}
|
||||||
/>
|
/>
|
||||||
<ExecutionEnvironmentLookup
|
|
||||||
helperTextInvalid={executionEnvironmentMeta.error}
|
|
||||||
isValid={
|
|
||||||
!executionEnvironmentMeta.touched || !executionEnvironmentMeta.error
|
|
||||||
}
|
}
|
||||||
fieldName={executionEnvironmentField.name}
|
>
|
||||||
onBlur={() => executionEnvironmentHelpers.setTouched()}
|
<Switch
|
||||||
value={executionEnvironmentField.value}
|
css="display: inline-flex;"
|
||||||
onChange={(value) => {
|
id="enabled"
|
||||||
executionEnvironmentHelpers.setValue(value);
|
label={t`Enabled`}
|
||||||
}}
|
labelOff={t`Disabled`}
|
||||||
/>
|
isChecked={enabled.value}
|
||||||
|
onChange={() => {
|
||||||
|
enabledHelpers.setValue(!enabled.value);
|
||||||
|
}}
|
||||||
|
ouiaId="enable-instance-switch"
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -100,11 +111,12 @@ function InstanceForm({
|
|||||||
<CardBody>
|
<CardBody>
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
name: instance.name || '',
|
hostname: '',
|
||||||
description: instance.description || '',
|
description: '',
|
||||||
type: instance.type || 'execution',
|
node_type: 'execution',
|
||||||
instanceGroups: instance.instance_groups || [],
|
node_state: 'Installed',
|
||||||
executionEnvironment: instance.execution_environment || null,
|
listener_port: 27199,
|
||||||
|
enabled: true,
|
||||||
}}
|
}}
|
||||||
onSubmit={(values) => {
|
onSubmit={(values) => {
|
||||||
handleSubmit(values);
|
handleSubmit(values);
|
||||||
|
|||||||
98
awx/ui/src/screens/Instances/Shared/InstanceForm.test.js
Normal file
98
awx/ui/src/screens/Instances/Shared/InstanceForm.test.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
import {
|
||||||
|
mountWithContexts,
|
||||||
|
waitForElement,
|
||||||
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
|
|
||||||
|
import InstanceForm from './InstanceForm';
|
||||||
|
|
||||||
|
jest.mock('../../../api');
|
||||||
|
|
||||||
|
describe('<InstanceForm />', () => {
|
||||||
|
let wrapper;
|
||||||
|
let handleCancel;
|
||||||
|
let handleSubmit;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
handleCancel = jest.fn();
|
||||||
|
handleSubmit = jest.fn();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<InstanceForm
|
||||||
|
handleCancel={handleCancel}
|
||||||
|
handleSubmit={handleSubmit}
|
||||||
|
submitError={null}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Initially renders successfully', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should display form fields properly', async () => {
|
||||||
|
await waitForElement(wrapper, 'InstanceForm', (el) => el.length > 0);
|
||||||
|
expect(wrapper.find('FormGroup[label="Name"]').length).toBe(1);
|
||||||
|
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
|
||||||
|
expect(wrapper.find('FormGroup[label="Instance State"]').length).toBe(1);
|
||||||
|
expect(wrapper.find('FormGroup[label="Listener Port"]').length).toBe(1);
|
||||||
|
expect(wrapper.find('FormGroup[label="Instance Type"]').length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update form values', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('input#name').simulate('change', {
|
||||||
|
target: { value: 'new Foo', name: 'hostname' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('input#name').prop('value')).toEqual('new Foo');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should call handleCancel when Cancel button is clicked', async () => {
|
||||||
|
expect(handleCancel).not.toHaveBeenCalled();
|
||||||
|
wrapper.find('button[aria-label="Cancel"]').invoke('onClick')();
|
||||||
|
wrapper.update();
|
||||||
|
expect(handleCancel).toBeCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should call handleSubmit when Cancel button is clicked', async () => {
|
||||||
|
expect(handleSubmit).not.toHaveBeenCalled();
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('input#name').simulate('change', {
|
||||||
|
target: { value: 'new Foo', name: 'hostname' },
|
||||||
|
});
|
||||||
|
wrapper.find('input#instance-description').simulate('change', {
|
||||||
|
target: { value: 'This is a repeat song', name: 'description' },
|
||||||
|
});
|
||||||
|
wrapper.find('input#instance-port').simulate('change', {
|
||||||
|
target: { value: 'This is a repeat song', name: 'listener_port' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(
|
||||||
|
wrapper.find('FormField[label="Instance State"]').prop('isDisabled')
|
||||||
|
).toBe(true);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('button[aria-label="Save"]').invoke('onClick')();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(handleSubmit).toBeCalledWith({
|
||||||
|
description: 'This is a repeat song',
|
||||||
|
enabled: true,
|
||||||
|
hostname: 'new Foo',
|
||||||
|
listener_port: 'This is a repeat song',
|
||||||
|
node_state: 'Installed',
|
||||||
|
node_type: 'execution',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user