From 70e097bd46011aef4eed19e7b4b9334569701eeb Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Mon, 3 Jun 2024 13:35:43 -0700 Subject: [PATCH 1/5] feat(FSADT1-1346): add create client button to staff dashboard (#984) * feat(FSADT1-1346): add create client to staff dashboard * chore: updating project files * feat(FSADT1-1346): soft-locking feature behind a feature flag * fix(FSADT1-1346): fixing tests with feature flag * chore: removing log * chore: renaming variables * chore: removing v-shadow * chore: renaming variables --- frontend/.devcontainer/devcontainer.json | 1 - frontend/.vscode/extensions.json | 3 +- frontend/cypress/e2e/FormStaffPage.cy.ts | 102 +++++++++++ frontend/package.json | 2 +- .../src/components/MainHeaderComponent.vue | 15 +- .../src/helpers/ForestClientUserSession.ts | 4 + frontend/src/pages/FormStaffPage.vue | 168 ++++++++++++++++++ frontend/src/routes.ts | 37 +++- 8 files changed, 324 insertions(+), 8 deletions(-) create mode 100644 frontend/cypress/e2e/FormStaffPage.cy.ts create mode 100644 frontend/src/pages/FormStaffPage.vue diff --git a/frontend/.devcontainer/devcontainer.json b/frontend/.devcontainer/devcontainer.json index 3193200c50..85b855aaff 100644 --- a/frontend/.devcontainer/devcontainer.json +++ b/frontend/.devcontainer/devcontainer.json @@ -19,7 +19,6 @@ "Vue.vscode-typescript-vue-plugin", "ms-vscode.vscode-typescript-next", "antfu.vite", - "ZixuanChen.vitest-explorer", "esbenp.prettier-vscode", "rvest.vs-code-prettier-eslint", "wayou.vscode-todo-highlight", diff --git a/frontend/.vscode/extensions.json b/frontend/.vscode/extensions.json index f81959f3b5..01e0ed9567 100644 --- a/frontend/.vscode/extensions.json +++ b/frontend/.vscode/extensions.json @@ -3,7 +3,6 @@ "vue.volar", "ms-vscode.vscode-typescript-next", "antfu.vite", - "zixuanchen.vitest-explorer", "esbenp.prettier-vscode", "rvest.vs-code-prettier-eslint", "wayou.vscode-todo-highlight", @@ -19,4 +18,4 @@ "redhat.vscode-xml", "sonarsource.sonarlint-vscode" ] -} +} \ No newline at end of file diff --git a/frontend/cypress/e2e/FormStaffPage.cy.ts b/frontend/cypress/e2e/FormStaffPage.cy.ts new file mode 100644 index 0000000000..c526338c39 --- /dev/null +++ b/frontend/cypress/e2e/FormStaffPage.cy.ts @@ -0,0 +1,102 @@ +import type { StaticResponse } from "../../node_modules/cypress/types/net-stubbing"; + +/* eslint-disable no-undef */ +describe("Staff Form", () => { + + beforeEach(() => { + + cy.visit("/"); + cy.wait(500); + cy.get("#landing-title").should("contain", "Forests Client Management System"); + cy.get("#landing-subtitle").should( + "contain", + "Create and manage client accounts" + ); + + cy.viewport(1920, 1080); + }); + + it("CLIENT_EDITOR should be able to see the button", () => { + + cy.login("uattest@gov.bc.ca", "Uat Test", "idir", { + given_name: "James", + family_name: "Baxter", + "cognito:groups": ["CLIENT_EDITOR"], + }); + + // Check if the Create client button is visible + cy.get('#menu-list-staff-form') + .should('be.visible') + .find('span') + .should('contain', 'Create client'); + + }); + + it("CLIENT_ADMIN should be able to see the button", () => { + + cy.login("uattest@gov.bc.ca", "Uat Test", "idir", { + given_name: "James", + family_name: "Baxter", + "cognito:groups": ["CLIENT_ADMIN"], + }); + + // Check if the Create client button is visible + cy.get('#menu-list-staff-form') + .should('be.visible') + .find('span') + .should('contain', 'Create client'); + + }); + + it("CLIENT_VIEWER should not be able to see the button", () => { + + cy.login("uattest@gov.bc.ca", "Uat Test", "idir", { + given_name: "James", + family_name: "Baxter", + "cognito:groups": ["CLIENT_VIEWER"], + }); + + // Check if the Create client button is not visible and cannot be found + cy.get('#menu-list-staff-form').should('not.exist'); + + }); + + it("CLIENT_EDITOR should be able to click the button", () => { + + cy.login("uattest@gov.bc.ca", "Uat Test", "idir", { + given_name: "James", + family_name: "Baxter", + "cognito:groups": ["CLIENT_EDITOR"], + }); + + // Check if the Create client button is visible + cy.get('#menu-list-staff-form') + .should('be.visible') + .click(); + + cy.get('h1') + .should('be.visible') + .should('contain', ' Create client '); + + }); + + it("CLIENT_ADMIN should be able to click the button", () => { + + cy.login("uattest@gov.bc.ca", "Uat Test", "idir", { + given_name: "James", + family_name: "Baxter", + "cognito:groups": ["CLIENT_ADMIN"], + }); + + // Check if the Create client button is visible + cy.get('#menu-list-staff-form') + .should('be.visible') + .click(); + + cy.get('h1') + .should('be.visible') + .should('contain', ' Create client '); + + }); + +}); diff --git a/frontend/package.json b/frontend/package.json index 487723dbc8..35b6f2a901 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "scripts": { "start": "vite --host --port 3000", "build": "vue-tsc --noEmit && vite build", - "preview": "cross-env VITE_NODE_ENV=test start-server-and-test stub http://127.0.0.1:8080 start", + "preview": "cross-env VITE_NODE_ENV=test VITE_FEATURE_FLAGS={\\\"STAFF_CREATE\\\":true} start-server-and-test stub http://127.0.0.1:8080 start", "preview:app": "cross-env VITE_NODE_ENV=test vite --host --port 3000", "typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", "lint": "eslint . --fix --ignore-path .gitignore", diff --git a/frontend/src/components/MainHeaderComponent.vue b/frontend/src/components/MainHeaderComponent.vue index aacb4abd72..0372a14608 100644 --- a/frontend/src/components/MainHeaderComponent.vue +++ b/frontend/src/components/MainHeaderComponent.vue @@ -12,7 +12,8 @@ import type CDSHeaderGlobalAction from "@carbon/web-components/es/components/ui- import { isSmallScreen, isMediumScreen } from "@/composables/useScreenSize"; import { useRoute } from "vue-router"; // Types -import { nodeEnv, appVersion } from "@/CoreConstants"; +import { nodeEnv, appVersion, featureFlags } from "@/CoreConstants"; +import ForestClientUserSession from "@/helpers/ForestClientUserSession"; // Routes import { CONFIRMATION_ROUTE_NAME } from "@/routes"; // @ts-ignore @@ -31,6 +32,8 @@ import Result16 from "@carbon/icons-vue/es/result/16"; import SignOut16 from "@carbon/icons-vue/es/user--follow/16"; // @ts-ignore import Close16 from "@carbon/icons-vue/es/close/16"; +// @ts-ignore +import TaskAdd16 from "@carbon/icons-vue/es/task--add/16"; const envPrefix = "openshift-"; const env = ref(nodeEnv); @@ -105,6 +108,8 @@ const headerBarButtonsSize = computed(() => const logoutBtnKind = computed(() => isSmallScreen.value || isMediumScreen.value ? "ghost" : "tertiary", ); + +const userHasAuthority = ["CLIENT_EDITOR", "CLIENT_ADMIN"].some(authority => ForestClientUserSession.authorities.includes(authority)) && featureFlags.STAFF_CREATE;