Merge "Remove unsed imports and file"
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..33170db 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 { NoTypePolicyEditorComponent } from "./no-type-policy-editor.component";
 
 describe("NoTypePolicyEditorComponent", () => {
-
   let component: TestNoTypePolicyEditorComponentHostComponent;
   let fixture: ComponentFixture<TestNoTypePolicyEditorComponentHostComponent>;
   let loader: HarnessLoader;
@@ -67,12 +66,12 @@
   });
 
   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,7 +83,7 @@
     );
     ele.setValue("{");
 
-    let formatButton: MatButtonHarness = await loader.getHarness(
+    const formatButton: MatButtonHarness = await loader.getHarness(
       MatButtonHarness.with({ selector: "#formatButton" })
     );
     expect(await formatButton.isDisabled()).toBeTruthy();
@@ -94,11 +93,40 @@
     const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
       "policyJsonTextArea"
     );
-    textArea.setValue('{"A":"A"}');
+    expect(textArea.value).toEqual('{"A":"A"}');
+
     component.noTypePolicyEditorComponent.formatJsonInput();
-    expect(component.noTypePolicyEditorComponent.policyJson).toEqual(
-      '{\n  "A": "A"\n}'
+    expect(textArea.value).toEqual('{\n  "A": "A"\n}');
+  });
+
+  it("should send valid json", async () => {
+    const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
+      "policyJsonTextArea"
     );
+    expect(textArea.value).toEqual('{"A":"A"}');
+
+    let validJson: string;
+    component.noTypePolicyEditorComponent.validJson.subscribe((json: string) => {
+      validJson = json;
+    });
+
+    textArea.setValue('{"B":"B"}');
+    expect(validJson).toEqual('{"B":"B"}');
+  });
+
+  it("should send null when invalid json", async () => {
+    const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
+      "policyJsonTextArea"
+    );
+    expect(textArea.value).toEqual('{"A":"A"}');
+
+    let invalidJson: string;
+    component.noTypePolicyEditorComponent.validJson.subscribe((json: string) => {
+      invalidJson = json;
+    });
+
+    textArea.setValue('{');
+    expect(invalidJson).toBeFalsy();
   });
 
   @Component({
diff --git a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts
index d231b00..5d2398c 100644
--- a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts
+++ b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts
@@ -63,9 +63,9 @@
   }
 
   formatJsonInput(): void {
-    this.policyJson = formatJsonString(
-      JSON.parse(this.policyJsonTextArea.value)
-    );
+    let jsonBefore: string = this.policyJsonTextArea.value;
+    let jsonAfter = formatJsonString(JSON.parse(jsonBefore));
+    this.policyJsonTextArea.setValue(jsonAfter);
   }
 
   jsonValidator(): ValidatorFn {
@@ -85,16 +85,14 @@
   }
 
   isJsonValid(json: string): boolean {
+    let valid = false as boolean;
     try {
       if (json != null) {
         JSON.parse(json);
-        return true;
-      } else {
-        return false;
+        valid = true;
       }
-    } catch (jsonError) {
-      return false;
-    }
+    } catch (jsonError) {}
+    return valid;
   }
 }