X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fric-selector%2Fric-selector.component.spec.ts;h=34abab48fb3f8a3e108dce8ef0e17ea2d3138d75;hb=be7ac675e03d10608f81d06604afd7a73d86e3e2;hp=0306ec4de187ee5558316f0aae4c36538d369a48;hpb=23f01d834cb151beb27ce2da0fe7f7b42b3b3a4d;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.spec.ts b/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.spec.ts index 0306ec4..34abab4 100644 --- a/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.spec.ts +++ b/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.spec.ts @@ -1,53 +1,72 @@ -import { HarnessLoader } from '@angular/cdk/testing'; -import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; -import { Component, ViewChild } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormBuilder, FormGroup } from '@angular/forms'; -import { MatSelectModule } from '@angular/material/select'; -import { MatSelectHarness } from '@angular/material/select/testing'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { of } from "rxjs/observable/of"; -import { Ric } from 'src/app/interfaces/ric'; -import { PolicyService } from 'src/app/services/policy/policy.service'; +// - +// ========================LICENSE_START================================= +// O-RAN-SC +// %% +// Copyright (C) 2021: Nordix Foundation +// %% +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ========================LICENSE_END=================================== +// -import { RicSelectorComponent } from './ric-selector.component'; +import { HarnessLoader } from "@angular/cdk/testing"; +import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed"; +import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core"; +import { async, ComponentFixture, TestBed } from "@angular/core/testing"; +import { OptionHarnessFilters } from "@angular/material/core/testing"; +import { MatSelectModule } from "@angular/material/select"; +import { MatSelectHarness } from "@angular/material/select/testing"; +import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { of } from "rxjs/observable/of"; +import { Ric } from "@interfaces/ric"; +import { PolicyService } from "@services/policy/policy.service"; -let formGroup: FormGroup = new FormGroup({}); +import { RicSelectorComponent } from "./ric-selector.component"; -describe('RicSelectorComponent', () => { +describe("RicSelectorComponent", () => { let component: TestRicSelectorHostComponent; let fixture: ComponentFixture; let loader: HarnessLoader; let policyServiceSpy: jasmine.SpyObj; - const ric1: Ric = { ric_id: 'ric1', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' }; - const ric2: Ric = { ric_id: 'ric2', managed_element_ids: ['me1'], policytype_ids: ['type1'], state: '' }; + const ric1: Ric = { + ric_id: "ric1", + managed_element_ids: ["me1"], + policytype_ids: ["type1"], + state: "", + }; + const ric2: Ric = { + ric_id: "ric2", + managed_element_ids: ["me1"], + policytype_ids: ["type1"], + state: "", + }; beforeEach(async(() => { - policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getRics']); + policyServiceSpy = jasmine.createSpyObj("PolicyService", ["getRics"]); const policyData = { createSchema: "{}", instanceId: null, instanceJson: '{"qosObjectives": {"priorityLevel": 3100}}', name: "name", - ric: null + ric: null, }; policyServiceSpy.getRics.and.returnValue(of({ rics: [ric1, ric2] })); TestBed.configureTestingModule({ - imports: [ - BrowserAnimationsModule, - MatSelectModule, - ], - declarations: [ - RicSelectorComponent, - TestRicSelectorHostComponent - ], - providers: [ - { provide: PolicyService, useValue: policyServiceSpy }, - FormBuilder - ] - }) - .compileComponents(); + imports: [BrowserAnimationsModule, MatSelectModule], + schemas: [CUSTOM_ELEMENTS_SCHEMA], + declarations: [RicSelectorComponent, TestRicSelectorHostComponent], + providers: [{ provide: PolicyService, useValue: policyServiceSpy }], + }).compileComponents(); fixture = TestBed.createComponent(TestRicSelectorHostComponent); component = fixture.componentInstance; @@ -55,40 +74,52 @@ describe('RicSelectorComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); })); - it('should create', () => { + it("should create", () => { expect(component).toBeTruthy(); }); - it('should be added to form group with required validator', async () => { - let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' })); - - expect(formGroup.get('ricSelector')).toBeTruthy(); - expect(await ricSelector.isRequired()).toBeTruthy(); - }); - - it('no ric selected', async () => { - let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' })); + it("no ric selected", async () => { + let ricSelector: MatSelectHarness = await loader.getHarness( + MatSelectHarness.with({ selector: "#ricSelector" }) + ); expect(await ricSelector.isEmpty()).toBeTruthy(); }); - it('options should contain rics for policy type', async () => { - let ricSelector: MatSelectHarness = await loader.getHarness(MatSelectHarness.with({ selector: '#ricSelector' })); + it("options should contain rics for policy type", async () => { + let ricSelector: MatSelectHarness = await loader.getHarness( + MatSelectHarness.with({ selector: "#ricSelector" }) + ); - expect(policyServiceSpy.getRics).toHaveBeenCalledWith('policyTypeName'); + expect(policyServiceSpy.getRics).toHaveBeenCalledWith("policyTypeName"); await ricSelector.open(); const count = (await ricSelector.getOptions()).length; expect(count).toEqual(2); }); -}); -@Component({ - selector: `ric-selector-host-component`, - template: `` -}) -export class TestRicSelectorHostComponent { - @ViewChild(RicSelectorComponent) - private ricSelectorComponent: RicSelectorComponent; - instanceForm: FormGroup = formGroup; - policyTypeName: string = 'policyTypeName'; -} + it("should send selected ric", async () => { + let selectedRic: string; + component.ricSelectorComponent.selectedRic.subscribe((ric: string) => { + selectedRic = ric; + }); + + let ricSelector: MatSelectHarness = await loader.getHarness( + MatSelectHarness.with({ selector: "#ricSelector" }) + ); + await ricSelector.clickOptions({ text: "ric1" }); + + expect(selectedRic).toEqual("ric1"); + }); + + @Component({ + selector: `ric-selector-host-component`, + template: ``, + }) + class TestRicSelectorHostComponent { + @ViewChild(RicSelectorComponent) + ricSelectorComponent: RicSelectorComponent; + policyTypeName: string = "policyTypeName"; + } +});