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
9 http://www.apache.org/licenses/LICENSE-2.0
\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
17 SPDX-License-Identifier: Apache-2.0
\r
18 ============LICENSE_END=========================================================
\r
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com
\r
23 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
\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
43 // Generate stub for toastr popup notifications
\r
44 class StubbedToastrNotificationService extends ToastrNotificationService {
\r
49 // Create SPY Object for Jasmine tests to mock DataService
\r
50 let spyDataService: jasmine.SpyObj<DataService>;
\r
52 describe('DetailsComponent', () => {
\r
53 beforeEach(async(() => {
\r
54 spyDataService = jasmine.createSpyObj('DataService', ['getActivityInstance', 'getVariableInstance']);
\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
63 CUSTOM_ELEMENTS_SCHEMA
\r
66 .compileComponents();
\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
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
81 processInstanceId: "",
\r
82 calledProcessInstanceId: "",
\r
85 durationInMillis: "1",
\r
89 spyDataService.getActivityInstance.and.returnValue(of([activity]));
\r
90 detailsComponent.getActInst("");
\r
91 expect(detailsComponent.activityInstance.length).toEqual(1);
\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
102 detailsComponent.getProcessDefinition("");
\r
103 detailsComponent.processDefinition = activity;
\r
104 expect(detailsComponent.processDefinition).toBeDefined();
\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
117 detailsComponent.getProcInstance("");
\r
118 detailsComponent.processInstance = testVals;
\r
119 expect(detailsComponent.processInstance).toBeDefined();
\r
123 // displayCamundaflow test
\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
134 spyDataService.getVariableInstance.and.returnValue(of([activity2]));
\r
135 detailsComponent.getVarInst("");
\r
136 expect(detailsComponent.variableInstance.length).toEqual(1);
\r