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=7c552bc1ddd0e9a86bfdb1eb3eef2003fa96f521;hb=4af3bc930eb59eb9457db01b3b6ccf6b7376aaad;hp=c87a656f47d9352d1ea72301cc6892a20154e312;hpb=a2a4491f5e44b5979f0d84a3065bcf76f3b01b93;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 c87a656..7c552bc 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 @@ -33,7 +33,6 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { NoTypePolicyEditorComponent } from "./no-type-policy-editor.component"; describe("NoTypePolicyEditorComponent", () => { - let component: TestNoTypePolicyEditorComponentHostComponent; let fixture: ComponentFixture; let loader: HarnessLoader; @@ -67,12 +66,12 @@ describe("NoTypePolicyEditorComponent", () => { }); it("should contain provided policy json and enabled Format button", async () => { - let textArea: MatInputHarness = await loader.getHarness( + const textArea: MatInputHarness = await loader.getHarness( MatInputHarness.with({ selector: "#policyJsonTextArea" }) ); expect(await textArea.getValue()).toEqual('{"A":"A"}'); - let formatButton: MatButtonHarness = await loader.getHarness( + const formatButton: MatButtonHarness = await loader.getHarness( MatButtonHarness.with({ selector: "#formatButton" }) ); expect(await formatButton.isDisabled()).toBeFalsy(); @@ -84,21 +83,47 @@ describe("NoTypePolicyEditorComponent", () => { ); ele.setValue("{"); - let formatButton: MatButtonHarness = await loader.getHarness( + const formatButton: MatButtonHarness = await loader.getHarness( MatButtonHarness.with({ selector: "#formatButton" }) ); expect(await formatButton.isDisabled()).toBeTruthy(); }); - it("should format unformatted json", async () => { + it("should send valid json", async () => { + const textAreaHarness: MatInputHarness = await loader.getHarness( + MatInputHarness.with({ selector: "#policyJsonTextArea" }) + ); + expect(await textAreaHarness.getValue()).toEqual('{"A":"A"}'); + + let validJson: string; + component.noTypePolicyEditorComponent.validJson.subscribe( + (json: string) => { + validJson = json; + } + ); + const textArea = component.noTypePolicyEditorComponent.instanceForm.get( "policyJsonTextArea" ); - textArea.setValue('{"A":"A"}'); - component.noTypePolicyEditorComponent.formatJsonInput(); - expect(component.noTypePolicyEditorComponent.policyJson).toEqual( - '{\n "A": "A"\n}' + textArea.setValue('{"B":"B"}'); + expect(validJson).toEqual('{"B":"B"}'); + }); + + it("should send null when invalid json", async () => { + const textArea: MatInputHarness = await loader.getHarness( + MatInputHarness.with({ selector: "#policyJsonTextArea" }) + ); + expect(await textArea.getValue()).toEqual('{"A":"A"}'); + + let invalidJson: string; + component.noTypePolicyEditorComponent.validJson.subscribe( + (json: string) => { + invalidJson = json; + } ); + + textArea.setValue("{"); + expect(invalidJson).toBeFalsy(); }); @Component({