Clean up and format
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / policy-instance-dialog / policy-instance-dialog.component.spec.ts
index b4c2732..e9b4c58 100644 (file)
@@ -30,13 +30,7 @@ import {
 } from "@angular/material/dialog";
 import { MatSelectModule } from "@angular/material/select";
 import { MatInputModule } from "@angular/material/input";
-import {
-  AbstractControl,
-  FormControl,
-  FormGroup,
-  ReactiveFormsModule,
-  Validators,
-} from "@angular/forms";
+import { AbstractControl, ReactiveFormsModule } from "@angular/forms";
 import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed";
 import { ToastrModule } from "ngx-toastr";
 
@@ -126,29 +120,24 @@ describe("PolicyInstanceDialogComponent", () => {
       expect(ele).toBeFalsy();
     });
 
-    it("should contain ric select with instance form and no policy type", async () => {
-      const ricSelector: RicSelectorComponent = fixture.debugElement.query(By.directive(RicSelectorComponent)).componentInstance;
+    it("should contain ric select with no policy type", async () => {
+      const ricSelector: RicSelectorComponent = fixture.debugElement.query(
+        By.directive(RicSelectorComponent)
+      ).componentInstance;
       expect(ricSelector).toBeTruthy();
-      expect(ricSelector.instanceForm).toBeTruthy();
       expect(ricSelector.policyTypeName).toBeFalsy();
     });
 
-    it("should contain json editor with instance form and empty JSON", async () => {
-      const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(By.directive(NoTypePolicyEditorComponent)).componentInstance;
+    it("should contain json editor with empty JSON", async () => {
+      const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(
+        By.directive(NoTypePolicyEditorComponent)
+      ).componentInstance;
       expect(noTypePolicyEditor).toBeTruthy();
-      expect(noTypePolicyEditor.instanceForm).toBeTruthy();
       expect(noTypePolicyEditor.policyJson).toEqual("{}");
     });
 
-    it("should contain enabled Close button and disabled Submit button", async () => {
+    it("should contain enabled Close button and Submit button", async () => {
       component.ngOnInit();
-      // Add an empty value with required validator to set the dialog's instance form to be invalid.
-      const value: any = null;
-      component.instanceForm.addControl(
-        "dummy",
-        new FormControl(value, [Validators.required])
-      );
-      expect(component.instanceForm.valid).toBeFalsy();
 
       let closeButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#closeButton" })
@@ -159,7 +148,6 @@ describe("PolicyInstanceDialogComponent", () => {
       let submitButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#submitButton" })
       );
-      expect(await submitButton.isDisabled()).toBeTruthy();
       expect(await submitButton.getText()).toEqual("Submit");
     });
   });
@@ -191,30 +179,26 @@ describe("PolicyInstanceDialogComponent", () => {
       expect(ele).toBeFalsy();
     });
 
-    it("should contain ric select with instance form and provided policy type", async () => {
-      const ricSelector: RicSelectorComponent = fixture.debugElement.query(By.directive(RicSelectorComponent)).componentInstance;
+    it("should contain ric select with provided policy type", async () => {
+      const ricSelector: RicSelectorComponent = fixture.debugElement.query(
+        By.directive(RicSelectorComponent)
+      ).componentInstance;
       expect(ricSelector).toBeTruthy();
-      expect(ricSelector.instanceForm).toBeTruthy();
       expect(ricSelector.policyTypeName).toEqual("Type 1");
     });
 
     it("should contain typed json editor with empty JSON, schema and dark mode true", async () => {
-      const typedPolicyEditor: TypedPolicyEditorComponent = fixture.debugElement.query(By.directive(TypedPolicyEditorComponent)).componentInstance;
+      const typedPolicyEditor: TypedPolicyEditorComponent = fixture.debugElement.query(
+        By.directive(TypedPolicyEditorComponent)
+      ).componentInstance;
       expect(typedPolicyEditor).toBeTruthy();
       expect(typedPolicyEditor.jsonObject).toBeFalsy();
       expect(typedPolicyEditor.jsonSchemaObject).toEqual(typedSchema);
       expect(typedPolicyEditor.darkMode).toBeTruthy();
     });
 
-    it("should contain enabled Close button and disabled Submit button", async () => {
+    it("should contain enabled Close button and Submit button", async () => {
       component.ngOnInit();
-      // Add an empty value with required validator to set the dialog's instance form to be invalid.
-      const value: any = null;
-      component.instanceForm.addControl(
-        "dummy",
-        new FormControl(value, [Validators.required])
-      );
-      expect(component.instanceForm.valid).toBeFalsy();
 
       let closeButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#closeButton" })
@@ -225,7 +209,6 @@ describe("PolicyInstanceDialogComponent", () => {
       let submitButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#submitButton" })
       );
-      expect(await submitButton.isDisabled()).toBeTruthy();
       expect(await submitButton.getText()).toEqual("Submit");
     });
   });
@@ -261,20 +244,23 @@ describe("PolicyInstanceDialogComponent", () => {
     });
 
     it("should not contain ric select", async () => {
-      const ricSelector = fixture.debugElement.query(By.directive(RicSelectorComponent));
+      const ricSelector = fixture.debugElement.query(
+        By.directive(RicSelectorComponent)
+      );
       expect(ricSelector).toBeFalsy();
     });
 
-    it("should contain json editor with form and json data", async () => {
-      const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(By.directive(NoTypePolicyEditorComponent)).componentInstance;
+    it("should contain json editor with json data", async () => {
+      const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(
+        By.directive(NoTypePolicyEditorComponent)
+      ).componentInstance;
       expect(noTypePolicyEditor).toBeTruthy();
-      expect(noTypePolicyEditor.instanceForm).toBeTruthy();
-      expect(unescapeQuotes(noTypePolicyEditor.policyJson)).toEqual('"' + instanceJson + '"');
+      expect(unescapeQuotes(noTypePolicyEditor.policyJson)).toEqual(
+        '"' + instanceJson + '"'
+      );
     });
 
     it("should contain enabled Close and Submit buttons when all inputs are valid", async () => {
-      expect(component.instanceForm.valid).toBeTruthy();
-
       let closeButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#closeButton" })
       );
@@ -320,21 +306,25 @@ describe("PolicyInstanceDialogComponent", () => {
     });
 
     it("should not contain ric select", async () => {
-      const ricSelector = fixture.debugElement.query(By.directive(RicSelectorComponent));
+      const ricSelector = fixture.debugElement.query(
+        By.directive(RicSelectorComponent)
+      );
       expect(ricSelector).toBeFalsy();
     });
 
     it("should contain typed json editor with instance JSON, schema and dark mode true", async () => {
-      const typedPolicyEditor: TypedPolicyEditorComponent = fixture.debugElement.query(By.directive(TypedPolicyEditorComponent)).componentInstance;
+      const typedPolicyEditor: TypedPolicyEditorComponent = fixture.debugElement.query(
+        By.directive(TypedPolicyEditorComponent)
+      ).componentInstance;
       expect(typedPolicyEditor).toBeTruthy();
-      expect(unescapeQuotes(typedPolicyEditor.jsonObject)).toEqual(instanceJson);
+      expect(unescapeQuotes(typedPolicyEditor.jsonObject)).toEqual(
+        instanceJson
+      );
       expect(typedPolicyEditor.jsonSchemaObject).toEqual(typedSchema);
       expect(typedPolicyEditor.darkMode).toBeTruthy();
     });
 
     it("should contain enabled Close and Submit buttons when all inputs are valid", async () => {
-      expect(component.instanceForm.valid).toBeTruthy();
-
       let closeButton: MatButtonHarness = await loader.getHarness(
         MatButtonHarness.with({ selector: "#closeButton" })
       );
@@ -379,7 +369,6 @@ function unescapeQuotes(string: string): string {
   ],
 })
 class RicSelectorStubComponent {
-  @Input() instanceForm: FormGroup;
   @Input() policyTypeName: string = "";
 
   get selectedRic(): string {
@@ -398,7 +387,6 @@ class RicSelectorStubComponent {
   ],
 })
 class NoTypePolicyEditorStubComponent {
-  @Input() instanceForm: FormGroup;
   @Input() policyJson: string;
 
   get policyJsonTextArea(): AbstractControl {