- it("should open dialog asking for delete and delete when ok response and refresh table afterwards", async () => {
- const dialogRefSpy = setupDialogRefSpy();
- confirmServiceSpy.openConfirmDialog.and.returnValue(dialogRefSpy);
- const createResponse = { status: 204 } as HttpResponse<Object>;
- policyServiceSpy.deletePolicy.and.returnValue(of(createResponse));
-
- spyOn(componentUnderTest, "getPolicyInstances");
- const deleteButton: MatButtonHarness = await loader.getHarness(
- MatButtonHarness.with({ selector: "#policy1DeleteButton" })
- );
- await deleteButton.click();
-
- expect(confirmServiceSpy.openConfirmDialog).toHaveBeenCalledWith(
- "Are you sure you want to delete this policy instance?"
- );
- expect(policyServiceSpy.deletePolicy).toHaveBeenCalledWith("policy1");
- expect(notificationServiceSpy.success).toHaveBeenCalledWith(
- "Delete succeeded!"
- );
- expect(componentUnderTest.getPolicyInstances).toHaveBeenCalled();
- });
+ spyOn(componentUnderTest, "getPolicyInstances");
+
+ const editButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#policy1EditButton" })
+ );
+ await editButton.click();
+
+ expect(dialogSpy.open).toHaveBeenCalledWith(
+ PolicyInstanceDialogComponent,
+ {
+ maxWidth: "1200px",
+ maxHeight: "900px",
+ width: "900px",
+ role: "dialog",
+ disableClose: false,
+ panelClass: "dark-theme",
+ data: {
+ createSchema: policyTypeSchema,
+ instanceId: "policy1",
+ instanceJson: "{}",
+ name: "1",
+ ric: "1",
+ },
+ }
+ );
+ expect(componentUnderTest.getPolicyInstances).toHaveBeenCalled();
+ });
+
+ it("should open dialog to edit policy and not refresh policies when dialog closed wihtout submit", async () => {
+ const dialogRefSpy = setupDialogRefSpy(false);
+ dialogSpy.open.and.returnValue(dialogRefSpy);
+
+ spyOn(componentUnderTest, "getPolicyInstances");
+
+ const editButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#policy1EditButton" })
+ );
+ await editButton.click();
+
+ expect(componentUnderTest.getPolicyInstances).not.toHaveBeenCalled();
+ });
+
+ it("should open instance dialog when clicking in any policy cell in table", async () => {
+ spyOn(componentUnderTest, "modifyInstance");
+
+ const policiesTable = await loader.getHarness(
+ MatTableHarness.with({ selector: "#policiesTable" })
+ );
+ const firstRow = (await policiesTable.getRows())[0];
+ const idCell = (await firstRow.getCells())[0];
+ (await idCell.host()).click();
+ const ownerCell = (await firstRow.getCells())[1];
+ (await ownerCell.host()).click();
+ const serviceCell = (await firstRow.getCells())[2];
+ (await serviceCell.host()).click();
+ const lastModifiedCell = (await firstRow.getCells())[3];
+ (await lastModifiedCell.host()).click();
+
+ // Totally unnecessary call just to make the framework count the number of calls to the spy correctly!
+ await policiesTable.getRows();
+
+ expect(componentUnderTest.modifyInstance).toHaveBeenCalledTimes(4);
+ });