Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {ExecutionComponent} from './execution.component';
import {Component, ViewChild} from "@angular/core";
import {Job, JobExecution} from "../../model/job";
import {JobsService} from "../../services/jobs.service";
import {ProductsService} from "../../services/products.service";
import {ConfigurationService} from "../../env/configuration.service";
import {ReactiveFormsModule} from "@angular/forms";
import {By} from "@angular/platform-browser";
import {of} from "rxjs";
import {ContentEditableDirective} from "../../directives/content-editable.directive";
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
@Component({
template: '<app-qa-job [job]="job" [queue]="queue"></app-qa-job>'
})
class HostComponent {
job: Job = {
job_arch_status: "ARCHIVED",
job_endtime: 1565212305634,
job_endtime_formatted: "08/07/2019, 02:11:45 PM",
job_id: 123,
job_name: "jobName",
job_starttime: 1564785856832,
job_starttime_formatted: "08/02/2019, 03:44:16 PM",
job_status: "QA_ACCEPTED",
jobspec_creation_date: 1563346880361,
jobspec_creation_date_formatted: "07/17/2019, 12:01:20 AM",
jobspec_id: 321,
jobspec_name: "JobSpecName",
jobspec_sdm_id: "JobSpecNameSDMid",
jobspec_status: "QA_ACCEPTED"
};
queue: string = 'calibration';
@ViewChild(ExecutionComponent, /* TODO: add static flag */ {}) qaJobComponent: ExecutionComponent;
}
export class fakeConfigService {
static get config() {
return {
url: "http://localhost:4200/VlassMngr",
rootDataDirectory: '/lustre/aoc/cluster/pipeline/vlass_test/spool',
weblogbaseurl: 'http://webtest.aoc.nrao.edu/'
};
};
}
describe('ExecutionComponent', () => {
let component: HostComponent;
let fixture: ComponentFixture<HostComponent>;
let jobServiceSpy: { getJob: jasmine.Spy, getJobSpec: jasmine.Spy, updateJobStatus: jasmine.Spy, updateNotes: jasmine.Spy };
let productServiceSpy: { updateProductStatus: jasmine.Spy };
beforeEach(async(() => {
jobServiceSpy = jasmine.createSpyObj('JobsService', ['getJob', 'getJobSpec', 'updateJobStatus', 'updateNotes']);
productServiceSpy = jasmine.createSpyObj('ProductsService', ['updateProductStatus']);
TestBed.configureTestingModule({
declarations: [HostComponent, ExecutionComponent, ContentEditableDirective],
providers: [
{provide: JobsService, useValue: jobServiceSpy},
{provide: ProductsService, useValue: productServiceSpy},
{provide: ConfigurationService, useValue: fakeConfigService}
],
imports: [ReactiveFormsModule, BrowserAnimationsModule]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HostComponent);
component = fixture.componentInstance;
jobServiceSpy = TestBed.get(JobsService);
productServiceSpy = TestBed.get(ProductsService);
});
it('should create', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});
it('should set the status form control to the job status on init', () => {
component.qaJobComponent.detailsExposed = true;
fixture.detectChanges(); //ngOnInit
let statusEl: HTMLSelectElement = fixture.debugElement.query(By.css('select.status')).nativeElement;
expect(statusEl.value).toEqual(component.job.job_status, 'job status control set from job')
});
it('should set detailsExposed to true, get the job details from the service and update the noteForm controls', fakeAsync(() => {
jobServiceSpy.getJob.and.returnValue(of({
analyst: null,
archivalJob: null,
archiveStatus: "UNARCHIVED",
end: 1556444603753,
endDate: "04/28/2019, 02:43:23 AM",
id: 123,
jobSpecId: 321,
jsonResults: null,
name: "JobExecution",
notes: "These are notes",
queueName: "quicklook",
sdmId: "JobExectuionSDMid",
start: 1556151603773,
startDate: "04/24/2019, 05:20:03 PM",
status: "QA_ACCEPTED",
tasks: []
} as JobExecution));
expect(component.qaJobComponent.detailsExposed).toBeFalsy('detailsExposed starts false');
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.showDetails();
expect(jobServiceSpy.getJob).toHaveBeenCalledTimes(1);
fixture.detectChanges();
tick();
expect(component.qaJobComponent.detailsExposed).toBeTruthy('detailsExposed set to true');
expect(component.qaJobComponent.noteFormGroup.get('notes').value).toEqual('These are notes', 'notes set from service value');
expect(component.qaJobComponent.noteFormGroup.get('id').value).toEqual(123, 'id set from service value');
}));
it('should set detailsExposed to false when hideDetails() is called', () => {
component.qaJobComponent.detailsExposed = true;
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.hideDetails();
expect(component.qaJobComponent.detailsExposed).toBeFalsy('set detailsExposed to false');
});
it('getJobStatusClass() should return the right class based on job_spec status', () => {
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.job.jobspec_status = 'ERROR';
expect(component.qaJobComponent.getJobStatusClass()).toEqual('badge-danger', 'badge-danger returned for ERROR');
component.qaJobComponent.job.jobspec_status = 'QA_REJECTED';
expect(component.qaJobComponent.getJobStatusClass()).toEqual('badge-warning', 'badge-warning returned for QA_REJECTED');
component.qaJobComponent.job.jobspec_status = 'PROCESSING';
expect(component.qaJobComponent.getJobStatusClass()).toEqual('badge-primary', 'badge-primary returned for PROCESSING');
component.qaJobComponent.job.jobspec_status = 'QA_ACCEPTED';
expect(component.qaJobComponent.getJobStatusClass()).toEqual('badge-info', 'badge-info returned for others');
});
it('getTaskStatusBgClass() should return the right class based on passed in status', () => {
expect(component.qaJobComponent.getTaskStatusBgClass('ERROR')).toEqual('bg-danger', 'bg-danger returned for ERROR');
expect(component.qaJobComponent.getTaskStatusBgClass('SUCCESS')).toEqual('bg-success', 'bg-success returned for SUCCESS');
expect(component.qaJobComponent.getTaskStatusBgClass('OTHER')).toEqual('bg-info', 'bg-info returned for OTHER');
});
it('getTaskStatusBadgeClass() should return the right class based on passed in status', () => {
expect(component.qaJobComponent.getTaskStatusBadgeClass('ERROR')).toEqual('badge-danger', 'badge-danger returned for ERROR');
expect(component.qaJobComponent.getTaskStatusBadgeClass('SUCCESS')).toEqual('badge-success', 'badge-success returned for SUCCESS');
expect(component.qaJobComponent.getTaskStatusBadgeClass('OTHER')).toEqual('badge-info', 'badge-info returned for OTHER');
});
it('canAcceptArchive() shoud return correct boolean based on passed in params', () => {
expect(component.qaJobComponent.canAcceptArchive('QA_READY', 'ARCHIVED')).toBeTruthy('QA_READY returns true');
expect(component.qaJobComponent.canAcceptArchive('QA_MANUAL', 'ARCHIVED')).toBeTruthy('QA_MANUAL returns true');
expect(component.qaJobComponent.canAcceptArchive('QA_ON_HOLD', 'ARCHIVE_ERROR')).toBeTruthy('ARCHIVE_ERROR returns true');
expect(component.qaJobComponent.canAcceptArchive('QA_ON_HOLD', 'ARCHIVED')).toBeFalsy('other options return flase');
});
it('getConfigUrl() should return the url from the config service', () => {
fixture.detectChanges(); //ngOnInit
expect(component.qaJobComponent.getConfigUrl()).toEqual('http://localhost:4200/VlassMngr', 'returned url from config service');
});
it('getConfigRootDataDirectory() should return the url from the config service', () => {
fixture.detectChanges(); //ngOnInit
expect(component.qaJobComponent.getConfigRootDataDirectory()).toEqual('/lustre/aoc/cluster/pipeline/vlass_test/spool', 'returned url from config service');
});
it('getConfigWebLogBaseUrl() should return the url from the config service', () => {
fixture.detectChanges(); //ngOnInit
expect(component.qaJobComponent.getConfigWebLogBaseUrl()).toEqual('http://webtest.aoc.nrao.edu/', 'returned url from config service');
});
it('updateStatus() should call product service if the status has changed', fakeAsync(() => {
productServiceSpy.updateProductStatus.and.returnValue(of('PROCESSING'));
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.updateStatus();
expect(productServiceSpy.updateProductStatus).toHaveBeenCalledTimes(0);
component.qaJobComponent.formGroup.get('status').setValue('PROCESSING');
component.qaJobComponent.updateStatus();
tick();
expect(productServiceSpy.updateProductStatus).toHaveBeenCalledTimes(1);
expect(component.qaJobComponent.job.jobspec_status).toEqual('PROCESSING', 'Updated jobspec_status to service return value');
}));
it('updateNotes() should call the job service and hide and call hideDetails()', fakeAsync(() => {
jobServiceSpy.updateNotes.and.returnValue(of(''));
let hideDetailsSpy = spyOn(component.qaJobComponent, "hideDetails");
component.qaJobComponent.detailsExposed = true;
component.qaJobComponent.noteFormGroup.get('id').setValue(123);
component.qaJobComponent.noteFormGroup.get('notes').setValue('These are notes');
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.updateNotes();
expect(jobServiceSpy.updateNotes).toHaveBeenCalledWith(123, 'These are notes');
tick();
expect(hideDetailsSpy.calls.count()).toEqual(1, 'called hideDetails');
}));
it('acceptQa() should call performQa() with id and accept', () => {
let performQaSpy = spyOn(component.qaJobComponent, 'performQa');
component.qaJobComponent.acceptQa(123);
expect(performQaSpy).toHaveBeenCalledWith(123, 'accept');
});
it('rejectQa() should call performQa() with id and reject', () => {
spyOn(window, 'confirm').and.returnValue(true);
let performQaSpy = spyOn(component.qaJobComponent, 'performQa');
component.qaJobComponent.rejectQa(123);
expect(performQaSpy).toHaveBeenCalledWith(123, 'reject');
});
it('performQa() should call the job service and hideDetails()', fakeAsync(() => {
jobServiceSpy.updateJobStatus.and.returnValue(of(''));
let hideDetailsSpy = spyOn(component.qaJobComponent, "hideDetails");
fixture.detectChanges(); //ngOnInit
component.qaJobComponent.performQa(123, 'accept');
expect(jobServiceSpy.updateJobStatus).toHaveBeenCalledTimes(0);
component.qaJobComponent.job.job_status = 'QA_READY';
component.qaJobComponent.performQa(123, 'accept');
expect(jobServiceSpy.updateJobStatus).toHaveBeenCalledWith(123, 'QA_ACCEPTED', 'calibration');
tick();
expect(hideDetailsSpy).toHaveBeenCalledTimes(1);
}));
});