1 import { HarnessLoader } from '@angular/cdk/testing';
2 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
3 import { Component, ViewChild } from '@angular/core';
4 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
5 import { FormBuilder, FormGroup } from '@angular/forms';
6 import { MatSelectModule } from '@angular/material/select';
7 import { MatSelectHarness } from '@angular/material/select/testing';
8 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9 import { of } from "rxjs/observable/of";
10 import { Ric } from 'src/app/interfaces/ric';
11 import { PolicyService } from 'src/app/services/policy/policy.service';
13 import { RicSelectorComponent } from './ric-selector.component';
15 let formGroup: FormGroup = new FormGroup({});
17 describe('RicSelectorComponent', () => {
18 let component: TestRicSelectorHostComponent;
19 let fixture: ComponentFixture<TestRicSelectorHostComponent>;
20 let loader: HarnessLoader;
21 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
22 const ric1: Ric = { ric_id: 'ric1', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
23 const ric2: Ric = { ric_id: 'ric2', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' };
25 beforeEach(async(() => {
26 policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getRics']);
30 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
35 policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] }));
36 TestBed.configureTestingModule({
38 BrowserAnimationsModule,
43 TestRicSelectorHostComponent
46 { provide: PolicyService, useValue: policyServiceSpy },
52 fixture = TestBed.createComponent(TestRicSelectorHostComponent);
53 component = fixture.componentInstance;
54 fixture.detectChanges();
55 loader = TestbedHarnessEnvironment.loader(fixture);
58 it('should create', () => {
59 expect(component).toBeTruthy();
62 it('should be added to form group with required validator', async () => {
63 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
65 expect(formGroup.get('ricSelector')).toBeTruthy();
66 expect(await ricSelector.isRequired()).toBeTruthy();
69 it('no ric selected', async () => {
70 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
72 expect(await ricSelector.isEmpty()).toBeTruthy();
75 it('options should contain rics for policy type', async () => {
76 let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' }));
78 expect(policyServiceSpy.getRics).toHaveBeenCalledWith('policyTypeName');
79 await ricSelector.open();
80 const count = (await ricSelector.getOptions()).length;
81 expect(count).toEqual(2);
86 selector: `ric-selector-host-component`,
87 template: `<nrcp-ric-selector [instanceForm]="instanceForm" [policyTypeName]="policyTypeName"></nrcp-ric-selector>`
89 export class TestRicSelectorHostComponent {
90 @ViewChild(RicSelectorComponent)
91 private ricSelectorComponent: RicSelectorComponent;
92 instanceForm: FormGroup = formGroup;
93 policyTypeName: string = 'policyTypeName';