Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / comp-specs / comp-specs.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 { HttpClientModule } from '@angular/common/http';
20 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
21 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
22 import { MatMenuModule, MatTooltipModule } 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 { DialogModule } from 'primeng/dialog';
29 import { DropdownModule } from 'primeng/dropdown';
30 import { ScrollPanelModule } from 'primeng/scrollpanel';
31 import { TableModule } from 'primeng/table';
32 import { ToastModule } from 'primeng/toast';
33
34 import { CompSpecsComponent } from './comp-specs.component';
35
36 describe('CompSpecsComponent', () => {
37   let component: CompSpecsComponent;
38   let fixture: ComponentFixture<CompSpecsComponent>;
39
40   beforeEach(async(() => {
41     TestBed.configureTestingModule({
42       declarations: [
43         CompSpecsComponent
44       ],
45       imports: [
46         Ng4LoadingSpinnerModule,
47         TableModule,
48         MatMenuModule,
49         ScrollPanelModule,
50         ToastModule,
51         DialogModule,
52         DropdownModule,
53         FormsModule,
54         ReactiveFormsModule,
55         ButtonModule,
56         HttpClientModule,
57         ToastModule,
58         RouterTestingModule,
59         MatTooltipModule
60       ],
61       providers: [
62         MessageService,
63         { provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
64         JwtHelperService
65       ]
66     })
67       .compileComponents();
68   }));
69
70   beforeEach(() => {
71     fixture = TestBed.createComponent(CompSpecsComponent);
72     component = fixture.componentInstance;
73     fixture.detectChanges();
74   });
75
76   it('should create', () => {
77     expect(component).toBeTruthy();
78   });
79
80   it(`should fill csElements Object`, () => {
81     const fixture = TestBed.createComponent(CompSpecsComponent);
82     const app = fixture.debugElement.componentInstance;
83
84     let mockCsElement = [{
85       id: 'testId1234',
86       name: 'test-MS',
87       type: 'k8s',
88       specContent: '',
89       policyJson: 'test',
90       status: 'New',
91       msInstanceInfo: {
92         release: '2008',
93         name: 'test Ms',
94       },
95       metadata: {
96         createdBy: 'test',
97         createdOn: '01-01-2020 12:00',
98         updatedBy: 'test',
99         updatedOn: '01-01-2020 12:00',
100         notes: 'test',
101         labels: ['test'],
102       }
103     }]
104
105     app.fillTable(mockCsElement)
106
107     expect(app.loadTable).toEqual(true);
108     expect(app.csElements.length).toEqual(1);
109   });
110
111   it(`should set spec content to view`, () => {
112     const fixture = TestBed.createComponent(CompSpecsComponent);
113     const app = fixture.debugElement.componentInstance;
114     let mockData = {
115       specContent: 'test'
116     }
117     app.showViewCsDialog(mockData)
118     expect(app.showViewCs).toEqual(true);
119     expect(app.specContentToView).toEqual('test');    
120   });
121
122   it(`should set policy json content to view`, () => {
123     const fixture = TestBed.createComponent(CompSpecsComponent);
124     const app = fixture.debugElement.componentInstance;
125     let mockData = {
126       policyJson: 'test'
127     }
128     app.showViewPolicyDialog(mockData)
129     expect(app.showViewPolicy).toEqual(true);
130     expect(app.policyJsonToView).toEqual('test');
131   });  
132 });
133