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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture } from '@angular/core/testing';
import { NgxsModule, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Mock } from 'ts-mockery';
import { ConfigureFn, configureTests } from '../../../../../jest/test-config.helper';
import { Service } from '../../../../models/components/service';
import { Resource } from '../../../../models/components/resource';
import { GroupInstance } from '../../../../models/graph/zones/group-instance';
import { PolicyInstance } from '../../../../models/graph/zones/policy-instance';
import { ArtifactGroupType } from '../../../../utils/constants';
import { WorkspaceState } from '../../../store/states/workspace.state';
import { CompositionPanelComponent } from './composition-panel.component';
import { ArtifactsTabComponent } from './panel-tabs/artifacts-tab/artifacts-tab.component';
import { GroupMembersTabComponent } from './panel-tabs/group-members-tab/group-members-tab.component';
import { GroupOrPolicyPropertiesTab } from './panel-tabs/group-or-policy-properties-tab/group-or-policy-properties-tab.component';
import { InfoTabComponent } from './panel-tabs/info-tab/info-tab.component';
import { PolicyTargetsTabComponent } from './panel-tabs/policy-targets-tab/policy-targets-tab.component';
import { PropertiesTabComponent } from './panel-tabs/properties-tab/properties-tab.component';
import { ReqAndCapabilitiesTabComponent } from './panel-tabs/req-capabilities-tab/req-capabilities-tab.component';
import {SubstitutionFilterTabComponent} from "./panel-tabs/substitution-filter-tab/substitution-filter-tab.component";
import {InterfaceOperationsComponent} from "../interface-operatons/interface-operations.component";
describe('composition-panel component', () => {
let fixture: ComponentFixture<CompositionPanelComponent>;
let store: Store;
const tabs = {
infoTab : {titleIcon: 'info-circle', component: InfoTabComponent, input: {}, isActive: true, tooltipText: 'Information'},
policyProperties: {
titleIcon: 'settings-o', component: GroupOrPolicyPropertiesTab, input: {type: 'policy'}, isActive: false, tooltipText: 'Properties'
},
policyTargets: {titleIcon: 'inputs-o', component: PolicyTargetsTabComponent, input: {}, isActive: false, tooltipText: 'Targets'},
groupMembers: {titleIcon: 'inputs-o', component: GroupMembersTabComponent, input: {}, isActive: false, tooltipText: 'Members'},
groupProperties: {
titleIcon: 'settings-o', component: GroupOrPolicyPropertiesTab, input: {type: 'group'}, isActive: false, tooltipText: 'Properties'
},
deploymentArtifacts: {
titleIcon: 'deployment-artifacts-o', component: ArtifactsTabComponent,
input: { type: ArtifactGroupType.DEPLOYMENT}, isActive: false, tooltipText: 'Deployment Artifacts'
},
apiArtifacts: {
titleIcon: 'api-o', component: ArtifactsTabComponent,
input: { type: ArtifactGroupType.SERVICE_API}, isActive: false, tooltipText: 'API Artifacts'
},
infoArtifacts: {
titleIcon: 'info-square-o', component: ArtifactsTabComponent,
input: { type: ArtifactGroupType.INFORMATION}, isActive: false, tooltipText: 'Information Artifacts'
},
properties: {
titleIcon: 'settings-o', component: PropertiesTabComponent,
input: {title: 'Properties and Attributes'}, isActive: false, tooltipText: 'Properties'
},
reqAndCapabilities : {
titleIcon: 'req-capabilities-o', component: ReqAndCapabilitiesTabComponent, input: {},
isActive: false, tooltipText: 'Requirements and Capabilities'
},
substitutionFilter: {
titleIcon: 'composition-o', component: SubstitutionFilterTabComponent, input: {title: 'SUBSTITUTION FILTER'},
isActive: false, tooltipText: 'Substitution Filter'
},
inputs: {titleIcon: 'inputs-o', component: PropertiesTabComponent, input: {title: 'Inputs'}, isActive: false, tooltipText: 'Inputs'},
settings: {titleIcon: 'settings-o', component: PropertiesTabComponent, input: {}, isActive: false, tooltipText: 'Settings'},
interfaceOperations: {
titleIcon: 'composition-o',
component: InterfaceOperationsComponent,
input: {title: 'Interface Operations'},
isActive: false,
tooltipText: 'Interface Operations'
}
};
beforeEach(
async(() => {
const configure: ConfigureFn = (testBed) => {
testBed.configureTestingModule({
declarations: [CompositionPanelComponent],
imports: [NgxsModule.forRoot([WorkspaceState])],
schemas: [NO_ERRORS_SCHEMA],
providers: [],
});
};
configureTests(configure).then((testBed) => {
fixture = testBed.createComponent(CompositionPanelComponent);
store = testBed.get(Store);
});
})
);
it('When PolicyInstance Selected => Expect (info, policyTargets and policyProperties) tabs appear', () => {
const testInstance = new PolicyInstance();
fixture.componentInstance.initTabs(testInstance);
expect (fixture.componentInstance.tabs.length).toBe(3);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.policyTargets);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.policyProperties);
});
it('should match current snapshot of composition-panel component.', () => {
expect(fixture).toMatchSnapshot();
});
it('When Topology Template is Service and no instance is selected Expect (info, deployment, inputs, info and api)', () => {
const selectedComponent: Service = new Service(null, null);
selectedComponent.isResource = jest.fn(() => false);
selectedComponent.isService = jest.fn(() => true );
fixture.componentInstance.store.select = jest.fn(() => Observable.of(selectedComponent));
// const pnfMock = Mock.of<Service>({ isResource : () => false });
fixture.componentInstance.topologyTemplate = selectedComponent;
// Call ngOnInit
fixture.componentInstance.ngOnInit();
// Expect that
expect (fixture.componentInstance.tabs.length).toBe(6);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.deploymentArtifacts);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.inputs);
expect (fixture.componentInstance.tabs[3]).toEqual(tabs.infoArtifacts);
expect (fixture.componentInstance.tabs[4]).toEqual(tabs.apiArtifacts);
expect (fixture.componentInstance.tabs[5]).toEqual(tabs.substitutionFilter);
});
it('When Topology Template is Resource and no instance is selected Expect (info, deployment, inputs, info and api)', () => {
const selectedComponent: Service = new Service(null, null);
selectedComponent.isResource = jest.fn(() => true);
selectedComponent.isService = jest.fn(() => false );
fixture.componentInstance.store.select = jest.fn(() => Observable.of(selectedComponent));
fixture.componentInstance.topologyTemplate = selectedComponent;
// Call ngOnInit
fixture.componentInstance.ngOnInit();
// Expect that
expect (fixture.componentInstance.tabs.length).toBe(5);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.deploymentArtifacts);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.properties);
expect (fixture.componentInstance.tabs[3]).toEqual(tabs.infoArtifacts);
expect (fixture.componentInstance.tabs[4]).toEqual(tabs.reqAndCapabilities);
});
it('When Topology Template is Service and proxyService instance is selected ' +
'Expect (info, deployment, inputs, info and api)', () => {
const selectedComponent: Service = new Service(null, null);
selectedComponent.isResource = jest.fn(() => false);
selectedComponent.isService = jest.fn(() => true );
fixture.componentInstance.store.select = jest.fn(() => Observable.of(selectedComponent));
fixture.componentInstance.selectedComponentIsServiceProxyInstance = jest.fn(() => true);
fixture.componentInstance.topologyTemplate = selectedComponent;
// Call ngOnInit
fixture.componentInstance.ngOnInit();
// Expect that
expect (fixture.componentInstance.tabs.length).toBe(7);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.properties);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.reqAndCapabilities);
expect (fixture.componentInstance.tabs[6]).toEqual(tabs.interfaceOperations);
});
it('When Topology Template is Resource and VL is selected ' +
'Expect (info, deployment, inputs, info and api)', () => {
const topologyTemplate: Resource = new Resource(null, null);
topologyTemplate.isResource = jest.fn(() => true);
topologyTemplate.isService = jest.fn(() => false );
const vlMock = Mock.of<Resource>({ resourceType : 'VL', isResource : () => true, isService : () => false });
fixture.componentInstance.store.select = jest.fn(() => Observable.of(vlMock));
fixture.componentInstance.topologyTemplate = topologyTemplate;
// Call ngOnInit
fixture.componentInstance.ngOnInit();
// Expect that
expect (fixture.componentInstance.tabs.length).toBe(6);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.deploymentArtifacts);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.properties);
expect (fixture.componentInstance.tabs[3]).toEqual(tabs.infoArtifacts);
expect (fixture.componentInstance.tabs[4]).toEqual(tabs.reqAndCapabilities);
});
it('When Topology Template is Service and VL is selected ' +
'Expect (info, deployment, inputs, info and api)', () => {
const topologyTemplate: Service = new Service(null, null);
topologyTemplate.isResource = jest.fn(() => true);
topologyTemplate.isService = jest.fn(() => false );
const vlMock = Mock.of<Resource>({ resourceType : 'VL', isResource : () => true, isService : () => false });
fixture.componentInstance.store.select = jest.fn(() => Observable.of(vlMock));
fixture.componentInstance.topologyTemplate = topologyTemplate;
// Call ngOnInit
fixture.componentInstance.ngOnInit();
// Expect that
expect (fixture.componentInstance.tabs.length).toBe(5);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.deploymentArtifacts);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.properties);
expect (fixture.componentInstance.tabs[3]).toEqual(tabs.infoArtifacts);
expect (fixture.componentInstance.tabs[4]).toEqual(tabs.reqAndCapabilities);
});
it('When GroupInstance Selected => Expect (info, groupMembers and groupProperties) tabs appear.', () => {
const testInstance = new GroupInstance();
fixture.componentInstance.initTabs(testInstance);
expect (fixture.componentInstance.tabs.length).toBe(3);
expect (fixture.componentInstance.tabs[0]).toEqual(tabs.infoTab);
expect (fixture.componentInstance.tabs[1]).toEqual(tabs.groupMembers);
expect (fixture.componentInstance.tabs[2]).toEqual(tabs.groupProperties);
});
});
|