Saleor 3479 tests for permissions groups (#1135)
* test for permission groups * test for permission groups * test for permission groups * test for permission groups * all tests for permission groups * all tests for permission groups
This commit is contained in:
parent
50764b5932
commit
dd4519a044
13 changed files with 294 additions and 3 deletions
71
cypress/apiRequests/PermissionGroup.js
Normal file
71
cypress/apiRequests/PermissionGroup.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
import { getValueWithDefault } from "./utils/Utils";
|
||||
|
||||
export function getPermissionGroups(first, startsWith) {
|
||||
const query = `query{
|
||||
permissionGroups(first:${first} filter:{
|
||||
search:"${startsWith}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(query)
|
||||
.then(resp => resp.body.data.permissionGroups.edges);
|
||||
}
|
||||
|
||||
export function deletePermissionGroup(permissionGroupId) {
|
||||
const mutation = `mutation{
|
||||
permissionGroupDelete(id:"${permissionGroupId}"){
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(mutation);
|
||||
}
|
||||
|
||||
export function createPermissionGroup({
|
||||
name,
|
||||
userIdsArray,
|
||||
permissionsArray
|
||||
}) {
|
||||
const users = getValueWithDefault(userIdsArray, `addUsers:${userIdsArray}`);
|
||||
const mutation = `mutation{
|
||||
permissionGroupCreate(input:{
|
||||
name:"${name}"
|
||||
addPermissions:${permissionsArray}
|
||||
${users}
|
||||
}){
|
||||
errors{
|
||||
field
|
||||
message
|
||||
}
|
||||
group{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy
|
||||
.sendRequestWithQuery(mutation)
|
||||
.its("body.data.permissionGroupCreate");
|
||||
}
|
||||
|
||||
export function getPermissionGroup(permissionGroupId) {
|
||||
const query = `query{
|
||||
permissionGroup(id:"${permissionGroupId}"){
|
||||
id
|
||||
name
|
||||
users{
|
||||
email
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query).its("body.data.permissionGroup");
|
||||
}
|
15
cypress/apiRequests/StaffMembers.js
Normal file
15
cypress/apiRequests/StaffMembers.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
export function getStaffMembersStartsWith(startsWith) {
|
||||
const query = `query{
|
||||
staffUsers(first:100 filter:{
|
||||
search:"${startsWith}"
|
||||
}){
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
return cy.sendRequestWithQuery(query);
|
||||
}
|
10
cypress/elements/permissionGroup/permissionGroupDetails.js
Normal file
10
cypress/elements/permissionGroup/permissionGroupDetails.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
export const PERMISSION_GROUP_DETAILS = {
|
||||
nameInput: '[name="name"]',
|
||||
productsPermissionCheckbox: '[id="MANAGE_PRODUCTS"]',
|
||||
productsTypesAndAttributesPermissionCheckbox:
|
||||
'[id="MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES"]',
|
||||
assignMemberButton: '[data-test-id="assign-members"]',
|
||||
searchField: '[name="query"]',
|
||||
removeUserButton: '[data-test-id="removeUser"]',
|
||||
userRow: '[data-test-id="userRow"]'
|
||||
};
|
4
cypress/elements/permissionGroup/permissionGroupsList.js
Normal file
4
cypress/elements/permissionGroup/permissionGroupsList.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const PERMISSION_GROUP_LIST = {
|
||||
createPermissionButton: '[data-test-id="createPermissionGroup"]',
|
||||
permissionGroupRow: '[data-test="id"]'
|
||||
};
|
|
@ -9,5 +9,6 @@ export const BUTTON_SELECTORS = {
|
|||
notSelectedOption: ":not([aria-selected])",
|
||||
deleteButton: '[data-test="button-bar-delete"]',
|
||||
expandIcon: '[data-test-id="expand-icon"]',
|
||||
deleteIcon: '[data-test-id="deleteIcon"]',
|
||||
showMoreButton: '[data-test-id="showMoreButton"]'
|
||||
};
|
||||
|
|
145
cypress/integration/allEnv/configuration/permissions.js
Normal file
145
cypress/integration/allEnv/configuration/permissions.js
Normal file
|
@ -0,0 +1,145 @@
|
|||
import faker from "faker";
|
||||
|
||||
import {
|
||||
createPermissionGroup,
|
||||
getPermissionGroup
|
||||
} from "../../../apiRequests/PermissionGroup.js";
|
||||
import { getStaffMembersStartsWith } from "../../../apiRequests/StaffMembers";
|
||||
import { USER_WITHOUT_NAME } from "../../../Data/users";
|
||||
import { PERMISSION_GROUP_DETAILS } from "../../../elements/permissionGroup/permissionGroupDetails";
|
||||
import { PERMISSION_GROUP_LIST } from "../../../elements/permissionGroup/permissionGroupsList";
|
||||
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
||||
import {
|
||||
permissionGroupDetails,
|
||||
staffMemberDetailsUrl,
|
||||
urlList
|
||||
} from "../../../url/urlList";
|
||||
import { deletePermissionGroupsStartsWith } from "../../../utils/permissionGroupUtils.js";
|
||||
|
||||
describe("Permissions groups", () => {
|
||||
const startsWith = "CyPermissions-";
|
||||
|
||||
before(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
deletePermissionGroupsStartsWith(startsWith);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearSessionData().loginUserViaRequest();
|
||||
});
|
||||
|
||||
it("should create permission group", () => {
|
||||
const permissionName = `${startsWith}${faker.datatype.number()}`;
|
||||
|
||||
cy.visit(urlList.permissionsGroups)
|
||||
.get(PERMISSION_GROUP_LIST.createPermissionButton)
|
||||
.click()
|
||||
.get(PERMISSION_GROUP_DETAILS.nameInput)
|
||||
.type(permissionName)
|
||||
.get(PERMISSION_GROUP_DETAILS.productsPermissionCheckbox)
|
||||
.click()
|
||||
.get(
|
||||
PERMISSION_GROUP_DETAILS.productsTypesAndAttributesPermissionCheckbox
|
||||
)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.get(PERMISSION_GROUP_DETAILS.assignMemberButton)
|
||||
.should("be.visible")
|
||||
.get(BUTTON_SELECTORS.back)
|
||||
.click()
|
||||
.get(SHARED_ELEMENTS.progressBar)
|
||||
.should("not.exist");
|
||||
cy.contains(
|
||||
PERMISSION_GROUP_LIST.permissionGroupRow,
|
||||
permissionName
|
||||
).should("be.visible");
|
||||
});
|
||||
|
||||
it("should delete permission group", () => {
|
||||
const permissionName = `${startsWith}${faker.datatype.number()}`;
|
||||
let staffMember;
|
||||
getStaffMembersStartsWith(USER_WITHOUT_NAME.email)
|
||||
.its("body.data.staffUsers.edges")
|
||||
.then(staffMemberResp => {
|
||||
staffMember = staffMemberResp[0].node;
|
||||
createPermissionGroup({
|
||||
name: permissionName,
|
||||
userIdsArray: `["${staffMember.id}"]`,
|
||||
permissionsArray: "[MANAGE_PRODUCTS]"
|
||||
});
|
||||
cy.visit(urlList.permissionsGroups);
|
||||
cy.contains(PERMISSION_GROUP_LIST.permissionGroupRow, permissionName)
|
||||
.should("be.visible")
|
||||
.find(BUTTON_SELECTORS.deleteIcon)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click();
|
||||
cy.contains(PERMISSION_GROUP_LIST.permissionGroupRow, permissionName)
|
||||
.should("not.exist")
|
||||
.visit(staffMemberDetailsUrl(staffMember.id));
|
||||
cy.get(SHARED_ELEMENTS.header).should("be.visible");
|
||||
cy.contains(permissionName).should("not.exist");
|
||||
});
|
||||
});
|
||||
|
||||
it("should add user to permission group", () => {
|
||||
const permissionName = `${startsWith}${faker.datatype.number()}`;
|
||||
createPermissionGroup({
|
||||
name: permissionName,
|
||||
permissionsArray: "[MANAGE_PRODUCTS]"
|
||||
})
|
||||
.then(({ group }) => {
|
||||
cy.visit(permissionGroupDetails(group.id))
|
||||
.get(PERMISSION_GROUP_DETAILS.assignMemberButton)
|
||||
.click()
|
||||
.get(PERMISSION_GROUP_DETAILS.searchField)
|
||||
.type(USER_WITHOUT_NAME.email)
|
||||
.get(PERMISSION_GROUP_DETAILS.userRow)
|
||||
.should("have.length", 1)
|
||||
.find(BUTTON_SELECTORS.checkbox)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.addAliasToGraphRequest("PermissionGroupUpdate")
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@PermissionGroupUpdate");
|
||||
getPermissionGroup(group.id);
|
||||
})
|
||||
.then(resp => {
|
||||
expect(resp.users).to.have.length(1);
|
||||
expect(resp.users[0].email).to.be.eq(USER_WITHOUT_NAME.email);
|
||||
});
|
||||
});
|
||||
|
||||
it("should remove user from permission group", () => {
|
||||
const permissionName = `${startsWith}${faker.datatype.number()}`;
|
||||
let staffMember;
|
||||
getStaffMembersStartsWith(USER_WITHOUT_NAME.email)
|
||||
.its("body.data.staffUsers.edges")
|
||||
.then(staffMemberResp => {
|
||||
staffMember = staffMemberResp[0].node;
|
||||
createPermissionGroup({
|
||||
name: permissionName,
|
||||
userIdsArray: `["${staffMember.id}"]`,
|
||||
permissionsArray: "[MANAGE_PRODUCTS]"
|
||||
});
|
||||
})
|
||||
.then(({ group }) => {
|
||||
cy.visit(permissionGroupDetails(group.id))
|
||||
.get(PERMISSION_GROUP_DETAILS.removeUserButton)
|
||||
.click()
|
||||
.get(BUTTON_SELECTORS.submit)
|
||||
.click()
|
||||
.addAliasToGraphRequest("PermissionGroupUpdate")
|
||||
.get(BUTTON_SELECTORS.confirm)
|
||||
.click()
|
||||
.wait("@PermissionGroupUpdate");
|
||||
cy.visit(staffMemberDetailsUrl(staffMember.id));
|
||||
cy.get(SHARED_ELEMENTS.header).should("be.visible");
|
||||
cy.contains(permissionName).should("not.exist");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -10,6 +10,12 @@ export const urlList = {
|
|||
shippingMethods: "shipping/",
|
||||
sales: "discounts/sales/",
|
||||
collections: "collections/",
|
||||
vouchers: "discounts/vouchers/"
|
||||
vouchers: "discounts/vouchers/",
|
||||
staffMembers: "staff/",
|
||||
permissionsGroups: "permission-groups/"
|
||||
};
|
||||
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
||||
export const staffMemberDetailsUrl = staffMemberId =>
|
||||
`${urlList.staffMembers}${staffMemberId}`;
|
||||
export const permissionGroupDetails = permissionGroupId =>
|
||||
`${urlList.permissionsGroups}${permissionGroupId}`;
|
||||
|
|
12
cypress/utils/permissionGroupUtils.js
Normal file
12
cypress/utils/permissionGroupUtils.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import {
|
||||
deletePermissionGroup,
|
||||
getPermissionGroups
|
||||
} from "../apiRequests/PermissionGroup";
|
||||
|
||||
export function deletePermissionGroupsStartsWith(startsWith) {
|
||||
cy.deleteElementsStartsWith(
|
||||
deletePermissionGroup,
|
||||
getPermissionGroups,
|
||||
startsWith
|
||||
);
|
||||
}
|
|
@ -205,7 +205,7 @@ const AssignMembersDialog: React.FC<AssignMembersDialogProps> = ({
|
|||
);
|
||||
|
||||
return (
|
||||
<TableRow key={member.id}>
|
||||
<TableRow key={member.id} data-test-id="userRow">
|
||||
<TableCell
|
||||
padding="checkbox"
|
||||
className={classes.checkboxCell}
|
||||
|
@ -286,6 +286,7 @@ const AssignMembersDialog: React.FC<AssignMembersDialogProps> = ({
|
|||
<FormattedMessage {...buttonMessages.back} />
|
||||
</Button>
|
||||
<ConfirmButton
|
||||
data-test="submit"
|
||||
color="primary"
|
||||
variant="contained"
|
||||
type="submit"
|
||||
|
|
|
@ -151,6 +151,7 @@ const PermissionGroupList: React.FC<PermissionGroupListProps> = props => {
|
|||
<>
|
||||
{permissionGroup.userCanManage && (
|
||||
<IconButton
|
||||
data-test-id="deleteIcon"
|
||||
color="primary"
|
||||
onClick={stopPropagation(() =>
|
||||
onDelete(permissionGroup.id)
|
||||
|
|
|
@ -33,7 +33,12 @@ const PermissionGroupListPage: React.FC<PermissionGroupListPageProps> = ({
|
|||
{intl.formatMessage(sectionNames.configuration)}
|
||||
</AppHeader>
|
||||
<PageHeader title={intl.formatMessage(sectionNames.permissionGroups)}>
|
||||
<Button color="primary" variant="contained" onClick={onAdd}>
|
||||
<Button
|
||||
color="primary"
|
||||
variant="contained"
|
||||
onClick={onAdd}
|
||||
data-test-id="createPermissionGroup"
|
||||
>
|
||||
<FormattedMessage
|
||||
defaultMessage="create permission group"
|
||||
description="button"
|
||||
|
|
|
@ -124,6 +124,7 @@ const PermissionGroupMemberList: React.FC<PermissionGroupProps> = props => {
|
|||
})}
|
||||
toolbar={
|
||||
<Button
|
||||
data-test-id="assign-members"
|
||||
color={disabled ? "secondary" : "primary"}
|
||||
onClick={onAssign}
|
||||
disabled={disabled}
|
||||
|
@ -256,6 +257,7 @@ const PermissionGroupMemberList: React.FC<PermissionGroupProps> = props => {
|
|||
{user ? (
|
||||
<>
|
||||
<IconButton
|
||||
data-test-id="removeUser"
|
||||
disabled={disabled}
|
||||
color="primary"
|
||||
onClick={stopPropagation(() =>
|
||||
|
|
|
@ -156810,6 +156810,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details default
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||
data-test-id="assign-members"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -156988,6 +156989,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details default
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="removeUser"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -157076,6 +157078,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details default
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="removeUser"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -157164,6 +157167,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details default
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="removeUser"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -157252,6 +157256,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details default
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="removeUser"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -158170,6 +158175,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details loading
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textSecondary-id MuiButton-disabled-id MuiButtonBase-disabled-id"
|
||||
data-test-id="assign-members"
|
||||
disabled=""
|
||||
tabindex="-1"
|
||||
type="button"
|
||||
|
@ -158353,6 +158359,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details loading
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id"
|
||||
data-test-id="removeUser"
|
||||
disabled=""
|
||||
tabindex="-1"
|
||||
type="button"
|
||||
|
@ -158444,6 +158451,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details loading
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id"
|
||||
data-test-id="removeUser"
|
||||
disabled=""
|
||||
tabindex="-1"
|
||||
type="button"
|
||||
|
@ -158535,6 +158543,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details loading
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id"
|
||||
data-test-id="removeUser"
|
||||
disabled=""
|
||||
tabindex="-1"
|
||||
type="button"
|
||||
|
@ -158626,6 +158635,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details loading
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id"
|
||||
data-test-id="removeUser"
|
||||
disabled=""
|
||||
tabindex="-1"
|
||||
type="button"
|
||||
|
@ -158864,6 +158874,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group Details no memb
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-text-id MuiButton-textPrimary-id"
|
||||
data-test-id="assign-members"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -159700,6 +159711,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List default 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="createPermissionGroup"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -159879,6 +159891,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List default 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="deleteIcon"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -159995,6 +160008,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List default 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="deleteIcon"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -160063,6 +160077,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List default 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="deleteIcon"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -160131,6 +160146,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List default 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiIconButton-root-id MuiIconButton-colorPrimary-id"
|
||||
data-test-id="deleteIcon"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -160203,6 +160219,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List loading 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="createPermissionGroup"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
@ -160422,6 +160439,7 @@ exports[`Storyshots Views / Permission Groups / Permission Group List no data 1`
|
|||
>
|
||||
<button
|
||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||
data-test-id="createPermissionGroup"
|
||||
tabindex="0"
|
||||
type="button"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue