This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
deployment-card-container.component.spec.ts
125 lines (115 loc) · 3.8 KB
/
deployment-card-container.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
115
116
117
118
119
120
121
122
123
124
125
import {
Component,
DebugElement,
DebugNode,
EventEmitter,
Input,
NO_ERRORS_SCHEMA,
Output,
} from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Contexts } from 'ngx-fabric8-wit';
import { BehaviorSubject, of } from 'rxjs';
import { createMock } from 'testing/mock';
import { initContext } from 'testing/test-context';
import { DeploymentsService } from '../services/deployments.service';
import { DeploymentCardContainerComponent } from './deployment-card-container.component';
@Component({
template: '<deployment-card-container></deployment-card-container>',
})
class HostComponent {}
@Component({
selector: 'deployment-card',
template: '',
})
class FakeDeploymentCardComponent {
@Input() spaceId: string;
@Input() applicationId: string;
@Input() environment: string;
@Input() collapsed: boolean;
@Output() collapsedChange: EventEmitter<boolean> = new EventEmitter<boolean>();
}
describe('DeploymentCardContainer', () => {
const environments: string[] = ['envId1', 'envId2'];
const testContext = initContext(
DeploymentCardContainerComponent,
HostComponent,
{
declarations: [FakeDeploymentCardComponent],
providers: [
{
provide: Contexts,
useValue: {
current: of({
path: 'mock-path',
user: {
attributes: {
username: 'mock-username',
},
},
}),
},
},
{
provide: DeploymentsService,
useFactory: (): jasmine.SpyObj<DeploymentsService> => {
const svc: jasmine.SpyObj<DeploymentsService> = createMock(DeploymentsService);
svc.hasDeployments.and.returnValue(new BehaviorSubject<boolean>(true));
return svc;
},
},
],
schemas: [NO_ERRORS_SCHEMA],
},
(component: DeploymentCardContainerComponent): void => {
component.spaceId = 'space';
component.environments = of(environments);
component.applications = ['app'];
},
);
describe('User has deployed applications', (): void => {
it('should create child components with proper inputs', (): void => {
const arrayOfComponents: DebugElement[] = testContext.fixture.debugElement.queryAll(
By.directive(FakeDeploymentCardComponent),
);
expect(arrayOfComponents.length).toEqual(environments.length);
environments.forEach(
(envData: string, index: number): void => {
const cardComponent: DebugNode['componentInstance'] =
arrayOfComponents[index].componentInstance;
expect(cardComponent.applicationId).toEqual('app');
expect(cardComponent.environment).toEqual(environments[index]);
},
);
});
it('should set the application title properly', (): void => {
const el: HTMLElement = testContext.fixture.debugElement.query(
By.css('#deploymentCardApplicationTitle'),
).nativeElement;
expect(el.textContent.trim()).toEqual('app');
});
});
describe('Empty State', (): void => {
beforeEach(
(): void => {
TestBed.get(DeploymentsService)
.hasDeployments()
.next(false);
testContext.detectChanges();
},
);
it('should display the empty state template', (): void => {
const el: HTMLElement = testContext.fixture.debugElement.query(
By.css('.deployments-empty-state'),
).nativeElement;
expect(el).toBeDefined();
});
it('should still display the application title properly', (): void => {
const el: HTMLElement = testContext.fixture.debugElement.query(
By.css('.not-deployed-application-title'),
).nativeElement;
expect(el.textContent.trim()).toEqual('app');
});
});
});