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
9 * # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
20 import { RadioButtonModule } from 'primeng/radiobutton';
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';
31 describe('CompSpecValidationComponent', () => {
32 let component: CompSpecValidationComponent;
33 let fixture: ComponentFixture<CompSpecValidationComponent>;
35 beforeEach(async(() => {
36 TestBed.configureTestingModule({
37 declarations: [ CompSpecValidationComponent ],
44 HttpClientTestingModule,
45 Ng4LoadingSpinnerModule
49 { provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
57 fixture = TestBed.createComponent(CompSpecValidationComponent);
58 component = fixture.componentInstance;
59 fixture.detectChanges();
62 it('should create', () => {
63 expect(component).toBeTruthy();
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);
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);
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);
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);
94 it(`should set validation error message`, async(() => {
95 const fixture = TestBed.createComponent(CompSpecValidationComponent);
96 const app = fixture.debugElement.componentInstance;
100 app.setSpecValidationMessage(mockSuccess)
101 fixture.detectChanges();
102 expect(app.validCompSpec).toEqual(true)
105 it(`should set validation error message`, async(() => {
106 const fixture = TestBed.createComponent(CompSpecValidationComponent);
107 const app = fixture.debugElement.componentInstance;
119 app.setSpecValidationMessage(mockError)
120 fixture.detectChanges();
121 expect(app.validCompSpec).toEqual(false)
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!')