Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / comp-spec-validation / comp-spec-validation.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 { async, ComponentFixture, TestBed } from '@angular/core/testing';
20 import { RadioButtonModule } from 'primeng/radiobutton';
21
22 import { CompSpecValidationComponent } from './comp-spec-validation.component';
23 import { FormsModule } from '@angular/forms';
24 import { MatCardModule, MatTooltipModule } from '@angular/material';
25 import { ScrollPanelModule } from 'primeng/scrollpanel';
26 import { HttpClientTestingModule } from '@angular/common/http/testing';
27 import { MessageService } from 'primeng/api';
28 import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt';
29 import { Ng4LoadingSpinnerModule } from 'ng4-loading-spinner';
30
31 describe('CompSpecValidationComponent', () => {
32   let component: CompSpecValidationComponent;
33   let fixture: ComponentFixture<CompSpecValidationComponent>;
34
35   beforeEach(async(() => {
36     TestBed.configureTestingModule({
37       declarations: [ CompSpecValidationComponent ],
38       imports: [ 
39         RadioButtonModule, 
40         FormsModule, 
41         MatCardModule,
42         MatTooltipModule,
43         ScrollPanelModule,
44         HttpClientTestingModule,
45         Ng4LoadingSpinnerModule
46       ],
47       providers: [
48         MessageService,
49         { provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
50         JwtHelperService
51       ]
52     })
53     .compileComponents();
54   }));
55
56   beforeEach(() => {
57     fixture = TestBed.createComponent(CompSpecValidationComponent);
58     component = fixture.componentInstance;
59     fixture.detectChanges();
60   });
61
62   it('should create', () => {
63     expect(component).toBeTruthy();
64   });
65
66   it(`should have as shouldValidate 'false'`, () => {
67     const fixture = TestBed.createComponent(CompSpecValidationComponent);
68     const app = fixture.debugElement.componentInstance;
69     expect(app.shouldValidate).toEqual(false);
70   });
71
72   it(`should change shouldValidate to 'true'`, async(() => {
73     const fixture = TestBed.createComponent(CompSpecValidationComponent);
74     const app = fixture.debugElement.componentInstance;
75     app.validateRadioButton()
76     fixture.detectChanges();
77     expect(app.shouldValidate).toEqual(true);
78   }));
79
80   it(`should have as shouldDownload 'false'`, () => {
81     const fixture = TestBed.createComponent(CompSpecValidationComponent);
82     const app = fixture.debugElement.componentInstance;
83     expect(app.shouldDownload).toEqual(false);
84   });  
85
86   it(`should change shouldDownload to 'true'`, async(() => {
87     const fixture = TestBed.createComponent(CompSpecValidationComponent);
88     const app = fixture.debugElement.componentInstance;
89     app.downloadRadioButton()
90     fixture.detectChanges();
91     expect(app.shouldDownload).toEqual(true);
92   }));
93
94   it(`should set validation error message`, async(() => {
95     const fixture = TestBed.createComponent(CompSpecValidationComponent);
96     const app = fixture.debugElement.componentInstance;
97     let mockSuccess = {
98       status: 200
99     }
100     app.setSpecValidationMessage(mockSuccess)
101     fixture.detectChanges();
102     expect(app.validCompSpec).toEqual(true)
103   }));
104
105   it(`should set validation error message`, async(() => {
106     const fixture = TestBed.createComponent(CompSpecValidationComponent);
107     const app = fixture.debugElement.componentInstance;
108
109     let mockError = {
110       status: 400,
111       error: {
112         summary: 'Test',
113         errors: [
114           'error1',
115           'error2'
116         ]
117       }
118     }
119     app.setSpecValidationMessage(mockError)
120     fixture.detectChanges();
121     expect(app.validCompSpec).toEqual(false)
122   }));
123
124   it(`should invalidate JSON structure`, async(() => {
125     const fixture = TestBed.createComponent(CompSpecValidationComponent);
126     const app = fixture.debugElement.componentInstance;
127     let mockErrorJson = "test: 'test}"
128     app.compSpecContent = mockErrorJson
129     expect(() => app.validateJsonStructure()).toThrowError('JSON Structure error, quit!')  
130   }));
131
132 });