Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / microservices / microservices.component.spec.ts
1 /* 
2  *  # ============LICENSE_START=======================================================
3  *  # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
4  *  # ================================================================================
5  *  # Licensed under the Apache License, Version 2.0 (the "License");
6  *  # you may not use this file except in compliance with the License.
7  *  # You may obtain a copy of the License at
8  *  #
9  *  #      http://www.apache.org/licenses/LICENSE-2.0
10  *  #
11  *  # Unless required by applicable law or agreed to in writing, software
12  *  # distributed under the License is distributed on an "AS IS" BASIS,
13  *  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  # See the License for the specific language governing permissions and
15  *  # limitations under the License.
16  *  # ============LICENSE_END=========================================================
17  */
18
19 import { HttpClientTestingModule } from '@angular/common/http/testing';
20 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
21 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
22 import { MatMenuModule } from '@angular/material';
23 import { RouterTestingModule } from '@angular/router/testing';
24 import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt';
25 import { Ng4LoadingSpinnerModule } from 'ng4-loading-spinner';
26 import { MessageService } from 'primeng/api';
27 import { ButtonModule } from 'primeng/button';
28 import { CalendarModule } from 'primeng/calendar';
29 import { DialogModule } from 'primeng/dialog';
30 import { DropdownModule } from 'primeng/dropdown';
31 import { ScrollPanelModule } from 'primeng/scrollpanel';
32 import { TableModule } from 'primeng/table';
33 import { ToastModule } from 'primeng/toast';
34 import { MsAddChangeComponent } from '../ms-add-change/ms-add-change.component';
35 import { MsInstanceAddComponent } from '../ms-instance-add/ms-instance-add.component';
36
37 import { MicroservicesComponent } from './microservices.component';
38
39 describe('MicroservicesComponent', () => {
40   let component: MicroservicesComponent;
41   let fixture: ComponentFixture<MicroservicesComponent>;
42
43   beforeEach(async(() => {
44     TestBed.configureTestingModule({
45       declarations: [
46         MicroservicesComponent,
47         MsAddChangeComponent,
48         MsInstanceAddComponent,
49       ],
50       imports: [
51         Ng4LoadingSpinnerModule,
52         TableModule,
53         MatMenuModule,
54         ScrollPanelModule,
55         ToastModule,
56         DialogModule,
57         DropdownModule,
58         FormsModule,
59         ReactiveFormsModule,
60         ButtonModule,
61         CalendarModule,
62         HttpClientTestingModule,
63         ToastModule,
64         RouterTestingModule
65       ],
66       providers: [
67         MessageService,
68         { provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
69         JwtHelperService
70       ]
71     })
72       .compileComponents();
73   }));
74
75   beforeEach(() => {
76     fixture = TestBed.createComponent(MicroservicesComponent);
77     component = fixture.componentInstance;
78     fixture.detectChanges();
79   });
80
81   it('should create', () => {
82     expect(component).toBeTruthy();
83   });
84
85   it(`should fill msInstances Object`, () => {
86     const fixture = TestBed.createComponent(MicroservicesComponent);
87     const app = fixture.debugElement.componentInstance;
88
89     let mockMicroservice = [{
90       id: 'testId1234',
91       name: 'test-MS',
92       tag: 'test-MS-tag',
93       serviceName: 'testServiceName',
94       type: 'testType',
95       location: 'TestLocation',
96       namespace: 'testNameSpace',
97       status: 'testStatus',
98       metadata: {
99         createdBy: 'test',
100         createdOn: '01-01-2020 12:00',
101         updatedBy: 'test',
102         updatedOn: '01-01-2020 12:00',
103         notes: 'test',
104         labels: ['test'],
105       },
106       msInstances: 'test'
107     }]
108
109     app.fillTable(mockMicroservice)
110
111     expect(app.loadTable).toEqual(true);
112     expect(app.msElements.length).toEqual(1);
113   });
114
115   it(`should set addOrChange to "Add"`, () => {
116     const fixture = TestBed.createComponent(MicroservicesComponent);
117     const app = fixture.debugElement.componentInstance;
118
119     let mockRowData = null
120     app.showAddChangeDialog(mockRowData)
121
122     expect(app.addOrChange).toEqual('Add');
123   });
124
125   it(`should set addOrChange to "Change"`, () => {
126     const fixture = TestBed.createComponent(MicroservicesComponent);
127     const app = fixture.debugElement.componentInstance;
128
129     let mockRowData = {field: 'test'}
130     app.showAddChangeDialog(mockRowData)
131
132     expect(app.addOrChange).toEqual('Change');
133   });
134 });