/
deployment-properties.component.spec.ts
114 lines (100 loc) · 4.5 KB
/
deployment-properties.component.spec.ts
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
import { TestBed, async, ComponentFixture, tick, fakeAsync } from '@angular/core/testing';
import { DeploymentPropertiesComponent } from './deployment-properties.component';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { StreamDefinition } from '../../model/stream-definition';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { SharedAboutService } from '../../../shared/services/shared-about.service';
import { MocksSharedAboutService } from '../../../tests/mocks/shared-about';
import { MockStreamsService } from '../../../tests/mocks/streams';
import { StreamsService } from '../../streams.service';
/**
* Test {@link DeploymentPropertiesComponent}.
*
* @author Damien Vitrac
*/
describe('DeploymentPropertiesComponent', () => {
let component: DeploymentPropertiesComponent;
let fixture: ComponentFixture<DeploymentPropertiesComponent>;
const sharedAboutService = new MocksSharedAboutService();
const streamsService = new MockStreamsService();
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DeploymentPropertiesComponent
],
imports: [
FormsModule,
ReactiveFormsModule,
],
providers: [
{ provide: StreamsService, useValue: streamsService },
{ provide: SharedAboutService, useValue: sharedAboutService }
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DeploymentPropertiesComponent);
component = fixture.componentInstance;
});
it('should be created', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
fixture.detectChanges();
expect(component).toBeTruthy();
});
it('should populate properties input', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
component.stream.deploymentProperties = { a: 'a', b: 'b' };
fixture.detectChanges();
expect(component.deploymentProperties.value).toBe('a=a\nb=b');
});
it('should not populate properties input (empty)', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
fixture.detectChanges();
expect(component.deploymentProperties.value).toBe('');
});
it('should display the platform input (skipper integration)', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
component.stream.deploymentProperties = {};
fixture.detectChanges();
const de: DebugElement = fixture.debugElement.query(By.css('#groupPlatform'));
const el: HTMLElement = fixture.debugElement.query(By.css('#deploymentPlatform')).nativeElement;
expect(de == null).not.toBeTruthy();
expect(el.innerHTML.indexOf('foo (bar)') !== -1).toBe(true);
expect(el.innerHTML.indexOf('default (local)') !== -1).toBe(true);
});
it('should not populate properties input (invalid data)', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
component.stream.deploymentProperties = 'aa';
fixture.detectChanges();
expect(component.deploymentProperties.value).toBe('');
});
it('should emit cancel event on cancel action', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
fixture.detectChanges();
const cancelEvent = spyOn(component.cancel, 'emit');
component.cancelDeployment();
expect(cancelEvent).toHaveBeenCalled();
});
it('should update the stream definition to deploy and emit event Submit on submit', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
fixture.detectChanges();
const submitEvent = spyOn(component.submit, 'emit');
component.deploymentProperties.setValue('a=a');
component.deployDefinition();
expect(component.stream.deploymentProperties.a).toBe('a');
expect(submitEvent).toHaveBeenCalled();
});
it('should update the stream definition to deploy with multiple properties and emit event Submit on submit', () => {
component.stream = new StreamDefinition('foo2', 'time |log', 'undeployed');
fixture.detectChanges();
const submitEvent = spyOn(component.submit, 'emit');
component.deploymentProperties.setValue('a=a\nb=c=d\ne=f');
component.deployDefinition();
expect(component.stream.deploymentProperties.a).toBe('a');
expect(component.stream.deploymentProperties.b).toBe('c=d');
expect(component.stream.deploymentProperties.e).toBe('f');
expect(submitEvent).toHaveBeenCalled();
});
});