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
import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {JobspecComponent} from './jobspec.component';
import {Component, ViewChild} from "@angular/core";
import {Job} from "../../model/job";
import {JobsService} from "../../services/jobs.service";
import {ConfigurationService} from "../../env/configuration.service";
import {of} from "rxjs";
@Component({
template: '<app-job [job]="job"></app-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"
};
@ViewChild(JobspecComponent, /* TODO: add static flag */ {}) jobComponent: JobspecComponent;
}
export class fakeConfigService {
static get config() {
return {url: "http://localhost:4200/VlassMngr"};
};
}
describe('JobComponent', () => {
let component: HostComponent;
let fixture: ComponentFixture<HostComponent>;
let jobServiceSpy: { getJobSpec: jasmine.Spy };
beforeEach(async(() => {
jobServiceSpy = jasmine.createSpyObj('JobsService', ['getJobSpec']);
TestBed.configureTestingModule({
declarations: [HostComponent, JobspecComponent],
providers: [
{provide: JobsService, useValue: jobServiceSpy},
{provide: ConfigurationService, useValue: fakeConfigService}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HostComponent);
component = fixture.componentInstance;
jobServiceSpy = TestBed.get(JobsService);
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('showDetails() should set detailsExposed to true and call job service for specs', fakeAsync(() => {
jobServiceSpy.getJobSpec.and.returnValue(of({}));
fixture.detectChanges(); // ngOnInit
expect(component.jobComponent.detailsExposed).toBeFalsy('detailsExposed starts false');
component.jobComponent.showDetails();
expect(component.jobComponent.detailsExposed).toBeTruthy('detailsExposed set to true');
expect(jobServiceSpy.getJobSpec).toHaveBeenCalledTimes(1);
}));
it('hideDetails() should set detailsExposed to false', () => {
component.jobComponent.detailsExposed = true;
component.jobComponent.hideDetails();
expect(component.jobComponent.detailsExposed).toBeFalsy('detailsExposed set to false');
});
it('getJobStatusClass() should return the right class by status', () => {
expect(component.jobComponent.getJobStatusClass('ERROR')).toEqual('badge-danger', 'badge-danger returned for ERROR');
expect(component.jobComponent.getJobStatusClass('QA_REJECTED')).toEqual('badge-warning', 'badge-warning returned for QA_REJECTED');
expect(component.jobComponent.getJobStatusClass('PROCESSING')).toEqual('badge-primary', 'badge-primary returned for PROCESSING');
expect(component.jobComponent.getJobStatusClass('QA_ACCEPTED')).toEqual('badge-info', 'badge-info returned for anything else');
});
it('getConfigUrl() should return the url from the config service', () => {
fixture.detectChanges(); //ngOnInit
expect(component.jobComponent.getConfigUrl()).toEqual('http://localhost:4200/VlassMngr', 'returned url from config service');
});
});