+ 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 bloody framework count the number of calls to the spy correctly!
+ await policiesTable.getRows();
+
+ expect(componentUnderTest.modifyInstance).toHaveBeenCalledTimes(4);
+ });
+
+ 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(
+ "Delete Policy",
+ "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();
+ });
+
+ it("should open dialog asking for delete and not delete whith Cancel as response", async () => {
+ const dialogRefSpy = setupDialogRefSpy(false);
+ confirmServiceSpy.openConfirmDialog.and.returnValue(dialogRefSpy);
+
+ const deleteButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#policy1DeleteButton" })
+ );
+ await deleteButton.click();
+
+ expect(policyServiceSpy.deletePolicy).not.toHaveBeenCalled();
+ });
+
+ it("should refresh table", async () => {
+ spyOn(componentUnderTest, "getPolicyInstances");
+
+ const refreshButton: MatButtonHarness = await loader.getHarness(
+ MatButtonHarness.with({ selector: "#refreshButton" })
+ );
+ await refreshButton.click();
+
+ expect(componentUnderTest.getPolicyInstances).toHaveBeenCalled();
+ });