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
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {SettingsComponent} from './settings.component';
import {SettingsService} from "../services/settings.service";
import {RouterTestingModule} from "@angular/router/testing";
import {Configuration} from "../env/model/configuration";
import {ConfigurationService} from "../env/configuration.service";
export class FakeConfigurationService {
get config() {
return {
dryrun: "false",
rootDataDirectory: "/lustre/aoc/cluster/pipeline/vlass_test/spool",
url: "http://localhost:4200/VlassMngr",
weblogbaseurl: "http://webtest.aoc.nrao.edu/",
projectcode: "VLASS1.1",
wsurl: "ws://localhost:8081/VlassMngr/changes",
currentepoch: "1"
} as Configuration;
};
}
describe('SettingsComponent', () => {
let component: SettingsComponent;
let fixture: ComponentFixture<SettingsComponent>;
let settingServiceSpy: {
getSettings: jasmine.Spy,
getQueueSettings: jasmine.Spy,
getWorkflowSettings: jasmine.Spy,
setSettings: jasmine.Spy,
deleteFile: jasmine.Spy
}; // we'll use a spy in place of the real service
let fakeConfigService: FakeConfigurationService;
beforeEach(async(() => {
// create the spy to inject as a substitute for the real TileService
settingServiceSpy = jasmine.createSpyObj('SettingService', ['getSettings', 'getQueueSettings', 'getWorkflowSettings', 'setSettings', 'deleteFile']);
// set up the test env with our mocks and spies
TestBed.configureTestingModule({
declarations: [SettingsComponent],
imports: [RouterTestingModule],
providers: [
{provide: SettingsService, useValue: settingServiceSpy},
{provide: ConfigurationService, useClass: FakeConfigurationService}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SettingsComponent);
component = fixture.componentInstance;
settingServiceSpy = TestBed.get(SettingsService); // we want to get the 'real' instance from our env
fakeConfigService = TestBed.get(ConfigurationService);
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should get settings and config url on init', () => {
expect(component.configUrl).toBeUndefined('configUrl starts empty');
fixture.detectChanges(); //ngOnInit
expect(settingServiceSpy.getSettings).toHaveBeenCalledTimes(1);
expect(settingServiceSpy.getQueueSettings).toHaveBeenCalledTimes(1);
expect(settingServiceSpy.getWorkflowSettings).toHaveBeenCalledTimes(1);
expect(component.configUrl).toEqual('http://localhost:4200/VlassMngr', 'configUrl updated from service');
});
it('saveSettings() should call service', () => {
component.saveSettings();
expect(settingServiceSpy.setSettings).toHaveBeenCalledTimes(1);
});
it('deleteFile() should call service', () => {
component.deleteFile('calibration', 'filename.xml');
expect(settingServiceSpy.deleteFile).toHaveBeenCalledWith('calibration', 'filename.xml');
expect(settingServiceSpy.deleteFile).toHaveBeenCalledTimes(1);
});
});