From 9ff40960490acec02a7828d42c420e05c63740bd Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 09:50:28 +0100 Subject: [PATCH 01/11] update alerts --- .../app/src/screens/role-management/account-form.tsx | 12 +++++++++--- .../screens/role-management/account-group-form.tsx | 12 +++++++++--- .../screens/role-management/account-role-form.tsx | 12 +++++++++--- .../role-management/global-permissions-form.tsx | 12 +++++++++--- .../role-management/object-permissions-form.tsx | 12 +++++++++--- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/frontend/app/src/screens/role-management/account-form.tsx b/frontend/app/src/screens/role-management/account-form.tsx index 4fde745ce0..ae707daaf9 100644 --- a/frontend/app/src/screens/role-management/account-form.tsx +++ b/frontend/app/src/screens/role-management/account-form.tsx @@ -90,9 +90,15 @@ export const AccountForm = ({ }, }); - toast(, { - toastId: "alert-success-account-created", - }); + if (currentObject) { + toast(, { + toastId: "alert-success-account-updated", + }); + } else { + toast(, { + toastId: "alert-success-account-created", + }); + } if (onSuccess) await onSuccess(result?.data?.[`${OBJECT_PERMISSION_OBJECT}Create`]); if (onUpdateComplete) await onUpdateComplete(); diff --git a/frontend/app/src/screens/role-management/account-group-form.tsx b/frontend/app/src/screens/role-management/account-group-form.tsx index a178756c4a..7e843a7591 100644 --- a/frontend/app/src/screens/role-management/account-group-form.tsx +++ b/frontend/app/src/screens/role-management/account-group-form.tsx @@ -102,9 +102,15 @@ export const AccountGroupForm = ({ }, }); - toast(, { - toastId: "alert-success-group-created", - }); + if (currentObject) { + toast(, { + toastId: "alert-success-group-updated", + }); + } else { + toast(, { + toastId: "alert-success-group-created", + }); + } if (onSuccess) await onSuccess(result?.data?.[`${OBJECT_PERMISSION_OBJECT}Create`]); if (onUpdateComplete) await onUpdateComplete(); diff --git a/frontend/app/src/screens/role-management/account-role-form.tsx b/frontend/app/src/screens/role-management/account-role-form.tsx index 76e19e99a5..be76982eab 100644 --- a/frontend/app/src/screens/role-management/account-role-form.tsx +++ b/frontend/app/src/screens/role-management/account-role-form.tsx @@ -95,9 +95,15 @@ export const AccountRoleForm = ({ }, }); - toast(, { - toastId: "alert-success-role-created", - }); + if (currentObject) { + toast(, { + toastId: "alert-success-role-updated", + }); + } else { + toast(, { + toastId: "alert-success-role-created", + }); + } if (onSuccess) await onSuccess(result?.data?.[`${ACCOUNT_ROLE_OBJECT}Create`]); if (onUpdateComplete) await onUpdateComplete(); diff --git a/frontend/app/src/screens/role-management/global-permissions-form.tsx b/frontend/app/src/screens/role-management/global-permissions-form.tsx index 682d3ca941..14ff6face3 100644 --- a/frontend/app/src/screens/role-management/global-permissions-form.tsx +++ b/frontend/app/src/screens/role-management/global-permissions-form.tsx @@ -101,9 +101,15 @@ export const GlobalPermissionForm = ({ }, }); - toast(, { - toastId: "alert-success-object-permission-created", - }); + if (currentObject) { + toast(, { + toastId: "alert-success-global-permission-updated", + }); + } else { + toast(, { + toastId: "alert-success-global-permission-created", + }); + } if (onSuccess) await onSuccess(result?.data?.[`${GLOBAL_PERMISSION_OBJECT}Create`]); if (onUpdateComplete) await onUpdateComplete(); diff --git a/frontend/app/src/screens/role-management/object-permissions-form.tsx b/frontend/app/src/screens/role-management/object-permissions-form.tsx index 9d35ef97a1..4c0b7b9c2f 100644 --- a/frontend/app/src/screens/role-management/object-permissions-form.tsx +++ b/frontend/app/src/screens/role-management/object-permissions-form.tsx @@ -118,9 +118,15 @@ export const ObjectPermissionForm = ({ }, }); - toast(, { - toastId: "alert-success-object-permission-created", - }); + if (currentObject) { + toast(, { + toastId: "alert-success-object-permission-updated", + }); + } else { + toast(, { + toastId: "alert-success-object-permission-created", + }); + } if (onSuccess) await onSuccess(result?.data?.[`${OBJECT_PERMISSION_OBJECT}Create`]); if (onUpdateComplete) await onUpdateComplete(); From 088019de640005b42db088782e607158f00f4f5a Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 10:36:16 +0100 Subject: [PATCH 02/11] fix relationship mutation --- .../form/utils/mutations/getCreateMutationFromFormData.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/app/src/components/form/utils/mutations/getCreateMutationFromFormData.ts b/frontend/app/src/components/form/utils/mutations/getCreateMutationFromFormData.ts index d27f9de378..8d7550999e 100644 --- a/frontend/app/src/components/form/utils/mutations/getCreateMutationFromFormData.ts +++ b/frontend/app/src/components/form/utils/mutations/getCreateMutationFromFormData.ts @@ -63,7 +63,10 @@ export const getCreateMutationFromFormDataOnly = ( return { ...acc, - [name]: Array.isArray(fieldValue) ? fieldValue : { value: fieldValue }, + [name]: Array.isArray(fieldValue) + ? // Uses array of ids for relationships + fieldValue.map((value) => ({ id: value.id })) + : { value: fieldValue }, }; } From a2f503c50cd99eede4b09b28f90b84bea490f117 Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 11:30:49 +0100 Subject: [PATCH 03/11] add test for role crud --- .../e2e/role-management/roles-crud.spec.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 frontend/app/tests/e2e/role-management/roles-crud.spec.ts diff --git a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts new file mode 100644 index 0000000000..ba5ec6818a --- /dev/null +++ b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts @@ -0,0 +1,106 @@ +import { expect, test } from "@playwright/test"; +import { ACCOUNT_STATE_PATH } from "../../constants"; + +test.describe("Role management - Roles CRUD", () => { + test.use({ storageState: ACCOUNT_STATE_PATH.ADMIN }); + test.describe.configure({ mode: "serial" }); + + test("should create a role ", async ({ page }) => { + await test.step("access main view", async () => { + await page.goto("/role-management/roles"); + }); + + await test.step("create role", async () => { + await page.getByRole("button", { name: "Create Account role" }).click(); + await page.getByLabel("Name *").click(); + await page.getByLabel("Name *").fill("test role"); + await page.getByLabel("Groups").click(); + await page.getByTestId("side-panel-container").getByText("Infrahub Users").click(); + await page.getByLabel("Groups").click(); + await page.getByTestId("side-panel-container").getByLabel("Permissions").click(); + await page + .getByTestId("side-panel-container") + .getByText("global:super_admin:allow_all") + .click(); + await page + .getByTestId("side-panel-container") + .getByText("global:manage_repositories:") + .click(); + await page.getByTestId("side-panel-container").getByLabel("Permissions").click(); + await page.getByRole("button", { name: "Create" }).click(); + await expect(page.getByText("Role created!")).toBeVisible(); + }); + + await test.step("verify role creation", async () => { + await expect(page.getByRole("cell", { name: "test role" })).toBeVisible(); + await expect( + page + .getByRole("cell", { + name: "global:super_admin:allow_all global:manage_repositories:allow_all", + }) + .locator("div") + .first() + ).toBeVisible(); + }); + }); + + test("should update a role ", async ({ page }) => { + await test.step("access main view", async () => { + await page.goto("/role-management/roles"); + }); + + await test.step("update role", async () => { + await page + .getByRole("row", { name: "test role Infrahub Users" }) + .getByTestId("actions-row-button") + .click(); + await page.getByTestId("update-row-button").click(); + await page.getByLabel("Name *").click(); + await page.getByLabel("Name *").fill("test role update"); + await page.getByLabel("Groups").click(); + await page.getByLabel("", { exact: true }).getByText("Infrahub Users").click(); + await page.getByTestId("side-panel-container").getByText("Super Administrators").click(); + await page.getByLabel("Groups").click(); + await page.getByTestId("side-panel-container").getByLabel("Permissions").click(); + await page + .getByTestId("side-panel-container") + .getByText("global:manage_schema:allow_all") + .click(); + await page.getByLabel("", { exact: true }).getByText("global:super_admin:allow_all").click(); + await page.getByTestId("side-panel-container").getByLabel("Permissions").click(); + await page.getByRole("button", { name: "Update" }).click(); + await expect(page.getByText("Role updated!")).toBeVisible(); + }); + + await test.step("verify role update", async () => { + await expect(page.getByText("test role update")).toBeVisible(); + await expect(page.getByText("Super Administrators").nth(1)).toBeVisible(); + await expect( + page.getByRole("cell", { + name: "global:manage_repositories:allow_all global:manage_schema:allow_all", + exact: true, + }) + ).toBeVisible(); + }); + }); + + test("should delete a role ", async ({ page }) => { + await test.step("access main view", async () => { + await page.goto("/role-management/roles"); + }); + + await test.step("delete role", async () => { + await page + .getByRole("row", { name: "test role update Super" }) + .getByTestId("actions-row-button") + .click(); + await page.getByTestId("delete-row-button").click(); + await page.getByTestId("modal-delete-confirm").click(); + await expect(page.getByText("Object test role update")).toBeVisible(); + }); + + await test.step("verify role delete", async () => { + await expect(page.getByText("test role update")).not.toBeVisible(); + }); + }); +}); From 455c48237bd291d3e2a8d6d2feee2aa531d603ef Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 15:37:52 +0100 Subject: [PATCH 04/11] update test --- .../app/tests/e2e/role-management/roles-crud.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts index ba5ec6818a..c09a2e2351 100644 --- a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts +++ b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts @@ -56,7 +56,7 @@ test.describe("Role management - Roles CRUD", () => { .click(); await page.getByTestId("update-row-button").click(); await page.getByLabel("Name *").click(); - await page.getByLabel("Name *").fill("test role update"); + await page.getByLabel("Name *").fill("test role 2"); await page.getByLabel("Groups").click(); await page.getByLabel("", { exact: true }).getByText("Infrahub Users").click(); await page.getByTestId("side-panel-container").getByText("Super Administrators").click(); @@ -73,7 +73,7 @@ test.describe("Role management - Roles CRUD", () => { }); await test.step("verify role update", async () => { - await expect(page.getByText("test role update")).toBeVisible(); + await expect(page.getByText("test role 2")).toBeVisible(); await expect(page.getByText("Super Administrators").nth(1)).toBeVisible(); await expect( page.getByRole("cell", { @@ -91,16 +91,16 @@ test.describe("Role management - Roles CRUD", () => { await test.step("delete role", async () => { await page - .getByRole("row", { name: "test role update Super" }) + .getByRole("row", { name: "test role 2" }) .getByTestId("actions-row-button") .click(); await page.getByTestId("delete-row-button").click(); await page.getByTestId("modal-delete-confirm").click(); - await expect(page.getByText("Object test role update")).toBeVisible(); + await expect(page.getByText("Object test role 2 deleted")).toBeVisible(); }); await test.step("verify role delete", async () => { - await expect(page.getByText("test role update")).not.toBeVisible(); + await expect(page.getByText("test role 2")).not.toBeVisible(); }); }); }); From 52bef6fb7bcc61d2b809eb57af08ba6ed7ebfbd6 Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 15:38:07 +0100 Subject: [PATCH 05/11] fix modal delete --- frontend/app/src/components/modals/modal-delete-object.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/app/src/components/modals/modal-delete-object.tsx b/frontend/app/src/components/modals/modal-delete-object.tsx index 2d91edeb4d..64ad1a9e9b 100644 --- a/frontend/app/src/components/modals/modal-delete-object.tsx +++ b/frontend/app/src/components/modals/modal-delete-object.tsx @@ -27,7 +27,11 @@ export default function ModalDeleteObject({ label, rowToDelete, open, close, onD const date = useAtomValue(datetimeAtom); const { objectKind } = useParams(); - const objectDisplay = rowToDelete?.display_label || rowToDelete?.name?.value || rowToDelete?.name; + const objectDisplay = + rowToDelete?.display_label || + rowToDelete?.display_label?.value || + rowToDelete?.name?.value || + rowToDelete?.name; const handleDeleteObject = async () => { if (!rowToDelete?.id) { From f77b1971df56aa6d5dc97269d6676bdde5d6eb8f Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 15:41:48 +0100 Subject: [PATCH 06/11] fix modal delete --- frontend/app/src/components/modals/modal-delete-object.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/src/components/modals/modal-delete-object.tsx b/frontend/app/src/components/modals/modal-delete-object.tsx index 64ad1a9e9b..cc86c326bd 100644 --- a/frontend/app/src/components/modals/modal-delete-object.tsx +++ b/frontend/app/src/components/modals/modal-delete-object.tsx @@ -28,8 +28,8 @@ export default function ModalDeleteObject({ label, rowToDelete, open, close, onD const { objectKind } = useParams(); const objectDisplay = - rowToDelete?.display_label || rowToDelete?.display_label?.value || + rowToDelete?.display_label || rowToDelete?.name?.value || rowToDelete?.name; From 1ed97676a3987d00c0a54adce5eb09674b6ff44c Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 15:46:47 +0100 Subject: [PATCH 07/11] fix global permission delete modal --- frontend/app/src/screens/role-management/global-permissions.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/src/screens/role-management/global-permissions.tsx b/frontend/app/src/screens/role-management/global-permissions.tsx index 6bb2141050..8e050352ca 100644 --- a/frontend/app/src/screens/role-management/global-permissions.tsx +++ b/frontend/app/src/screens/role-management/global-permissions.tsx @@ -94,6 +94,7 @@ function GlobalPermissions() { value: { edges: edge?.node?.roles?.edges }, }, identifier: { display: }, + __typename: edge.node.__typename, }, }; }); From 668ba88c92d1e8f872d7b9fcdfa0a8ddd5df8ac6 Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 16:04:46 +0100 Subject: [PATCH 08/11] fix test --- frontend/app/tests/e2e/role-management/roles-crud.spec.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts index c09a2e2351..edd3aedfe1 100644 --- a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts +++ b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts @@ -21,6 +21,7 @@ test.describe("Role management - Roles CRUD", () => { await page .getByTestId("side-panel-container") .getByText("global:super_admin:allow_all") + .first() .click(); await page .getByTestId("side-panel-container") @@ -66,7 +67,6 @@ test.describe("Role management - Roles CRUD", () => { .getByTestId("side-panel-container") .getByText("global:manage_schema:allow_all") .click(); - await page.getByLabel("", { exact: true }).getByText("global:super_admin:allow_all").click(); await page.getByTestId("side-panel-container").getByLabel("Permissions").click(); await page.getByRole("button", { name: "Update" }).click(); await expect(page.getByText("Role updated!")).toBeVisible(); @@ -75,12 +75,6 @@ test.describe("Role management - Roles CRUD", () => { await test.step("verify role update", async () => { await expect(page.getByText("test role 2")).toBeVisible(); await expect(page.getByText("Super Administrators").nth(1)).toBeVisible(); - await expect( - page.getByRole("cell", { - name: "global:manage_repositories:allow_all global:manage_schema:allow_all", - exact: true, - }) - ).toBeVisible(); }); }); From d75abd1d7d7c939fea2efefb357c7aa6aaa3ea1a Mon Sep 17 00:00:00 2001 From: pa-lem Date: Tue, 19 Nov 2024 16:18:49 +0100 Subject: [PATCH 09/11] fix update global permission --- frontend/app/src/screens/role-management/global-permissions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/src/screens/role-management/global-permissions.tsx b/frontend/app/src/screens/role-management/global-permissions.tsx index 8e050352ca..3574085d85 100644 --- a/frontend/app/src/screens/role-management/global-permissions.tsx +++ b/frontend/app/src/screens/role-management/global-permissions.tsx @@ -76,7 +76,7 @@ function GlobalPermissions() { data[GLOBAL_PERMISSION_OBJECT]?.edges.map((edge) => { return { values: { - id: { value: edge?.node?.id }, + id: edge?.node?.id, display_label: { value: edge?.node?.display_label }, action: { value: edge?.node?.action?.value }, decision: { From 0de73ba73ee0669c4c5d0619214a6c132b52d1e1 Mon Sep 17 00:00:00 2001 From: pa-lem Date: Wed, 20 Nov 2024 17:01:56 +0100 Subject: [PATCH 10/11] update test --- frontend/app/tests/e2e/role-management/roles-crud.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts index edd3aedfe1..8eaaa9cb76 100644 --- a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts +++ b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts @@ -90,6 +90,7 @@ test.describe("Role management - Roles CRUD", () => { .click(); await page.getByTestId("delete-row-button").click(); await page.getByTestId("modal-delete-confirm").click(); + await expect(page.getByText("Are you sure you want to remove")).not.toBeVisible(); await expect(page.getByText("Object test role 2 deleted")).toBeVisible(); }); From e356c62044e8b2bcb599555d6e59a75c7bd91937 Mon Sep 17 00:00:00 2001 From: pa-lem Date: Thu, 21 Nov 2024 09:17:12 +0100 Subject: [PATCH 11/11] add test id in loader + update test --- frontend/app/src/components/ui/search-input.tsx | 7 ++++++- frontend/app/tests/e2e/role-management/roles-crud.spec.ts | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/app/src/components/ui/search-input.tsx b/frontend/app/src/components/ui/search-input.tsx index f79f2a08a9..c19145a42d 100644 --- a/frontend/app/src/components/ui/search-input.tsx +++ b/frontend/app/src/components/ui/search-input.tsx @@ -20,7 +20,12 @@ export const SearchInput = forwardRef( - {loading && } + {loading && ( + + )} ); } diff --git a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts index 8eaaa9cb76..2b7feffbd0 100644 --- a/frontend/app/tests/e2e/role-management/roles-crud.spec.ts +++ b/frontend/app/tests/e2e/role-management/roles-crud.spec.ts @@ -11,6 +11,7 @@ test.describe("Role management - Roles CRUD", () => { }); await test.step("create role", async () => { + await expect(page.getByText("Retrieving roles...")).not.toBeVisible(); await page.getByRole("button", { name: "Create Account role" }).click(); await page.getByLabel("Name *").click(); await page.getByLabel("Name *").fill("test role"); @@ -95,6 +96,7 @@ test.describe("Role management - Roles CRUD", () => { }); await test.step("verify role delete", async () => { + await expect(page.getByTestId("objects-search-input-loader")).not.toBeVisible(); await expect(page.getByText("test role 2")).not.toBeVisible(); }); });