2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: 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 { HarnessLoader } from '@angular/cdk/testing';
22 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
23 import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
24 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
25 import { FormBuilder, FormGroup } from '@angular/forms';
26 import { MatSelectModule } from '@angular/material/select';
27 import { MatSelectHarness } from '@angular/material/select/testing';
28 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
29 import { of } from "rxjs/observable/of";
30 import { Ric } from 'src/app/interfaces/ric';
31 import { PolicyService } from 'src/app/services/policy/policy.service';
33 import { RicSelectorComponent } from './ric-selector.component';
36 describe('RicSelectorComponent', () => {
37 let formGroup: FormGroup = new FormGroup({});
38 let component: TestRicSelectorHostComponent;
39 let fixture: ComponentFixture<TestRicSelectorHostComponent>;
40 let loader: HarnessLoader;
41 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
42 const ric1: Ric = { ric_id: 'ric1', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
43 const ric2: Ric = { ric_id: 'ric2', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
45 beforeEach(async(() => {
46 policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getRics']);
50 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
55 policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] }));
56 TestBed.configureTestingModule({
58 BrowserAnimationsModule,
62 CUSTOM_ELEMENTS_SCHEMA
66 TestRicSelectorHostComponent
69 { provide: PolicyService, useValue: policyServiceSpy },
75 fixture = TestBed.createComponent(TestRicSelectorHostComponent);
76 component = fixture.componentInstance;
77 fixture.detectChanges();
78 loader = TestbedHarnessEnvironment.loader(fixture);
81 it('should create', () => {
82 expect(component).toBeTruthy();
85 it('no ric selected', async () => {
86 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
88 expect(await ricSelector.isEmpty()).toBeTruthy();
91 it('options should contain rics for policy type', async () => {
92 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
94 expect(policyServiceSpy.getRics).toHaveBeenCalledWith('policyTypeName');
95 await ricSelector.open();
96 const count = (await ricSelector.getOptions()).length;
97 expect(count).toEqual(2);
101 selector: `ric-selector-host-component`,
102 template: `<nrcp-ric-selector [instanceForm]="instanceForm" [policyTypeName]="policyTypeName"></nrcp-ric-selector>`
104 class TestRicSelectorHostComponent {
105 @ViewChild(RicSelectorComponent)
106 private ricSelectorComponent: RicSelectorComponent;
107 instanceForm: FormGroup = formGroup;
108 policyTypeName: string = 'policyTypeName';