2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
22 import { ComponentFixture, TestBed } from "@angular/core/testing";
23 import { HarnessLoader } from "@angular/cdk/testing";
24 import { MatButtonModule } from '@angular/material/button';
25 import { MatButtonHarness } from '@angular/material/button/testing';
26 import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
27 import { MatSelectModule } from '@angular/material/select';
28 import { MatInputModule } from '@angular/material/input';
29 import { ReactiveFormsModule } from "@angular/forms";
30 import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed";
31 import { ToastrModule } from "ngx-toastr";
33 import { PolicyService } from "../../services/policy/policy.service";
34 import { ErrorDialogService } from "../../services/ui/error-dialog.service";
35 import { UiService } from "../../services/ui/ui.service";
36 import { NoTypePolicyInstanceDialogComponent } from "./no-type-policy-instance-dialog.component";
38 describe('NoTypePolicyInstanceDialogComponent', () => {
39 let component: NoTypePolicyInstanceDialogComponent;
40 let fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>;
41 let loader: HarnessLoader;
42 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
43 let errDialogServiceSpy: jasmine.SpyObj<ErrorDialogService>;
45 beforeEach(async () => {
46 policyServiceSpy = jasmine.createSpyObj('PolicyService', [ 'putPolicy' ]);
47 errDialogServiceSpy = jasmine.createSpyObj('ErrorDialogService', [ 'displayError' ]);
49 TestBed.configureTestingModule({
51 BrowserAnimationsModule,
57 ToastrModule.forRoot()
60 NoTypePolicyInstanceDialogComponent
63 { provide: MatDialogRef, useValue: component },
64 { provide: PolicyService, useValue: policyServiceSpy },
65 { provide: ErrorDialogService, useValue: errDialogServiceSpy },
66 { provide: MAT_DIALOG_DATA, useValue: true },
72 describe('content when creating policy', () => {
73 beforeEach(async () => {
74 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
77 it('should contain oran logo and create title and no instance info', async () => {
78 let ele = fixture.debugElement.nativeElement.querySelector('img');
79 expect(ele.src).toContain('assets/oran-logo.png');
81 ele = fixture.debugElement.nativeElement.querySelector('text');
82 expect(ele.childNodes[0].childNodes[0].textContent).toEqual('Create new policy instance of < No type >');
84 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
85 expect(ele).toBeFalsy();
88 it('should contain ric select', async () => {
89 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
90 expect(ele).toBeTruthy();
93 it('should contain json editor', async () => {
94 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
95 expect(ele).toBeTruthy();
98 it('should contain enabled Close button and disabled Submit button', async () => {
101 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#closeButton' }));
102 expect(await closeButton.isDisabled()).toBeFalsy();
103 expect(await closeButton.getText()).toEqual('Close');
105 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
106 // expect(await submitButton.isDisabled()).toBeTruthy();
107 expect(await submitButton.getText()).toEqual('Submit');
111 describe('content when editing policy', () => {
112 beforeEach(async () => {
115 instanceId: "instanceId",
116 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
120 TestBed.overrideProvider(MAT_DIALOG_DATA, {useValue: policyData }); // Should be provided with a policy
121 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
124 it('should contain oran logo and instance info', async () => {
125 let ele = fixture.debugElement.nativeElement.querySelector('img');
126 expect(ele.src).toContain('assets/oran-logo.png');
128 ele = fixture.debugElement.nativeElement.querySelector('text');
129 expect(ele.childNodes[0].childNodes[0]).toBeFalsy(); // No create title
131 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
132 expect(ele).toBeTruthy();
133 expect(ele.innerText).toEqual('[ric1] Instance ID: instanceId');
136 it('should not contain ric select', async () => {
137 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
138 expect(ele).toBeFalsy();
141 it('should contain json editor', async () => {
142 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
143 expect(ele).toBeTruthy();
146 it('should contain enabled Close and Submit buttons', async () => {
147 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#closeButton'}));
148 expect(await closeButton.isDisabled()).toBeFalsy();
149 expect(await closeButton.getText()).toEqual('Close');
151 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
152 expect(await submitButton.isDisabled()).toBeFalsy();
153 expect(await submitButton.getText()).toEqual('Submit');
159 function compileAndGetComponents(fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>, component: NoTypePolicyInstanceDialogComponent, loader: HarnessLoader) {
160 TestBed.compileComponents();
162 fixture = TestBed.createComponent(NoTypePolicyInstanceDialogComponent);
163 component = fixture.componentInstance;
164 fixture.detectChanges();
165 loader = TestbedHarnessEnvironment.loader(fixture);
166 return { fixture, component, loader };