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===================================
22 import { HarnessLoader } from '@angular/cdk/testing';
23 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
24 import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
25 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
26 import { FormBuilder, FormGroup } from '@angular/forms';
27 import { MatSelectModule } from '@angular/material/select';
28 import { MatSelectHarness } from '@angular/material/select/testing';
29 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
30 import { of } from "rxjs/observable/of";
31 import { Ric } from 'src/app/interfaces/ric';
32 import { PolicyService } from 'src/app/services/policy/policy.service';
34 import { RicSelectorComponent } from './ric-selector.component';
37 describe('RicSelectorComponent', () => {
38 let formGroup: FormGroup = new FormGroup({});
39 let component: TestRicSelectorHostComponent;
40 let fixture: ComponentFixture<TestRicSelectorHostComponent>;
41 let loader: HarnessLoader;
42 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
43 const ric1: Ric = { ric_id: 'ric1', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
44 const ric2: Ric = { ric_id: 'ric2', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
46 beforeEach(async(() => {
47 policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getRics']);
51 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
56 policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] }));
57 TestBed.configureTestingModule({
59 BrowserAnimationsModule,
63 CUSTOM_ELEMENTS_SCHEMA
67 TestRicSelectorHostComponent
70 { provide: PolicyService, useValue: policyServiceSpy },
76 fixture = TestBed.createComponent(TestRicSelectorHostComponent);
77 component = fixture.componentInstance;
78 fixture.detectChanges();
79 loader = TestbedHarnessEnvironment.loader(fixture);
82 it('should create', () => {
83 expect(component).toBeTruthy();
86 it('should be added to form group with required validator', async () => {
87 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
89 expect(formGroup.get('ricSelector')).toBeTruthy();
90 expect(await ricSelector.isRequired()).toBeTruthy();
93 it('no ric selected', async () => {
94 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
96 expect(await ricSelector.isEmpty()).toBeTruthy();
99 it('options should contain rics for policy type', async () => {
100 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
102 expect(policyServiceSpy.getRics).toHaveBeenCalledWith('policyTypeName');
103 await ricSelector.open();
104 const count = (await ricSelector.getOptions()).length;
105 expect(count).toEqual(2);
109 selector: `ric-selector-host-component`,
110 template: `<nrcp-ric-selector [instanceForm]="instanceForm" [policyTypeName]="policyTypeName"></nrcp-ric-selector>`
112 class TestRicSelectorHostComponent {
113 @ViewChild(RicSelectorComponent)
114 private ricSelectorComponent: RicSelectorComponent;
115 instanceForm: FormGroup = formGroup;
116 policyTypeName: string = 'policyTypeName';