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 { MatSelectModule } from "@angular/material/select";
26 import { MatSelectHarness } from "@angular/material/select/testing";
27 import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
28 import { of } from "rxjs/observable/of";
29 import { Ric } from "src/app/interfaces/ric";
30 import { PolicyService } from "src/app/services/policy/policy.service";
32 import { RicSelectorComponent } from "./ric-selector.component";
34 describe("RicSelectorComponent", () => {
35 let component: TestRicSelectorHostComponent;
36 let fixture: ComponentFixture<TestRicSelectorHostComponent>;
37 let loader: HarnessLoader;
38 let policyServiceSpy: jasmine.SpyObj<PolicyService>;
41 managed_element_ids: ["me1"],
42 policytype_ids: ["type1"],
47 managed_element_ids: ["me1"],
48 policytype_ids: ["type1"],
52 beforeEach(async(() => {
53 policyServiceSpy = jasmine.createSpyObj("PolicyService", ["getRics"]);
57 instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}',
62 policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] }));
63 TestBed.configureTestingModule({
64 imports: [BrowserAnimationsModule, MatSelectModule],
65 schemas: [CUSTOM_ELEMENTS_SCHEMA],
66 declarations: [RicSelectorComponent, TestRicSelectorHostComponent],
67 providers: [{ provide: PolicyService, useValue: policyServiceSpy }],
68 }).compileComponents();
70 fixture = TestBed.createComponent(TestRicSelectorHostComponent);
71 component = fixture.componentInstance;
72 fixture.detectChanges();
73 loader = TestbedHarnessEnvironment.loader(fixture);
76 it("should create", () => {
77 expect(component).toBeTruthy();
80 it("no ric selected when no ric provided", async () => {
81 let ricSelector: MatSelectHarness = await loader.getHarness(
82 MatSelectHarness.with({ selector: "#ricSelector" })
85 expect(await ricSelector.isEmpty()).toBeTruthy();
88 it("options should contain rics for policy type", async () => {
89 let ricSelector: MatSelectHarness = await loader.getHarness(
90 MatSelectHarness.with({ selector: "#ricSelector" })
93 expect(policyServiceSpy.getRics).toHaveBeenCalledWith("policyTypeName");
94 await ricSelector.open();
95 const count = (await ricSelector.getOptions()).length;
96 expect(count).toEqual(2);
100 selector: `ric-selector-host-component`,
101 template: `<nrcp-ric-selector
102 [policyTypeName]="policyTypeName"
103 ></nrcp-ric-selector>`,
105 class TestRicSelectorHostComponent {
106 @ViewChild(RicSelectorComponent)
107 private ricSelectorComponent: RicSelectorComponent;
108 policyTypeName: string = "policyTypeName";