CI: Migrate Sonar Scan job to GHA
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / no-type-policy-editor / no-type-policy-editor.component.spec.ts
index c87a656..7c552bc 100644 (file)
@@ -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<TestNoTypePolicyEditorComponentHostComponent>;
   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({