+
+ it("should enable Submit button when ric is selected and json is valid", async () => {
+ const ricSelector: RicSelectorComponent = fixture.debugElement.query(
+ By.directive(RicSelectorComponent)
+ ).componentInstance;
+ const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(
+ By.directive(NoTypePolicyEditorComponent)
+ ).componentInstance;
+ let submitButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#submitButton" })
+ );
+
+ noTypePolicyEditor.validJson.emit(null);
+ expect(await submitButton.isDisabled()).toBeTruthy();
+
+ ricSelector.selectedRic.emit("ric1");
+ expect(await submitButton.isDisabled()).toBeTruthy();
+
+ noTypePolicyEditor.validJson.emit("{}");
+ expect(await submitButton.isDisabled()).toBeFalsy();
+ });
+
+ it("should generate policy ID when submitting new policy and close dialog", async () => {
+ const ricSelector: RicSelectorComponent = fixture.debugElement.query(
+ By.directive(RicSelectorComponent)
+ ).componentInstance;
+ const noTypePolicyEditor: NoTypePolicyEditorComponent = fixture.debugElement.query(
+ By.directive(NoTypePolicyEditorComponent)
+ ).componentInstance;
+ let submitButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#submitButton" })
+ );
+
+ spyOn(uuid, "v4").and.returnValue("1234567890");
+ ricSelector.selectedRic.emit("ric1");
+ noTypePolicyEditor.validJson.emit("{}");
+
+ policyServiceSpy.putPolicy.and.returnValue(of("Success"));
+
+ await submitButton.click();
+
+ const policyInstance = {} as CreatePolicyInstance;
+ policyInstance.policy_data = JSON.parse("{}");
+ policyInstance.policy_id = "1234567890";
+ policyInstance.policytype_id = "";
+ policyInstance.ric_id = "ric1";
+ policyInstance.service_id = "controlpanel";
+ expect(policyServiceSpy.putPolicy).toHaveBeenCalledWith(policyInstance);
+
+ expect(dialogRefSpy.close).toHaveBeenCalledWith("ok");
+ });
+
+ it("should not close dialog when error from server", async () => {
+ let submitButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#submitButton" })
+ );
+
+ const errorResponse = {
+ status: 400,
+ statusText: "Bad Request",
+ } as HttpErrorResponse;
+ policyServiceSpy.putPolicy.and.returnValue(errorResponse);
+
+ await submitButton.click();
+
+ expect(policyServiceSpy.putPolicy).toHaveBeenCalled();
+
+ expect(dialogRefSpy.close).not.toHaveBeenCalled();
+ });