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 { OptionHarnessFilters } from "@angular/material/core/testing";
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";
35 describe("RicSelectorComponent", () => {
36 let component: TestRicSelectorHostComponent;
37 let fixture: ComponentFixture<TestRicSelectorHostComponent>;
38 let loader: HarnessLoader;
39 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
42 managed_element_ids: ["me1"],
43 policytype_ids: ["type1"],
48 managed_element_ids: ["me1"],
49 policytype_ids: ["type1"],
53 beforeEach(async(() => {
54 policyServiceSpy = jasmine.createSpyObj("PolicyService", ["getRics"]);
58 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
63 policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] }));
64 TestBed.configureTestingModule({
65 imports: [BrowserAnimationsModule, MatSelectModule],
66 schemas: [CUSTOM_ELEMENTS_SCHEMA],
67 declarations: [RicSelectorComponent, TestRicSelectorHostComponent],
68 providers: [{ provide: PolicyService, useValue: policyServiceSpy }],
69 }).compileComponents();
71 fixture = TestBed.createComponent(TestRicSelectorHostComponent);
72 component = fixture.componentInstance;
73 fixture.detectChanges();
74 loader = TestbedHarnessEnvironment.loader(fixture);
77 it("should create", () => {
78 expect(component).toBeTruthy();
81 it("no ric selected", async () => {
82 let ricSelector: MatSelectHarness = await loader.getHarness(
83 MatSelectHarness.with({ selector: "#ricSelector" })
86 expect(await ricSelector.isEmpty()).toBeTruthy();
89 it("options should contain rics for policy type", async () => {
90 let ricSelector: MatSelectHarness = await loader.getHarness(
91 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);
100 it("should send selected ric", async () => {
101 let selectedRic: string;
102 component.ricSelectorComponent.selectedRic.subscribe((ric: string) => {
106 let ricSelector: MatSelectHarness = await loader.getHarness(
107 MatSelectHarness.with({ selector: "#ricSelector" })
109 await ricSelector.clickOptions({ text: "ric1" });
111 expect(selectedRic).toEqual("ric1");
115 selector: `ric-selector-host-component`,
116 template: `<nrcp-ric-selector
117 [policyTypeName]="policyTypeName"
118 ></nrcp-ric-selector>`,
120 class TestRicSelectorHostComponent {
121 @ViewChild(RicSelectorComponent)
122 ricSelectorComponent: RicSelectorComponent;
123 policyTypeName: string = "policyTypeName";