Clean up and format
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / no-type-policy-editor / no-type-policy-editor.component.spec.ts
index fb3a6a6..c87a656 100644 (file)
@@ -22,7 +22,6 @@ 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";
@@ -34,7 +33,6 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
 import { NoTypePolicyEditorComponent } from "./no-type-policy-editor.component";
 
 describe("NoTypePolicyEditorComponent", () => {
-  let formGroup: FormGroup = new FormGroup({});
 
   let component: TestNoTypePolicyEditorComponentHostComponent;
   let fixture: ComponentFixture<TestNoTypePolicyEditorComponentHostComponent>;
@@ -54,7 +52,6 @@ describe("NoTypePolicyEditorComponent", () => {
         NoTypePolicyEditorComponent,
         TestNoTypePolicyEditorComponentHostComponent,
       ],
-      providers: [FormBuilder],
     }).compileComponents();
 
     fixture = TestBed.createComponent(
@@ -69,15 +66,6 @@ describe("NoTypePolicyEditorComponent", () => {
     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" })
@@ -91,7 +79,9 @@ describe("NoTypePolicyEditorComponent", () => {
   });
 
   it("Format button should be disabled when json not valid", async () => {
-    const ele = formGroup.get("policyJsonTextArea");
+    const ele = component.noTypePolicyEditorComponent.instanceForm.get(
+      "policyJsonTextArea"
+    );
     ele.setValue("{");
 
     let formatButton: MatButtonHarness = await loader.getHarness(
@@ -101,7 +91,9 @@ describe("NoTypePolicyEditorComponent", () => {
   });
 
   it("should format unformatted json", async () => {
-    const textArea = formGroup.get("policyJsonTextArea");
+    const textArea = component.noTypePolicyEditorComponent.instanceForm.get(
+      "policyJsonTextArea"
+    );
     textArea.setValue('{"A":"A"}');
     component.noTypePolicyEditorComponent.formatJsonInput();
     expect(component.noTypePolicyEditorComponent.policyJson).toEqual(
@@ -113,13 +105,11 @@ describe("NoTypePolicyEditorComponent", () => {
     selector: `no-type-policy-editor-host-component`,
     template: `<nrcp-no-type-policy-editor
       [policyJson]="this.policyJson"
-      [instanceForm]="instanceForm"
     ></nrcp-no-type-policy-editor>`,
   })
   class TestNoTypePolicyEditorComponentHostComponent {
     @ViewChild(NoTypePolicyEditorComponent)
     noTypePolicyEditorComponent: NoTypePolicyEditorComponent;
-    instanceForm: FormGroup = formGroup;
     policyJson: string = '{"A":"A"}';
   }
 });