From 91c9349205324af36106749fe6d60042dbceb8f0 Mon Sep 17 00:00:00 2001 From: Diana Barsan <35681649+dianabarsan@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:25:11 +0200 Subject: [PATCH] fix(#8730): fix permission checks for contact fab and actionbar (#8738) Adds separate checks for con_create_people on contact page actionbar and FAB. #8730 --- .../contacts/fab-actionbar.wdio-spec.js | 86 +++++++++++++++++++ .../default/common/common.wdio.page.js | 28 ++++++ .../actionbar/actionbar.component.html | 8 +- .../ts/services/fast-action-button.service.ts | 11 ++- .../fast-action-button.service.spec.ts | 34 ++++++-- 5 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 tests/e2e/default/contacts/fab-actionbar.wdio-spec.js diff --git a/tests/e2e/default/contacts/fab-actionbar.wdio-spec.js b/tests/e2e/default/contacts/fab-actionbar.wdio-spec.js new file mode 100644 index 00000000000..c44ceb984fb --- /dev/null +++ b/tests/e2e/default/contacts/fab-actionbar.wdio-spec.js @@ -0,0 +1,86 @@ +const placeFactory = require('@factories/cht/contacts/place'); +const userFactory = require('@factories/cht/users/users'); +const personFactory = require('@factories/cht/contacts/person'); +const utils = require('@utils'); +const loginPage = require('@page-objects/default/login/login.wdio.page'); +const commonElements = require('@page-objects/default/common/common.wdio.page'); +const { genericForm } = require('@page-objects/default/contacts/contacts.wdio.page'); + +const places = placeFactory.generateHierarchy(); +const healthCenter = places.get('health_center'); +const onlineUser = userFactory.build({ place: healthCenter._id, roles: [ 'program_officer' ] }); +const patient = personFactory.build({ parent: { _id: healthCenter._id, parent: healthCenter.parent } }); +describe('FAB + Actionbar', () => { + before(async () => { + await utils.saveDocs([ ...places.values(), patient ]); + await utils.createUsers([ onlineUser ]); + await loginPage.login(onlineUser); + }); + + afterEach(async () => { + await utils.revertSettings(false); + }); + + describe('FAB', () => { + it('should show new household and new person create option', async () => { + await commonElements.goToPeople(healthCenter._id); + const fabLabels = await commonElements.getFastActionItemsLabels(); + + expect(fabLabels).to.have.members(['New household', 'New person']); + }); + + it('should show fab when user only has can_create_places permission', async () => { + await utils.updatePermissions(onlineUser.roles, [], ['can_create_people']); + await commonElements.goToPeople(healthCenter._id); + + await commonElements.clickFastActionFAB({ waitForList: false }); + const formTitle = await genericForm.getFormTitle(); + expect(formTitle).to.equal('New household'); + }); + + it('should show fab when user only has can_create_people permission', async () => { + await utils.updatePermissions(onlineUser.roles, [], ['can_create_places']); + await commonElements.goToPeople(healthCenter._id); + + await commonElements.clickFastActionFAB({ waitForList: false }); + const formTitle = await genericForm.getFormTitle(); + expect(formTitle).to.equal('New person'); + }); + }); + + describe('Action bar', () => { + it('should show new household and new person create option', async () => { + await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar']); + await commonElements.goToPeople(healthCenter._id); + const actionBarLabels = await commonElements.getActionBarLabels(); + + expect(actionBarLabels).to.have.members([ + 'New household', + 'New person', + 'New action', + ]); + }); + + it('should not show new person when missing permission', async () => { + await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar'], ['can_create_people']); + await commonElements.goToPeople(healthCenter._id); + const actionBarLabels = await commonElements.getActionBarLabels(); + + expect(actionBarLabels).to.have.members([ + 'New household', + 'New action', + ]); + }); + + it('should not show new place when missing permission', async () => { + await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar'], ['can_create_places']); + await commonElements.goToPeople(healthCenter._id); + const actionBarLabels = await commonElements.getActionBarLabels(); + + expect(actionBarLabels).to.have.members([ + 'New person', + 'New action', + ]); + }); + }); +}); diff --git a/tests/page-objects/default/common/common.wdio.page.js b/tests/page-objects/default/common/common.wdio.page.js index 86646477066..d48f0aa6fda 100644 --- a/tests/page-objects/default/common/common.wdio.page.js +++ b/tests/page-objects/default/common/common.wdio.page.js @@ -12,6 +12,7 @@ const FAST_ACTION_LIST_CONTAINER = '.fast-action-content-wrapper'; const fastActionListContainer = () => $(FAST_ACTION_LIST_CONTAINER); const fastActionListCloseButton = () => $(`${FAST_ACTION_LIST_CONTAINER} .panel-header .panel-header-close`); const fastActionById = (id) => $(`${FAST_ACTION_LIST_CONTAINER} .fast-action-item[test-id="${id}"]`); +const fastActionItems = () => $$(`${FAST_ACTION_LIST_CONTAINER} .fast-action-item`); const moreOptionsMenu = () => $('.more-options-menu-container>.mat-mdc-menu-trigger'); const hamburgerMenuItemSelector = '#header-dropdown li'; const logoutButton = () => $(`${hamburgerMenuItemSelector} .fa-power-off`); @@ -28,6 +29,9 @@ const syncSuccess = () => $(`${hamburgerMenuItemSelector}.sync-status .success`) const syncRequired = () => $(`${hamburgerMenuItemSelector}.sync-status .required`); const jsonError = async () => (await $('pre')).getText(); +const actionBar = () => $('.detail-actions.right-pane'); +const actionBarActions = () => $$('.detail-actions.right-pane span'); + //languages const activeSnackbar = () => $('#snackbar.active'); const inactiveSnackbar = () => $('#snackbar:not(.active)'); @@ -82,6 +86,20 @@ const clickFastActionFAB = async ({ actionId, waitForList }) => { } }; +const getFastActionItemsLabels = async () => { + await closeHamburgerMenu(); + await (await fastActionFAB()).waitForDisplayed(); + await (await fastActionFAB()).waitForClickable(); + await (await fastActionFAB()).click(); + + await browser.pause(500); + await (await fastActionListContainer()).waitForDisplayed(); + + const items = await fastActionItems(); + const fastActionItemLabels = await Promise.all(items.map(item => item.getText())); + return fastActionItemLabels; +}; + const clickFastActionFlat = async ({ actionId, waitForList }) => { await (await fastActionFlat()).waitForDisplayed(); await (await fastActionFlat()).waitForClickable(); @@ -406,6 +424,14 @@ const loadNextInfiniteScrollPage = async () => { await waitForLoaderToDisappear(await $('.left-pane')); }; +const getActionBarLabels = async () => { + await (await actionBar()).waitForDisplayed(); + await (await actionBarActions())[0].waitForDisplayed(); + const items = await actionBarActions(); + const labels = await Promise.all(items.map(item => item.getText())); + return labels.filter(label => !!label); +}; + module.exports = { openMoreOptionsMenu, closeFastActionList, @@ -466,4 +492,6 @@ module.exports = { getAllButtonLabelsNames, loadNextInfiniteScrollPage, goToUrl, + getFastActionItemsLabels, + getActionBarLabels, }; diff --git a/webapp/src/ts/components/actionbar/actionbar.component.html b/webapp/src/ts/components/actionbar/actionbar.component.html index 9a5659ee81f..dc7c5723b3e 100644 --- a/webapp/src/ts/components/actionbar/actionbar.component.html +++ b/webapp/src/ts/components/actionbar/actionbar.component.html @@ -38,10 +38,10 @@
-
+
@@ -51,7 +51,7 @@