mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
Update usage of summary_fields for execution environments (#8217)
Update usage of summary_fields for execution environments. Also, update unit-tests to cover this change. See: https://github.com/ansible/awx/issues/8216
This commit is contained in:
@@ -20,11 +20,11 @@ const WarningMessage = styled(Alert)`
|
|||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const requireNameOrUsername = props => {
|
const requiredField = props => {
|
||||||
const { name, username } = props;
|
const { name, username, image } = props;
|
||||||
if (!name && !username) {
|
if (!name && !username && !image) {
|
||||||
return new Error(
|
return new Error(
|
||||||
`One of 'name' or 'username' is required by ItemToDelete component.`
|
`One of 'name', 'username' or 'image' is required by ItemToDelete component.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
@@ -47,13 +47,24 @@ const requireNameOrUsername = props => {
|
|||||||
'ItemToDelete'
|
'ItemToDelete'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (image) {
|
||||||
|
checkPropTypes(
|
||||||
|
{
|
||||||
|
image: string,
|
||||||
|
},
|
||||||
|
{ image: props.image },
|
||||||
|
'prop',
|
||||||
|
'ItemToDelete'
|
||||||
|
);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ItemToDelete = shape({
|
const ItemToDelete = shape({
|
||||||
id: number.isRequired,
|
id: number.isRequired,
|
||||||
name: requireNameOrUsername,
|
name: requiredField,
|
||||||
username: requireNameOrUsername,
|
username: requiredField,
|
||||||
|
image: requiredField,
|
||||||
summary_fields: shape({
|
summary_fields: shape({
|
||||||
user_capabilities: shape({
|
user_capabilities: shape({
|
||||||
delete: bool.isRequired,
|
delete: bool.isRequired,
|
||||||
@@ -171,7 +182,7 @@ function ToolbarDeleteButton({
|
|||||||
<div>{i18n._(t`This action will delete the following:`)}</div>
|
<div>{i18n._(t`This action will delete the following:`)}</div>
|
||||||
{itemsToDelete.map(item => (
|
{itemsToDelete.map(item => (
|
||||||
<span key={item.id}>
|
<span key={item.id}>
|
||||||
<strong>{item.name || item.username}</strong>
|
<strong>{item.name || item.username || item.image}</strong>
|
||||||
<br />
|
<br />
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const executionEnvironments = {
|
|||||||
organization: null,
|
organization: null,
|
||||||
credential: null,
|
credential: null,
|
||||||
url: '/api/v2/execution_environments/1/',
|
url: '/api/v2/execution_environments/1/',
|
||||||
|
summary_fields: { user_capabilities: { edit: true, delete: true } },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
@@ -27,6 +28,7 @@ const executionEnvironments = {
|
|||||||
organization: null,
|
organization: null,
|
||||||
credential: null,
|
credential: null,
|
||||||
url: '/api/v2/execution_environments/2/',
|
url: '/api/v2/execution_environments/2/',
|
||||||
|
summary_fields: { user_capabilities: { edit: false, delete: true } },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
count: 2,
|
count: 2,
|
||||||
@@ -67,6 +69,81 @@ describe('<ExecutionEnvironmentList/>', () => {
|
|||||||
expect(ExecutionEnvironmentsAPI.readOptions).toBeCalled();
|
expect(ExecutionEnvironmentsAPI.readOptions).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should delete item successfully', async () => {
|
||||||
|
ExecutionEnvironmentsAPI.read.mockResolvedValue(executionEnvironments);
|
||||||
|
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(options);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(<ExecutionEnvironmentList />);
|
||||||
|
});
|
||||||
|
await waitForElement(
|
||||||
|
wrapper,
|
||||||
|
'ExecutionEnvironmentList',
|
||||||
|
el => el.length > 0
|
||||||
|
);
|
||||||
|
|
||||||
|
wrapper
|
||||||
|
.find('input#select-execution-environment-1')
|
||||||
|
.simulate('change', executionEnvironments.data.results[0]);
|
||||||
|
wrapper.update();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
wrapper.find('input#select-execution-environment-1').prop('checked')
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('Button[aria-label="Delete"]').prop('onClick')();
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('Button[aria-label="confirm delete"]').prop('onClick')();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ExecutionEnvironmentsAPI.destroy).toBeCalledWith(
|
||||||
|
executionEnvironments.data.results[0].id
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render deletion error modal', async () => {
|
||||||
|
ExecutionEnvironmentsAPI.destroy.mockRejectedValue(
|
||||||
|
new Error({
|
||||||
|
response: {
|
||||||
|
config: {
|
||||||
|
method: 'DELETE',
|
||||||
|
url: '/api/v2/execution_environments',
|
||||||
|
},
|
||||||
|
data: 'An error occurred',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ExecutionEnvironmentsAPI.read.mockResolvedValue(executionEnvironments);
|
||||||
|
ExecutionEnvironmentsAPI.readOptions.mockResolvedValue(options);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(<ExecutionEnvironmentList />);
|
||||||
|
});
|
||||||
|
waitForElement(wrapper, 'ExecutionEnvironmentList', el => el.length > 0);
|
||||||
|
|
||||||
|
wrapper
|
||||||
|
.find('input#select-execution-environment-1')
|
||||||
|
.simulate('change', 'a');
|
||||||
|
wrapper.update();
|
||||||
|
expect(
|
||||||
|
wrapper.find('input#select-execution-environment-1').prop('checked')
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
await act(async () =>
|
||||||
|
wrapper.find('Button[aria-label="Delete"]').prop('onClick')()
|
||||||
|
);
|
||||||
|
wrapper.update();
|
||||||
|
|
||||||
|
await act(async () =>
|
||||||
|
wrapper.find('Button[aria-label="confirm delete"]').prop('onClick')()
|
||||||
|
);
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('ErrorDetail').length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('should thrown content error', async () => {
|
test('should thrown content error', async () => {
|
||||||
ExecutionEnvironmentsAPI.read.mockRejectedValue(
|
ExecutionEnvironmentsAPI.read.mockRejectedValue(
|
||||||
new Error({
|
new Error({
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ describe('<ExecutionEnvironmentForm/>', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should display form fields properly', () => {
|
test('should display form fields properly', () => {
|
||||||
expect(wrapper.find('FormGroup[label="Image"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Image name"]').length).toBe(1);
|
||||||
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
|
expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1);
|
||||||
expect(wrapper.find('CredentialLookup').length).toBe(1);
|
expect(wrapper.find('CredentialLookup').length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user