Merge pull request #12029 from nixocio/ui_issue_12008

Update when deleted is shown on job details
This commit is contained in:
Sarah Akus
2022-04-14 14:44:13 -04:00
committed by GitHub
2 changed files with 81 additions and 27 deletions

View File

@@ -93,7 +93,11 @@ function JobDetail({ job, inventorySourceLabels }) {
); );
const renderInventoryDetail = () => { const renderInventoryDetail = () => {
if (job.type !== 'project_update') { if (
job.type !== 'project_update' &&
job.type !== 'system_job' &&
job.type !== 'workflow_job'
) {
return inventory ? ( return inventory ? (
<Detail <Detail
dataCy="job-inventory" dataCy="job-inventory"
@@ -114,6 +118,60 @@ function JobDetail({ job, inventorySourceLabels }) {
<DeletedDetail label={t`Inventory`} /> <DeletedDetail label={t`Inventory`} />
); );
} }
if (job.type === 'workflow_job') {
return inventory ? (
<Detail
dataCy="job-inventory"
label={t`Inventory`}
value={
<Link
to={
inventory.kind === 'smart'
? `/inventories/smart_inventory/${inventory.id}`
: `/inventories/inventory/${inventory.id}`
}
>
{inventory.name}
</Link>
}
/>
) : null;
}
return null;
};
const renderProjectDetail = () => {
if (
job.type !== 'ad_hoc_command' &&
job.type !== 'inventory_update' &&
job.type !== 'system_job' &&
job.type !== 'workflow_job'
) {
return project ? (
<>
<Detail
dataCy="job-project"
label={t`Project`}
value={<Link to={`/projects/${project.id}`}>{project.name}</Link>}
/>
<Detail
dataCy="job-project-status"
label={t`Project Status`}
value={
projectUpdate ? (
<Link to={`/jobs/project/${projectUpdate.id}`}>
<StatusLabel status={project.status} />
</Link>
) : (
<StatusLabel status={project.status} />
)
}
/>
</>
) : (
<DeletedDetail label={t`Project`} />
);
}
return null; return null;
}; };
@@ -225,30 +283,7 @@ function JobDetail({ job, inventorySourceLabels }) {
} }
/> />
)} )}
{project ? ( {renderProjectDetail()}
<>
<Detail
dataCy="job-project"
label={t`Project`}
value={<Link to={`/projects/${project.id}`}>{project.name}</Link>}
/>
<Detail
dataCy="job-project-status"
label={t`Project Status`}
value={
projectUpdate ? (
<Link to={`/jobs/project/${projectUpdate.id}`}>
<StatusLabel status={project.status} />
</Link>
) : (
<StatusLabel status={project.status} />
)
}
/>
</>
) : (
<DeletedDetail label={t`Project`} />
)}
{scmBranch && ( {scmBranch && (
<Detail <Detail
dataCy="source-control-branch" dataCy="source-control-branch"

View File

@@ -63,7 +63,6 @@ describe('<JobDetail />', () => {
'Instance Group', 'Instance Group',
mockJobData.summary_fields.instance_group.name mockJobData.summary_fields.instance_group.name
); );
assertDetail('Job Slice', '0/1');
assertDetail('Credentials', 'SSH: Demo Credential'); assertDetail('Credentials', 'SSH: Demo Credential');
assertDetail('Machine Credential', 'SSH: Machine cred'); assertDetail('Machine Credential', 'SSH: Machine cred');
assertDetail('Source Control Branch', 'main'); assertDetail('Source Control Branch', 'main');
@@ -104,6 +103,23 @@ describe('<JobDetail />', () => {
expect(projectStatusLabel.prop('status')).toEqual('successful'); expect(projectStatusLabel.prop('status')).toEqual('successful');
}); });
test('should display Deleted for Inventory and Project for job type run', () => {
const job = {
...mockJobData,
summary_fields: {
...mockJobData.summary_fields,
project: null,
inventory: null,
},
project: null,
inventory: null,
};
wrapper = mountWithContexts(<JobDetail job={job} />);
expect(wrapper.find(`DeletedDetail[label="Project"]`).length).toBe(1);
expect(wrapper.find(`DeletedDetail[label="Inventory"]`).length).toBe(1);
});
test('should not display finished date', () => { test('should not display finished date', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<JobDetail <JobDetail
@@ -146,6 +162,7 @@ describe('<JobDetail />', () => {
assertDetail('Module Name', 'command'); assertDetail('Module Name', 'command');
assertDetail('Module Arguments', 'echo hello_world'); assertDetail('Module Arguments', 'echo hello_world');
assertDetail('Job Type', 'Run Command'); assertDetail('Job Type', 'Run Command');
expect(wrapper.find(`Detail[label="Project"]`).length).toBe(0);
}); });
test('should display source data', () => { test('should display source data', () => {
@@ -182,6 +199,7 @@ describe('<JobDetail />', () => {
/> />
); );
assertDetail('Source', 'Sourced from Project'); assertDetail('Source', 'Sourced from Project');
expect(wrapper.find(`Detail[label="Project"]`).length).toBe(0);
}); });
test('should show schedule that launched workflow job', async () => { test('should show schedule that launched workflow job', async () => {
@@ -215,7 +233,7 @@ describe('<JobDetail />', () => {
).toHaveLength(1); ).toHaveLength(1);
}); });
test('should hide "Launched By" detail for JT launched from a workflow launched by a schedule', async () => { test('should hide "Launched By" detail for JT launched from a workflow launched by a schedule', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<JobDetail <JobDetail
job={{ job={{
@@ -317,6 +335,7 @@ describe('<JobDetail />', () => {
expect( expect(
wrapper.find('Button[aria-label="Cancel Demo Job Template"]') wrapper.find('Button[aria-label="Cancel Demo Job Template"]')
).toHaveLength(0); ).toHaveLength(0);
expect(wrapper.find(`Detail[label="Project"]`).length).toBe(0);
}); });
test('should not show cancel job button, job completed', async () => { test('should not show cancel job button, job completed', async () => {