X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fno-type-policy-editor%2Fno-type-policy-editor.component.spec.ts;h=7fb64c4acafc753a7e9f225136e22356538b4f65;hb=66372cb88b6b3e94dada9197c5efeaa7b2c93e17;hp=529caee2492b233caee410254d8883d7121984d3;hpb=3caae651141afb8f90a3e7d468b26bb3f3765f7e;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts index 529caee..7fb64c4 100644 --- a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts +++ b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts @@ -18,22 +18,22 @@ // ========================LICENSE_END=================================== // -import { HarnessLoader } from '@angular/cdk/testing'; -import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; -import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormBuilder, FormGroup } from '@angular/forms'; -import { MatButtonModule } from '@angular/material/button'; -import { MatButtonHarness } from '@angular/material/button/testing'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { MatInputHarness } from '@angular/material/input/testing'; -import { BrowserModule } from '@angular/platform-browser'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { HarnessLoader } from "@angular/cdk/testing"; +import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed"; +import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { FormBuilder, FormGroup } from "@angular/forms"; +import { MatButtonModule } from "@angular/material/button"; +import { MatButtonHarness } from "@angular/material/button/testing"; +import { MatFormFieldModule } from "@angular/material/form-field"; +import { MatInputModule } from "@angular/material/input"; +import { MatInputHarness } from "@angular/material/input/testing"; +import { BrowserModule } from "@angular/platform-browser"; +import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; -import { NoTypePolicyEditorComponent } from './no-type-policy-editor.component'; +import { NoTypePolicyEditorComponent } from "./no-type-policy-editor.component"; -describe('NoTypePolicyEditorComponent', () => { +describe("NoTypePolicyEditorComponent", () => { let formGroup: FormGroup = new FormGroup({}); let component: TestNoTypePolicyEditorComponentHostComponent; @@ -47,70 +47,68 @@ describe('NoTypePolicyEditorComponent', () => { BrowserAnimationsModule, MatButtonModule, MatFormFieldModule, - MatInputModule - ], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA + MatInputModule, ], + schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [ NoTypePolicyEditorComponent, - TestNoTypePolicyEditorComponentHostComponent + TestNoTypePolicyEditorComponentHostComponent, ], - providers: [ - FormBuilder - ] - }) - .compileComponents(); + providers: [FormBuilder], + }).compileComponents(); - fixture = TestBed.createComponent(TestNoTypePolicyEditorComponentHostComponent); + fixture = TestBed.createComponent( + TestNoTypePolicyEditorComponentHostComponent + ); component = fixture.componentInstance; fixture.detectChanges(); 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 textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' })); - - expect(formGroup.get('policyJsonTextArea')).toBeTruthy(); - expect(await textArea.isRequired()).toBeTruthy(); - }); - - it('should contain provided policy json and enabled Format button', async () => { - let textArea: MatInputHarness = await loader.getHarness(MatInputHarness.with({ selector: '#policyJsonTextArea' })); + it("should contain provided policy json and enabled Format button", async () => { + let textArea: MatInputHarness = await loader.getHarness( + MatInputHarness.with({ selector: "#policyJsonTextArea" }) + ); expect(await textArea.getValue()).toEqual('{"A":"A"}'); - console.log('Validity:',formGroup.valid); - let formatButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#formatButton' })); + let formatButton: MatButtonHarness = await loader.getHarness( + MatButtonHarness.with({ selector: "#formatButton" }) + ); expect(await formatButton.isDisabled()).toBeFalsy(); }); - it('Format button should be disabled when json not valid', async () => { - const ele = formGroup.get('policyJsonTextArea'); - ele.setValue('{'); + it("Format button should be disabled when json not valid", async () => { + const ele = component.noTypePolicyEditorComponent.instanceForm.get("policyJsonTextArea"); + ele.setValue("{"); - let formatButton: MatButtonHarness = await loader.getHarness(MatButtonHarness.with({ selector: '#formatButton' })); + let formatButton: MatButtonHarness = await loader.getHarness( + MatButtonHarness.with({ selector: "#formatButton" }) + ); expect(await formatButton.isDisabled()).toBeTruthy(); }); - it('should format unformatted json', async () => { - const textArea = formGroup.get('policyJsonTextArea'); + it("should format unformatted json", async () => { + const textArea = component.noTypePolicyEditorComponent.instanceForm.get("policyJsonTextArea"); textArea.setValue('{"A":"A"}'); component.noTypePolicyEditorComponent.formatJsonInput(); - expect(component.noTypePolicyEditorComponent.policyJson).toEqual('{\n "A": "A"\n}'); + expect(component.noTypePolicyEditorComponent.policyJson).toEqual( + '{\n "A": "A"\n}' + ); }); @Component({ selector: `no-type-policy-editor-host-component`, - template: `` + template: ``, }) class TestNoTypePolicyEditorComponentHostComponent { @ViewChild(NoTypePolicyEditorComponent) noTypePolicyEditorComponent: NoTypePolicyEditorComponent; - instanceForm: FormGroup = formGroup; policyJson: string = '{"A":"A"}'; } });