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";
37 import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
39 describe('NoTypePolicyInstanceDialogComponent', () => {
40 let component: NoTypePolicyInstanceDialogComponent;
41 let fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>;
42 let loader: HarnessLoader;
43 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
44 let errDialogServiceSpy: jasmine.SpyObj<ErrorDialogService>;
46 beforeEach(async () => {
47 policyServiceSpy = jasmine.createSpyObj('PolicyService', [ 'putPolicy' ]);
48 errDialogServiceSpy = jasmine.createSpyObj('ErrorDialogService', [ 'displayError' ]);
50 TestBed.configureTestingModule({
52 BrowserAnimationsModule,
58 ToastrModule.forRoot()
61 CUSTOM_ELEMENTS_SCHEMA
64 NoTypePolicyInstanceDialogComponent
67 { provide: MatDialogRef, useValue: component },
68 { provide: PolicyService, useValue: policyServiceSpy },
69 { provide: ErrorDialogService, useValue: errDialogServiceSpy },
70 { provide: MAT_DIALOG_DATA, useValue: true },
76 describe('content when creating policy', () => {
77 beforeEach(async () => {
78 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
81 it('should contain oran logo and create title and no instance info', async () => {
82 let ele = fixture.debugElement.nativeElement.querySelector('img');
83 expect(ele.src).toContain('assets/oran-logo.png');
85 ele = fixture.debugElement.nativeElement.querySelector('text');
86 expect(ele.childNodes[0].childNodes[0].textContent).toEqual('Create new policy instance of < No type >');
88 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
89 expect(ele).toBeFalsy();
92 it('should contain ric select', async () => {
93 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
94 expect(ele).toBeTruthy();
97 it('should contain json editor', async () => {
98 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
99 expect(ele).toBeTruthy();
102 it('should contain enabled Close button and disabled Submit button', async () => {
103 component.ngOnInit();
105 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#closeButton' }));
106 expect(await closeButton.isDisabled()).toBeFalsy();
107 expect(await closeButton.getText()).toEqual('Close');
109 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
110 // expect(await submitButton.isDisabled()).toBeTruthy();
111 expect(await submitButton.getText()).toEqual('Submit');
115 describe('content when editing policy', () => {
116 beforeEach(async () => {
119 instanceId: "instanceId",
120 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
124 TestBed.overrideProvider(MAT_DIALOG_DATA, {useValue: policyData }); // Should be provided with a policy
125 ({ fixture, component, loader } = compileAndGetComponents(fixture, component, loader));
128 it('should contain oran logo and instance info', async () => {
129 let ele = fixture.debugElement.nativeElement.querySelector('img');
130 expect(ele.src).toContain('assets/oran-logo.png');
132 ele = fixture.debugElement.nativeElement.querySelector('text');
133 expect(ele.childNodes[0].childNodes[0]).toBeFalsy(); // No create title
135 ele = fixture.debugElement.nativeElement.querySelector('#instanceInfo');
136 expect(ele).toBeTruthy();
137 expect(ele.innerText).toEqual('[ric1] Instance ID: instanceId');
140 it('should not contain ric select', async () => {
141 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-ric-selector');
142 expect(ele).toBeFalsy();
145 it('should contain json editor', async () => {
146 const ele = fixture.debugElement.nativeElement.querySelector('nrcp-no-type-policy-editor');
147 expect(ele).toBeTruthy();
150 it('should contain enabled Close and Submit buttons', async () => {
151 let closeButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#closeButton'}));
152 expect(await closeButton.isDisabled()).toBeFalsy();
153 expect(await closeButton.getText()).toEqual('Close');
155 let submitButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({selector: '#submitButton'}));
156 expect(await submitButton.isDisabled()).toBeFalsy();
157 expect(await submitButton.getText()).toEqual('Submit');
163 function compileAndGetComponents(fixture: ComponentFixture<NoTypePolicyInstanceDialogComponent>, component: NoTypePolicyInstanceDialogComponent, loader: HarnessLoader) {
164 TestBed.compileComponents();
166 fixture = TestBed.createComponent(NoTypePolicyInstanceDialogComponent);
167 component = fixture.componentInstance;
168 fixture.detectChanges();
169 loader = TestbedHarnessEnvironment.loader(fixture);
170 return { fixture, component, loader };