Refactor job secondary label assignment

This commit is contained in:
Jake McDermott
2019-10-01 10:33:47 -04:00
parent d549877ebd
commit b4b2cf76f6
4 changed files with 35 additions and 35 deletions

View File

@@ -142,28 +142,14 @@ function ListJobsController (
return { icon, link, value }; return { icon, link, value };
}); });
vm.getSliceJobDetails = (job) => { vm.getSecondaryTagLabel = (job) => {
if (!job.job_slice_count) { if (job.job_slice_number && job.job_slice_count && job.job_slice_count > 1) {
return null;
}
if (job.job_slice_count === 1) {
return null;
}
if (job.job_slice_number && job.job_slice_count) {
return `${strings.get('list.SLICE_JOB')} ${job.job_slice_number}/${job.job_slice_count}`; return `${strings.get('list.SLICE_JOB')} ${job.job_slice_number}/${job.job_slice_count}`;
} }
if (job.launch_type === 'webhook') {
return null; return strings.get('list.ROW_ITEM_LABEL_WEBHOOK');
};
vm.getWebhookDetails = (job) => {
if (job.launch_type !== 'webhook') {
return null;
} }
return null;
return strings.get('list.ROW_ITEM_LABEL_WEBHOOK');
}; };
vm.getTranslatedStatusString = (status) => { vm.getTranslatedStatusString = (status) => {

View File

@@ -34,7 +34,7 @@
header-value="{{ job.id }} - {{ job.name }}" header-value="{{ job.id }} - {{ job.name }}"
header-state="{{ vm.getSref(job) }}" header-state="{{ vm.getSref(job) }}"
header-tag="{{ vm.jobTypes[job.type] }}" header-tag="{{ vm.jobTypes[job.type] }}"
secondary-tag="{{ vm.getSliceJobDetails(job) || vm.getWebhookDetails(job) }}"> secondary-tag="{{ vm.getSecondaryTagLabel(job) }}">
</at-row-item> </at-row-item>
<div class="at-Row-actions"> <div class="at-Row-actions">
<at-relaunch job="job" ng-show="job.summary_fields.user_capabilities.start"> <at-relaunch job="job" ng-show="job.summary_fields.user_capabilities.start">

View File

@@ -6,6 +6,6 @@ import './file.unit';
import './layout.unit'; import './layout.unit';
import './side-nav.unit'; import './side-nav.unit';
import './side-nav-item.unit'; import './side-nav-item.unit';
import './jobs-list-split-jobs.unit'; import './jobs-list.unit';
import './job-details-split-jobs.unit'; import './job-details-split-jobs.unit';
import './stream.unit'; import './stream.unit';

View File

@@ -36,6 +36,9 @@ describe('View: Split Jobs List', () => {
if (str === 'list.SLICE_JOB') { if (str === 'list.SLICE_JOB') {
return 'Slice Job'; return 'Slice Job';
} }
if (str === 'list.ROW_ITEM_LABEL_WEBHOOK') {
return 'Webhook';
}
return ''; return '';
} }
}; };
@@ -96,40 +99,51 @@ describe('View: Split Jobs List', () => {
it('is created successfully', () => { it('is created successfully', () => {
expect(JobList).toBeDefined(); expect(JobList).toBeDefined();
}); });
it('has method "getSplitJobDetails"', () => { it('has method "getSecondaryTagLabel"', () => {
expect(JobList.getSliceJobDetails).toBeDefined(); expect(JobList.getSecondaryTagLabel).toBeDefined();
}); });
it('returns a string', () => { it('returns the expected string when slice data is available', () => {
const data = { const data = {
job_slice_number: 1, job_slice_number: 1,
job_slice_count: 2 job_slice_count: 2,
launch_type: 'manual',
}; };
const result = JobList.getSliceJobDetails(data); const result = JobList.getSecondaryTagLabel(data);
expect(result).toEqual('Slice Job 1/2'); expect(result).toEqual('Slice Job 1/2');
}); });
it('returns null when data is null', () => { it('returns null when slice data is null', () => {
const data = { const data = {
job_slice_number: null, job_slice_number: null,
job_slice_count: null job_slice_count: null,
launch_type: 'manual',
}; };
const result = JobList.getSliceJobDetails(data); const result = JobList.getSecondaryTagLabel(data);
expect(result).toBeNull(); expect(result).toBeNull();
}); });
it('returns null when data is undefined', () => { it('returns null when slice data is undefined', () => {
const data = { const data = {
job_slice_number: undefined, job_slice_number: undefined,
job_slice_count: undefined job_slice_count: undefined,
launch_type: 'manual',
}; };
const result = JobList.getSliceJobDetails(data); const result = JobList.getSecondaryTagLabel(data);
expect(result).toBeNull(); expect(result).toBeNull();
}); });
it('returns null when job is not a sliced job', () => { it('returns null when job is not a sliced or webhook job', () => {
const data = { const data = {
job_slice_number: null, job_slice_number: null,
job_slice_count: 1 job_slice_count: 1,
launch_type: 'manual',
}; };
const result = JobList.getSliceJobDetails(data); const result = JobList.getSecondaryTagLabel(data);
expect(result).toBeNull(); expect(result).toBeNull();
}); });
it('returns the expected string for webhook jobs', () => {
const data = {
launch_type: 'webhook',
};
const result = JobList.getSecondaryTagLabel(data);
expect(result).toEqual('Webhook');
});
}); });
}); });