Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / blueprints / blueprints.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, 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 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
34
35 import { BlueprintsComponent } from './blueprints.component';
36
37 describe('BlueprintsComponent', () => {
38   let component: BlueprintsComponent;
39   let fixture: ComponentFixture<BlueprintsComponent>;
40
41   beforeEach(async(() => {
42     TestBed.configureTestingModule({
43       declarations: [BlueprintsComponent],
44       imports: [
45         Ng4LoadingSpinnerModule,
46         TableModule,
47         MatMenuModule,
48         ScrollPanelModule,
49         ToastModule,
50         DialogModule,
51         DropdownModule,
52         FormsModule,
53         ReactiveFormsModule,
54         ButtonModule,
55         HttpClientTestingModule,
56         ToastModule,
57         RouterTestingModule,
58         MatTooltipModule,
59         BrowserAnimationsModule
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(BlueprintsComponent);
72     component = fixture.componentInstance;
73     fixture.detectChanges();
74   });
75
76   it('should create', () => {
77     expect(component).toBeTruthy();
78   });
79
80   it(`should set states`, async(() => {
81     const fixture = TestBed.createComponent(BlueprintsComponent);
82     const app = fixture.debugElement.componentInstance;
83     let mockStates = [
84       'state1', 
85       'state2'
86     ]
87     app.setMenuStates(mockStates)
88     fixture.detectChanges();
89     expect(app.states).toEqual([ ]);
90   }));
91
92   it(`should not enable action buttons`, async(() => {
93     const fixture = TestBed.createComponent(BlueprintsComponent);
94     const app = fixture.debugElement.componentInstance;
95     
96     app.selectedBPs = []
97     app.enableButtonCheck()
98     fixture.detectChanges();
99
100     expect(app.canDownload).toEqual(false);
101     expect(app.canUpdate).toEqual(false);
102     expect(app.canDelete).toEqual(false);
103   }));
104
105   it(`should enable download/update buttons but not delete`, async(() => {
106     const fixture = TestBed.createComponent(BlueprintsComponent);
107     const app = fixture.debugElement.componentInstance;
108
109     app.selectedBPs = [{status: 'TEST'}]
110     app.enableButtonCheck()
111     fixture.detectChanges();
112
113     expect(app.canDownload).toEqual(true);
114     expect(app.canUpdate).toEqual(true);
115     expect(app.canDelete).toEqual(false);
116   }));
117
118   it(`should enable download/update buttons but not delete`, async(() => {
119     const fixture = TestBed.createComponent(BlueprintsComponent);
120     const app = fixture.debugElement.componentInstance;
121
122     app.selectedBPs = [{ status: 'IN_DEV' }]
123     app.enableButtonCheck()
124     fixture.detectChanges();
125
126     expect(app.canDownload).toEqual(true);
127     expect(app.canUpdate).toEqual(true);
128     expect(app.canDelete).toEqual(true);
129   }));
130
131   it(`should enable download/update buttons but not delete`, async(() => {
132     const fixture = TestBed.createComponent(BlueprintsComponent);
133     const app = fixture.debugElement.componentInstance;
134
135     let mockBpToView = {
136       tag: 'test-tag',
137       type: 'k8s',
138       instanceRelease: '2008',
139       version: '1',
140       content: 'test'
141     }
142
143     app.viewBpContent(mockBpToView)
144     fixture.detectChanges();
145
146     expect(app.BpFileNameForDownload).toEqual('test-tag_k8s_2008_1');
147     expect(app.BpContentToView).toEqual('test');
148     expect(app.showBpContentDialog).toEqual(true);
149   }));
150   
151 });
152
153