Refactor of tests in navigation.js (#2323)

This commit is contained in:
Ewa Czerniak 2022-09-22 11:37:06 +02:00 committed by GitHub
parent 78ea5fb0f5
commit 2bdd1311de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 84 deletions

View file

@ -50,5 +50,6 @@ Tests will be re-run only when the "run e2e" label is added.
18. [ ] app 18. [ ] app
19. [ ] plugins 19. [ ] plugins
20. [ ] translations 20. [ ] translations
21. [ ] navigation
CONTAINERS=1 CONTAINERS=1

View file

@ -47,44 +47,37 @@ describe("As a staff user I want to navigate through shop using different permis
if (key !== "all") { if (key !== "all") {
it( it(
`should be able to navigate through shop as a staff member using ${key} permission. ${permissionsOptions[key].testCase}`, `should be able to navigate through shop as a staff member using ${key} permission. ${permissionsOptions[key].testCase}`,
{ tags: ["@allEnv", "@navigation"] }, { tags: ["@allEnv", "@navigation", "@stable"] },
() => { () => {
const permissionOption = permissionsOptions[key]; const permissionOption = permissionsOptions[key];
const permissions = permissionOption.permissions; const permissions = permissionOption.permissions;
cy.clearSessionData(); cy.clearSessionData();
permissionsSteps.navigateToAllAvailablePageAndCheckIfDisplayed( permissionsSteps.navigateToAllAvailablePageAndCheckIfDisplayed(
permissionOption, permissionOption,
); );
permissionsSteps permissionsSteps.getDisplayedSelectors().then(selectors => {
.getDisplayedSelectors() permissionsSteps.expectAllSelectorsPermitted(
.then(selectors => { permissions,
permissionsSteps.expectAllSelectorsPermitted( selectors,
permissions, );
selectors, });
); if (!permissions) {
}) return;
.then(() => { }
if (!permissions) { permissions.forEach(permission => {
return; if (permission.parent) {
} cy.get(permission.parent.parentMenuSelector).click();
permissions.forEach(permission => { permissionsSteps
if (permission.parent) { .getDisplayedSelectors(permission.parent.parentSelectors)
cy.get(permission.parent.parentMenuSelector) .then(parentSelectors => {
.click() permissionsSteps.expectAllSelectorsPermitted(
.then(() => { permissions,
permissionsSteps.getDisplayedSelectors( parentSelectors,
permission.parent.parentSelectors, );
); });
}) }
.then(parentSelectors => { });
permissionsSteps.expectAllSelectorsPermitted(
permissions,
parentSelectors,
);
});
}
});
});
}, },
); );
} }
@ -95,6 +88,7 @@ describe("As a staff user I want to navigate through shop using different permis
{ tags: ["@critical", "@allEnv", "@navigation", "@stable"] }, { tags: ["@critical", "@allEnv", "@navigation", "@stable"] },
() => { () => {
const permissionOption = permissionsOptions.all; const permissionOption = permissionsOptions.all;
cy.clearSessionData(); cy.clearSessionData();
permissionsSteps.navigateToAllAvailablePageAndCheckIfDisplayed( permissionsSteps.navigateToAllAvailablePageAndCheckIfDisplayed(
permissionOption, permissionOption,

View file

@ -5,81 +5,80 @@ export const PERMISSIONS_OPTIONS = {
all: { all: {
user: TEST_ADMIN_USER, user: TEST_ADMIN_USER,
permissions: Object.values(PERMISSIONS), permissions: Object.values(PERMISSIONS),
testCase: "TC: SALEOR_3401" testCase: "TC: SALEOR_3401",
}, },
app: { app: {
user: ONE_PERMISSION_USERS.app, user: ONE_PERMISSION_USERS.app,
permissions: [], permissions: [],
testCase: "TC: SALEOR_3402" testCase: "TC: SALEOR_3402",
}, },
channel: { channel: {
user: ONE_PERMISSION_USERS.channel, user: ONE_PERMISSION_USERS.channel,
permissions: [PERMISSIONS.channel], permissions: [PERMISSIONS.channel],
testCase: "TC: SALEOR_3403" testCase: "TC: SALEOR_3403",
}, },
customer: { customer: {
user: ONE_PERMISSION_USERS.user, user: ONE_PERMISSION_USERS.user,
permissions: [PERMISSIONS.customer], permissions: [PERMISSIONS.customer],
testCase: "TC: SALEOR_3404" testCase: "TC: SALEOR_3404",
}, },
discount: { discount: {
user: ONE_PERMISSION_USERS.discount, user: ONE_PERMISSION_USERS.discount,
permissions: [PERMISSIONS.discounts], permissions: [PERMISSIONS.discounts],
testCase: "TC: SALEOR_3405" testCase: "TC: SALEOR_3405",
}, },
giftCard: { giftCard: {
user: ONE_PERMISSION_USERS.giftCard, user: ONE_PERMISSION_USERS.giftCard,
testCase: "TC: SALEOR_3406" testCase: "TC: SALEOR_3406",
}, },
order: { order: {
user: ONE_PERMISSION_USERS.order, user: ONE_PERMISSION_USERS.order,
permissions: [PERMISSIONS.order], permissions: [PERMISSIONS.order],
testCase: "TC: SALEOR_3407" testCase: "TC: SALEOR_3407",
}, },
page: { page: {
user: ONE_PERMISSION_USERS.page, user: ONE_PERMISSION_USERS.page,
permissions: [PERMISSIONS.page], permissions: [PERMISSIONS.page],
testCase: "TC: SALEOR_3408" testCase: "TC: SALEOR_3408",
}, },
plugin: { plugin: {
user: ONE_PERMISSION_USERS.plugin, user: ONE_PERMISSION_USERS.plugin,
permissions: [PERMISSIONS.plugin], permissions: [PERMISSIONS.plugin],
testCase: "TC: SALEOR_3409" testCase: "TC: SALEOR_3409",
}, },
product: { product: {
user: ONE_PERMISSION_USERS.product, user: ONE_PERMISSION_USERS.product,
permissions: [PERMISSIONS.product, PERMISSIONS.warehouse], permissions: [PERMISSIONS.product, PERMISSIONS.warehouse],
testCase: "TC: SALEOR_3410" testCase: "TC: SALEOR_3410",
}, },
productTypeAndAttribute: { productTypeAndAttribute: {
user: ONE_PERMISSION_USERS.productTypeAndAttribute, user: ONE_PERMISSION_USERS.productTypeAndAttribute,
permissions: [PERMISSIONS.productTypeAndAttribute], permissions: [PERMISSIONS.productTypeAndAttribute],
testCase: "TC: SALEOR_3411" testCase: "TC: SALEOR_3411",
}, },
pageTypeAndAttribute: { pageTypeAndAttribute: {
user: ONE_PERMISSION_USERS.pageTypeAndAttribute, user: ONE_PERMISSION_USERS.pageTypeAndAttribute,
permissions: [PERMISSIONS.pageTypeAndAttribute], permissions: [PERMISSIONS.pageTypeAndAttribute],
testCase: "TC: SALEOR_3412" testCase: "TC: SALEOR_3412",
}, },
settings: { settings: {
user: ONE_PERMISSION_USERS.settings, user: ONE_PERMISSION_USERS.settings,
permissions: [PERMISSIONS.settings], permissions: [PERMISSIONS.settings],
testCase: "TC: SALEOR_3413" testCase: "TC: SALEOR_3413",
},
shipping: {
user: ONE_PERMISSION_USERS.shipping,
permissions: [PERMISSIONS.shipping],
testCase: "TC: SALEOR_3415"
}, },
staff: { staff: {
user: ONE_PERMISSION_USERS.staff, user: ONE_PERMISSION_USERS.staff,
permissions: [PERMISSIONS.staff], permissions: [PERMISSIONS.staff],
testCase: "TC: SALEOR_3414" testCase: "TC: SALEOR_3414",
} },
// }, shipping: {
// translations: { user: ONE_PERMISSION_USERS.shipping,
// user: ONE_PERMISSION_USERS.translations, permissions: [PERMISSIONS.shipping],
// permissions: [PERMISSIONS.translations], testCase: "TC: SALEOR_3415",
// testCase: "TC: SALEOR_3416" },
// } // commented as part of SALEOR-6705 task. Need to be fixed in future. Klaudia Jaroszewicz translations: {
user: ONE_PERMISSION_USERS.translations,
permissions: [PERMISSIONS.translations],
testCase: "TC: SALEOR_3416",
},
}; };

View file

@ -4,72 +4,68 @@ import { urlList } from "../../fixtures/urlList";
export function navigateToAllAvailablePageAndCheckIfDisplayed({ export function navigateToAllAvailablePageAndCheckIfDisplayed({
user, user,
permissions permissions,
}) { }) {
cy.loginUserViaRequest("auth", user); cy.loginUserViaRequest("auth", user).visit(urlList.homePage);
cy.visit(urlList.homePage);
if (!permissions) { if (!permissions) {
return; return;
} }
return permissions.forEach(permission => return permissions.forEach(permission =>
permission.permissionSelectors.forEach(permissionSelector => { permission.permissionSelectors.forEach(permissionSelector => {
navigateToAvailablePageAndCheckIfDisplayed( if (permission.parent) {
permission.parent, cy.get(permission.parent.parentMenuSelector).click();
permissionSelector }
); return cy
}) .get(permissionSelector)
.click()
.then(() => {
isElementDisplayed().should("be.true");
});
}),
); );
} }
function navigateToAvailablePageAndCheckIfDisplayed(
parent,
permissionSelector
) {
if (parent) {
cy.get(parent.parentMenuSelector).click();
}
return cy
.get(permissionSelector)
.click()
.then(() => {
isElementDisplayed();
})
.then(isDisplayed => {
expect(isDisplayed).to.be.true;
});
}
export function isElementDisplayed(element = SHARED_ELEMENTS.header) { export function isElementDisplayed(element = SHARED_ELEMENTS.header) {
return cy.get("body").then(body => body.find(element).length > 0); return cy.get("body").then(body => body.find(element).length > 0);
} }
export function getDisplayedSelectors(selectors = LEFT_MENU_SELECTORS) { export function getDisplayedSelectors(selectors = LEFT_MENU_SELECTORS) {
const displayedSelectors = {}; const displayedSelectors = {};
cy.wrap(displayedSelectors).as("displayedSelectors"); cy.wrap(displayedSelectors).as("displayedSelectors");
Object.values(selectors).forEach((value, i) => Object.values(selectors).forEach((value, i) =>
isElementDisplayed(value).then(isDisplayed => { isElementDisplayed(value).then(isDisplayed => {
if (isDisplayed) { if (isDisplayed) {
cy.wrap(value); cy.wrap(value);
displayedSelectors["link" + i] = value; displayedSelectors["link" + i] = value;
cy.wrap(displayedSelectors).as("displayedSelectors"); cy.wrap(displayedSelectors).as("displayedSelectors");
} }
}) }),
); );
return cy.get("@displayedSelectors"); return cy.get("@displayedSelectors");
} }
export function expectAllSelectorsPermitted(permissions, selectors) { export function expectAllSelectorsPermitted(permissions, selectors) {
Object.values(selectors).forEach(selector => { Object.values(selectors).forEach(selector => {
const isSelectorPermitted = isPermitted(permissions, selector); const isSelectorPermitted = isPermitted(permissions, selector);
expect(isSelectorPermitted, `${selector} selector should be in permitted`) expect(isSelectorPermitted, `${selector} selector should be in permitted`)
.to.be.true; .to.be.true;
}); });
} }
function isPermitted(permissions, selector) { function isPermitted(permissions, selector) {
let permittedSelectors = [LEFT_MENU_SELECTORS.home]; let permittedSelectors = [LEFT_MENU_SELECTORS.home];
permissions.forEach(permission => { permissions.forEach(permission => {
if (permission.parent) { if (permission.parent) {
permittedSelectors.push(permission.parent.parentMenuSelector); permittedSelectors.push(permission.parent.parentMenuSelector);
} }
permittedSelectors = permittedSelectors.concat( permittedSelectors = permittedSelectors.concat(
permission.permissionSelectors permission.permissionSelectors,
); );
}); });
return permittedSelectors.includes(selector); return permittedSelectors.includes(selector);