8205226f9e49c92cf32dac8b6c453502f444eac8
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / details / details.component.spec.ts
1 /**\r
2 ============LICENSE_START=======================================================\r
3  Copyright (C) 2018 Ericsson. All rights reserved.\r
4 ================================================================================\r
5 Licensed under the Apache License, Version 2.0 (the "License");\r
6 you may not use this file except in compliance with the License.\r
7 You may obtain a copy of the License at\r
8 \r
9     http://www.apache.org/licenses/LICENSE-2.0\r
10 \r
11 Unless required by applicable law or agreed to in writing, software\r
12 distributed under the License is distributed on an "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 See the License for the specific language governing permissions and\r
15  limitations under the License.\r
16 \r
17 SPDX-License-Identifier: Apache-2.0\r
18 ============LICENSE_END=========================================================\r
19 \r
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com\r
21 */\r
22 \r
23 import { async, ComponentFixture, TestBed } from '@angular/core/testing';\r
24 \r
25 import { DetailsComponent } from './details.component';\r
26 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';\r
27 import { RouterTestingModule } from '@angular/router/testing';\r
28 import { MatTableModule } from '@angular/material';\r
29 import { inject } from '@angular/core/testing';\r
30 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';\r
31 import { HttpClientModule } from '@angular/common/http';\r
32 import { HttpClient } from '@angular/common/http';\r
33 import { RouterModule } from '@angular/router';\r
34 import { APP_BASE_HREF } from '@angular/common';\r
35 import { ToastrNotificationService } from '../toastr-notification-service.service';\r
36 import { DataService } from '../data.service';\r
37 import { Observable, of } from 'rxjs';\r
38 import { ACTINST } from '../model/activityInstance.model';\r
39 import { PDI } from '../model/processDefinition.model';\r
40 import { PII } from '../model/processInstance.model';\r
41 import { VarInstance } from '../model/variableInstance.model';\r
42 \r
43 // Generate stub for toastr popup notifications\r
44 class StubbedToastrNotificationService extends ToastrNotificationService {\r
45   toastrSettings() {\r
46   }\r
47 }\r
48 \r
49 // Create SPY Object for Jasmine tests to mock DataService\r
50 let spyDataService: jasmine.SpyObj<DataService>;\r
51 \r
52 describe('DetailsComponent', () => {\r
53   beforeEach(async(() => {\r
54     spyDataService = jasmine.createSpyObj('DataService', ['getActivityInstance', 'getVariableInstance']);\r
55 \r
56     TestBed.configureTestingModule({\r
57       providers: [DetailsComponent, HttpClient, HttpTestingController,\r
58         { provide: APP_BASE_HREF, useValue: '/' },\r
59         { provide: ToastrNotificationService, useClass: StubbedToastrNotificationService },\r
60         { provide: DataService, useValue: spyDataService }],\r
61       imports: [RouterTestingModule, MatTableModule, HttpClientModule, RouterModule.forRoot([])],\r
62       schemas: [\r
63         CUSTOM_ELEMENTS_SCHEMA\r
64       ]\r
65     })\r
66       .compileComponents();\r
67   }));\r
68 \r
69   // Ensure creation of DetailsComponent component\r
70   it('component should be created', inject([DetailsComponent],\r
71     (detailsComponent: DetailsComponent) => {\r
72       expect(detailsComponent).toBeTruthy();\r
73     }));\r
74 \r
75 \r
76   // Mock an activityInstance and ensure array is populated\r
77   it('activityInstance should be defined if data service returns activities', inject([DetailsComponent],\r
78     (detailsComponent: DetailsComponent) => {\r
79       const activity: ACTINST = {\r
80         activityId: "",\r
81         processInstanceId: "",\r
82         calledProcessInstanceId: "",\r
83         activityName: "",\r
84         activityType: "",\r
85         durationInMillis: "1",\r
86         endTime: "",\r
87         startTime: ""\r
88       };\r
89       spyDataService.getActivityInstance.and.returnValue(of([activity]));\r
90       detailsComponent.getActInst("");\r
91       expect(detailsComponent.activityInstance.length).toEqual(1);\r
92     }));\r
93 \r
94 \r
95   // Create a processDefinition and ensure it is defined\r
96   it('processDefinition should be defined if PDI populated', inject([DetailsComponent],\r
97     (detailsComponent: DetailsComponent) => {\r
98       const activity: PDI = {\r
99         processDefinitionId: "1",\r
100         processDefinitionXml: ""\r
101       };\r
102       detailsComponent.getProcessDefinition("");\r
103       detailsComponent.processDefinition = activity;\r
104       expect(detailsComponent.processDefinition).toBeDefined();\r
105     }));\r
106 \r
107 \r
108   // Create a processInstance and ensure it is defined\r
109   it('processInstance should be defined if PII populated', inject([DetailsComponent],\r
110     (detailsComponent: DetailsComponent) => {\r
111       const testVals: PII = {\r
112         processInstancId: "1",\r
113         processDefinitionId: "1",\r
114         processDefinitionName: "test",\r
115         superProcessInstanceId: "1"\r
116       };\r
117       detailsComponent.getProcInstance("");\r
118       detailsComponent.processInstance = testVals;\r
119       expect(detailsComponent.processInstance).toBeDefined();\r
120     }));\r
121 \r
122 \r
123     // displayCamundaflow test\r
124     // TODO\r
125 \r
126     // Mock an variableInstance and ensure array is populated\r
127     it('variableInstance should be defined if data service returns activities', inject([DetailsComponent],\r
128       (detailsComponent: DetailsComponent) => {\r
129         const activity2: VarInstance = {\r
130           name: "a",\r
131           type: "a",\r
132           value: "1"\r
133         };\r
134         spyDataService.getVariableInstance.and.returnValue(of([activity2]));\r
135         detailsComponent.getVarInst("");\r
136         expect(detailsComponent.variableInstance.length).toEqual(1);\r
137       }));\r
138 });\r