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 { MatSelectHarness } from '@angular/material/select/testing';
29 import { MatInputModule } from '@angular/material/input';
30 import { MatInputHarness } from '@angular/material/input/testing';
31 import { of } from "rxjs/observable/of";
32 import { FormControl, ReactiveFormsModule } from "@angular/forms";
33 import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed";
34 import { ToastrModule } from "ngx-toastr";
36 import { PolicyService } from "../../services/policy/policy.service";
37 import { ErrorDialogService } from "../../services/ui/error-dialog.service";
38 import { UiService } from "../../services/ui/ui.service";
39 import { NoTypePolicyInstanceDialogComponent } from "./no-type-policy-instance-dialog.component";
40 import { RicSelectorComponent } from "../ric-selector/ric-selector.component";
41 import { NoTypePolicyEditorComponent } from "../no-type-policy-editor/no-type-policy-editor.component";
43 describe('NoTypePolicyInstanceDialogComponent', () => {
44 let component: NoTypePolicyInstanceDialogComponent;
45 let fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>;
46 let loader: HarnessLoader;
47 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
48 let errDialogServiceSpy: jasmine.SpyObj<ErrorDialogService>;
50 beforeEach(async () => {
51 policyServiceSpy = jasmine.createSpyObj('PolicyService', [ 'putPolicy' ]);
52 errDialogServiceSpy = jasmine.createSpyObj('ErrorDialogService', [ 'displayError' ]);
54 TestBed.configureTestingModule({
56 BrowserAnimationsModule,
62 ToastrModule.forRoot()
65 NoTypePolicyInstanceDialogComponent
68 { provide: MatDialogRef, useValue: component },
69 { provide: PolicyService, useValue: policyServiceSpy },
70 { provide: ErrorDialogService, useValue: errDialogServiceSpy },
71 { provide: MAT_DIALOG_DATA, useValue: true },
77 describe('content when creating policy', () => {
78 beforeEach(async () => {
79 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
82 it('should contain oran logo and create title and no instance info', async () => {
83 let ele = fixture.debugElement.nativeElement.querySelector('img');
84 expect(ele.src).toContain('assets/oran-logo.png');
86 ele = fixture.debugElement.nativeElement.querySelector('text');
87 expect(ele.childNodes[0].childNodes[0].textContent).toEqual('Create new policy instance of < No type >');
89 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
90 expect(ele).toBeFalsy();
93 it('should contain ric select', async () => {
94 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
95 expect(ele).toBeTruthy();
98 it('should contain json editor', async () => {
99 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
100 expect(ele).toBeTruthy();
103 it('should contain enabled Close button and disabled Submit button', async () => {
104 component.ngOnInit();
106 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#closeButton' }));
107 expect(await closeButton.isDisabled()).toBeFalsy();
108 expect(await closeButton.getText()).toEqual('Close');
110 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
111 // expect(await submitButton.isDisabled()).toBeTruthy();
112 expect(await submitButton.getText()).toEqual('Submit');
116 describe('content when editing policy', () => {
117 beforeEach(async () => {
120 instanceId: "instanceId",
121 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
125 TestBed.overrideProvider(MAT_DIALOG_DATA, {useValue: policyData }); // Should be provided with a policy
126 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
129 it('should contain oran logo and instance info', async () => {
130 let ele = fixture.debugElement.nativeElement.querySelector('img');
131 expect(ele.src).toContain('assets/oran-logo.png');
133 ele = fixture.debugElement.nativeElement.querySelector('text');
134 expect(ele.childNodes[0].childNodes[0]).toBeFalsy(); // No create title
136 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
137 expect(ele).toBeTruthy();
138 expect(ele.innerText).toEqual('[ric1] Instance ID: instanceId');
141 it('should not contain ric select', async () => {
142 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
143 expect(ele).toBeFalsy();
146 it('should contain json editor', async () => {
147 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
148 expect(ele).toBeTruthy();
151 it('should contain enabled Close and Submit buttons', async () => {
152 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#closeButton'}));
153 expect(await closeButton.isDisabled()).toBeFalsy();
154 expect(await closeButton.getText()).toEqual('Close');
156 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
157 expect(await submitButton.isDisabled()).toBeFalsy();
158 expect(await submitButton.getText()).toEqual('Submit');
164 function compileAndGetComponents(fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>, component: NoTypePolicyInstanceDialogComponent, loader: HarnessLoader) {
165 TestBed.compileComponents();
167 fixture = TestBed.createComponent(NoTypePolicyInstanceDialogComponent);
168 component = fixture.componentInstance;
169 fixture.detectChanges();
170 loader = TestbedHarnessEnvironment.loader(fixture);
171 return { fixture, component, loader };