Fixes translation omissions

This commit is contained in:
Alex Corey
2019-09-24 11:19:05 -04:00
parent 1ebe91cbf7
commit 1316ace475
2 changed files with 59 additions and 27 deletions

View File

@@ -12,7 +12,14 @@ import { VariablesInput as _VariablesInput } from '@components/CodeMirrorInput';
import ErrorDetail from '@components/ErrorDetail'; import ErrorDetail from '@components/ErrorDetail';
import { toTitleCase } from '@util/strings'; import { toTitleCase } from '@util/strings';
import { Job } from '../../../types'; import { Job } from '../../../types';
import { JobsAPI, ProjectUpdatesAPI } from '@api'; import {
JobsAPI,
ProjectUpdatesAPI,
SystemJobsAPI,
WorkflowJobsAPI,
InventoriesAPI,
AdHocCommandsAPI,
} from '@api';
import { JOB_TYPE_URL_SEGMENTS } from '../../../constants'; import { JOB_TYPE_URL_SEGMENTS } from '../../../constants';
const ActionButtonWrapper = styled.div` const ActionButtonWrapper = styled.div`
@@ -47,20 +54,34 @@ function JobDetail({ job, i18n, history }) {
credentials, credentials,
labels, labels,
} = job.summary_fields; } = job.summary_fields;
const [isDeleteModalOpen, setDeleteModal] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [errorMsg, setErrorMsg] = useState(); const [errorMsg, setErrorMsg] = useState();
const deleteJob = async () => { const deleteJob = async () => {
try { try {
if (job.type === 'job') { switch (job.type) {
await JobsAPI.destroy(job.id); case 'project_update':
} else { await ProjectUpdatesAPI.destroy(job.id);
await ProjectUpdatesAPI.destroy(job.id); break;
case 'system_job':
await SystemJobsAPI.destroy(job.id);
break;
case 'workflow_job':
await WorkflowJobsAPI.destroy(job.id);
break;
case 'ad_hoc_command':
await AdHocCommandsAPI.destroy(job.id);
break;
case 'inventory_update':
await InventoriesAPI.destroy(job.id);
break;
default:
await JobsAPI.destroy(job.id);
} }
history.push('/jobs'); history.push('/jobs');
} catch (err) { } catch (err) {
setErrorMsg(err); setErrorMsg(err);
setDeleteModal(false); setIsDeleteModalOpen(false);
} }
}; };
return ( return (
@@ -171,8 +192,8 @@ function JobDetail({ job, i18n, history }) {
<ActionButtonWrapper> <ActionButtonWrapper>
<Button <Button
variant="danger" variant="danger"
aria-label="delete" aria-label={i18n._(t`Delete`)}
onClick={() => setDeleteModal(true)} onClick={() => setIsDeleteModalOpen(true)}
> >
{i18n._(t`Delete`)} {i18n._(t`Delete`)}
</Button> </Button>
@@ -190,7 +211,7 @@ function JobDetail({ job, i18n, history }) {
isOpen={isDeleteModalOpen} isOpen={isDeleteModalOpen}
title={i18n._(t`Delete Job`)} title={i18n._(t`Delete Job`)}
variant="danger" variant="danger"
onClose={() => setDeleteModal(false)} onClose={() => setIsDeleteModalOpen(false)}
> >
{i18n._(t`Are you sure you want to delete:`)} {i18n._(t`Are you sure you want to delete:`)}
<br /> <br />
@@ -198,13 +219,17 @@ function JobDetail({ job, i18n, history }) {
<ActionButtonWrapper> <ActionButtonWrapper>
<Button <Button
variant="secondary" variant="secondary"
aria-label="close" aria-label={i18n._(t`Close`)}
component={Link} component={Link}
to={`/jobs/${JOB_TYPE_URL_SEGMENTS[job.type]}/${job.id}`} to={`/jobs/${JOB_TYPE_URL_SEGMENTS[job.type]}/${job.id}`}
> >
{i18n._(t`Cancel`)} {i18n._(t`Cancel`)}
</Button> </Button>
<Button variant="danger" aria-label="delete" onClick={deleteJob}> <Button
variant="danger"
aria-label={i18n._(t`Delete`)}
onClick={deleteJob}
>
{i18n._(t`Delete`)} {i18n._(t`Delete`)}
</Button> </Button>
</ActionButtonWrapper> </ActionButtonWrapper>

View File

@@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { act } from 'react-dom/test-utils';
import { mountWithContexts } from '@testUtils/enzymeHelpers'; import { mountWithContexts } from '@testUtils/enzymeHelpers';
import { sleep } from '@testUtils/testUtils'; import { sleep } from '@testUtils/testUtils';
import JobDetail from './JobDetail'; import JobDetail from './JobDetail';
@@ -61,7 +62,7 @@ describe('<JobDetail />', () => {
job.summary_fields.credentials[0] job.summary_fields.credentials[0]
); );
}); });
test('should properly delete job', () => { test('should properly delete job', async () => {
job = { job = {
name: 'Rage', name: 'Rage',
id: 1, id: 1,
@@ -74,28 +75,25 @@ describe('<JobDetail />', () => {
wrapper wrapper
.find('button') .find('button')
.at(0) .at(0)
.invoke('onClick')(); .simulate('click');
await sleep(1);
wrapper.update();
const modal = wrapper.find('Modal'); const modal = wrapper.find('Modal');
expect(modal.length).toBe(1); expect(modal.length).toBe(1);
modal.find('button[aria-label="delete"]').invoke('onClick')(); modal.find('button[aria-label="Delete"]').simulate('click');
expect(JobsAPI.destroy).toHaveBeenCalledTimes(1); expect(JobsAPI.destroy).toHaveBeenCalledTimes(1);
}); });
// The test below is skipped until react can be upgraded to at least 16.9.0. An upgrade to
test('should display error modal when a job does not delete properly', async () => { // react - router will likely be necessary also.
test.skip('should display error modal when a job does not delete properly', async () => {
job = { job = {
name: 'Angry', name: 'Angry',
id: 'a', id: 'a',
type: 'project_updates', type: 'project_update',
summary_fields: { summary_fields: {
job_template: { name: 'Peanut' }, job_template: { name: 'Peanut' },
}, },
}; };
const wrapper = mountWithContexts(<JobDetail job={job} />);
wrapper
.find('button')
.at(0)
.invoke('onClick')();
const modal = wrapper.find('Modal');
ProjectUpdatesAPI.destroy.mockRejectedValue( ProjectUpdatesAPI.destroy.mockRejectedValue(
new Error({ new Error({
response: { response: {
@@ -108,10 +106,19 @@ describe('<JobDetail />', () => {
}, },
}) })
); );
modal.find('button[aria-label="delete"]').invoke('onClick')(); const wrapper = mountWithContexts(<JobDetail job={job} />);
await sleep(1);
wrapper
.find('button')
.at(0)
.simulate('click');
const modal = wrapper.find('Modal');
await act(async () => {
await modal.find('Button[variant="danger"]').prop('onClick')();
});
wrapper.update(); wrapper.update();
const errorModal = wrapper.find('ErrorDetail__Expandable');
const errorModal = wrapper.find('ErrorDetail');
expect(errorModal.length).toBe(1); expect(errorModal.length).toBe(1);
}); });
}); });