Refactor job secondary label assignment

This commit is contained in:
Jake McDermott 2019-10-01 10:33:47 -04:00
parent d549877ebd
commit b4b2cf76f6
No known key found for this signature in database
GPG Key ID: 0E56ED990CDFCB4F
4 changed files with 35 additions and 35 deletions

View File

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

View File

@ -34,7 +34,7 @@
header-value="{{ job.id }} - {{ job.name }}"
header-state="{{ vm.getSref(job) }}"
header-tag="{{ vm.jobTypes[job.type] }}"
secondary-tag="{{ vm.getSliceJobDetails(job) || vm.getWebhookDetails(job) }}">
secondary-tag="{{ vm.getSecondaryTagLabel(job) }}">
</at-row-item>
<div class="at-Row-actions">
<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 './side-nav.unit';
import './side-nav-item.unit';
import './jobs-list-split-jobs.unit';
import './jobs-list.unit';
import './job-details-split-jobs.unit';
import './stream.unit';

View File

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