Tests - fixes pages scenarios (#3857)

* test fixes for pages scenarios

* fixed pages tests - should create published page should keep failing since waits for BE fix
This commit is contained in:
wojteknowacki 2023-07-05 14:23:56 +02:00 committed by GitHub
parent 52bac3b8f5
commit ad341e9954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 144 additions and 77 deletions

View file

@ -3,22 +3,30 @@
import faker from "faker";
import { PAGE_DETAILS_SELECTORS } from "../../elements/pages/page-details";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { pageDetailsUrl } from "../../fixtures/urlList";
import { createAttribute } from "../../support/api/requests/Attribute";
import {
createPage as createPageRequest,
getPage,
} from "../../support/api/requests/Page";
import { createPageType } from "../../support/api/requests/PageType";
import { attributesTypes, createPage } from "../../support/pages/pagesPage";
BUTTON_SELECTORS,
PAGE_DETAILS_SELECTORS,
} from "../../elements";
import {
pageDetailsUrl,
urlList,
} from "../../fixtures/urlList";
import {
attributeRequests,
pageRequests,
pageTypeRequests,
} from "../../support/api/requests";
import {
pageDetailsPage,
pagesPage,
} from "../../support/pages";
describe("Tests for pages", () => {
const startsWith = `Pages`;
const name = `${startsWith}${faker.datatype.number()}`;
let attribute;
let pageType;
let pageTypeId;
const attributeValuesOnPage = {
NUMERIC: 1,
@ -30,10 +38,11 @@ describe("Tests for pages", () => {
before(() => {
cy.clearSessionData().loginUserViaRequest();
createAttribute({ name, type: "PAGE_TYPE" })
attributeRequests
.createAttribute({ name, type: "PAGE_TYPE" })
.then(attributeResp => {
attribute = attributeResp;
createPageType({ name, attributeId: attribute.id });
pageTypeRequests.createPageType({ name, attributeId: attribute.id });
})
.then(({ pageType: pageTypeResp }) => {
pageType = pageTypeResp;
@ -49,18 +58,22 @@ describe("Tests for pages", () => {
"should create not published page",
{ tags: ["@pages", "@allEnv", "@stable"] },
() => {
const randomName = `${startsWith}${faker.datatype.number()}`;
createPage({ pageName: randomName, pageTypeName: name })
.then(page => {
getPage(page.id);
})
.then(page => {
expect(page.title).to.eq(randomName);
cy.addAliasToGraphRequest("PageType");
const pageName = `${startsWith}${faker.datatype.number()}`;
cy.visit(urlList.pages);
pagesPage.openCreatePageDialog();
pagesPage.selectPageTypeOnIndex(0);
cy.clickSubmitButton();
cy.waitForRequestAndCheckIfNoErrors("@PageType");
pageDetailsPage.typePageName(pageName);
cy.get(PAGE_DETAILS_SELECTORS.isNotPublishedCheckbox).click();
pagesPage.savePage().then(page => {
pageRequests.getPage(page.id).then(page => {
expect(page.title).to.eq(pageName);
expect(page.isPublished).to.be.false;
expect(page.attributes[0].attribute.id).to.eq(attribute.id);
getPage(page.id, "token").should("be.null");
pageRequests.getPage(page.id, "token").should("be.null");
});
});
},
);
@ -70,13 +83,14 @@ describe("Tests for pages", () => {
() => {
const randomName = `${startsWith}${faker.datatype.number()}`;
createPage({
pageName: randomName,
pageTypeName: name,
isPublished: true,
})
pagesPage
.createPage({
pageName: randomName,
pageTypeName: name,
isPublished: true,
})
.then(page => {
getPage(page.id, "token");
pageRequests.getPage(page.id, "token");
})
.then(page => {
expect(page.title).to.eq(randomName);
@ -86,42 +100,55 @@ describe("Tests for pages", () => {
},
);
Object.keys(attributesTypes).forEach(attributeType => {
Object.keys(pagesPage.attributesTypes).forEach(attributeType => {
it(
`should create page with ${attributeType} attribute`,
{ tags: ["@pages", "@allEnv", "@stable"] },
() => {
const randomName = `AAA-${startsWith}${faker.datatype.number()}`;
const randomName = `${startsWith}${faker.datatype.number()}`;
const attributeValues = [attributeValuesOnPage[attributeType]];
createAttribute({
name: randomName,
type: "PAGE_TYPE",
inputType: attributeType,
attributeValues,
}).then(attributeResp => {
attribute = attributeResp;
createPageType({ name: randomName, attributeId: attribute.id });
});
createPage({
pageName: randomName,
pageTypeName: randomName,
attributeType,
attributeValue: attributeValuesOnPage[attributeType],
})
.then(page => {
getPage(page.id);
attributeRequests
.createAttribute({
name: randomName,
type: "PAGE_TYPE",
inputType: attributeType,
attributeValues,
})
.then(page => {
expect(page.attributes[0].values[0].inputType).to.eq(attributeType);
if (attributeType !== "BOOLEAN") {
expect(page.attributes[0].values[0].name).to.eq(
attributeValuesOnPage[attributeType].toString(),
);
} else {
expect(page.attributes[0].values[0].name).to.includes(
"Yes".toString(),
);
}
.then(attributeResp => {
attribute = attributeResp;
pageTypeRequests
.createPageType({
name: randomName,
attributeId: attribute.id,
})
.then(createPageResponse => {
pageTypeId = createPageResponse.pageType.id;
cy.visit(`${urlList.addPageType}${pageTypeId}`);
pagesPage
.createPageWithAttribute({
pageName: randomName,
pageTypeName: randomName,
attributeType,
attributeValue: attributeValuesOnPage[attributeType],
})
.then(page => {
pageRequests.getPage(page.id);
})
.then(page => {
expect(page.attributes[0].values[0].inputType).to.eq(
attributeType,
);
if (attributeType !== "BOOLEAN") {
expect(page.attributes[0].values[0].name).to.eq(
attributeValuesOnPage[attributeType].toString(),
);
} else {
expect(page.attributes[0].values[0].name).to.includes(
"Yes".toString(),
);
}
});
});
});
},
);
@ -130,30 +157,33 @@ describe("Tests for pages", () => {
it("should delete page", { tags: ["@pages", "@allEnv", "@stable"] }, () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
createPageRequest({
pageTypeId: pageType.id,
title: randomName,
}).then(({ page }) => {
cy.visit(pageDetailsUrl(page.id))
.get(BUTTON_SELECTORS.deleteButton)
.click()
.addAliasToGraphRequest("PageRemove")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors("@PageRemove");
getPage(page.id).should("be.null");
});
pageRequests
.createPage({
pageTypeId: pageType.id,
title: randomName,
})
.then(({ page }) => {
cy.visit(pageDetailsUrl(page.id))
.get(BUTTON_SELECTORS.deleteButton)
.click()
.addAliasToGraphRequest("PageRemove")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors("@PageRemove");
pageRequests.getPage(page.id).should("be.null");
});
});
it("should update page", { tags: ["@pages", "@allEnv", "@stable"] }, () => {
const randomName = `${startsWith}${faker.datatype.number()}`;
const updatedName = `${startsWith}${faker.datatype.number()}`;
createPageRequest({
pageTypeId: pageType.id,
title: randomName,
isPublished: true,
})
pageRequests
.createPage({
pageTypeId: pageType.id,
title: randomName,
isPublished: true,
})
.then(({ page }) => {
cy.visit(pageDetailsUrl(page.id))
.get(PAGE_DETAILS_SELECTORS.nameInput)
@ -165,7 +195,7 @@ describe("Tests for pages", () => {
.get(BUTTON_SELECTORS.confirm)
.click()
.waitForRequestAndCheckIfNoErrors("@PageUpdate");
getPage(page.id);
pageRequests.getPage(page.id);
})
.then(page => {
expect(page.title).to.eq(updatedName);

View file

@ -1,4 +1,6 @@
export const PAGES_LIST_SELECTORS = {
createPageButton: '[data-test-id="create-page"]',
dialogPageTypeInput: "[data-test-id='dialog-page-type']",
dialogPageTypeInputOptions:
"[data-test-id='single-autocomplete-select-option']",
};

View file

@ -16,6 +16,7 @@ export const urlList = {
navigation: "navigation/",
orders: "orders/",
pages: "pages/",
addPageType: "pages/add?page-type-id=",
pageTypes: "page-types/",
permissionsGroups: "permission-groups/",
plugins: "plugins/",

View file

@ -10,3 +10,6 @@ export {
} from "./StaffMembers";
export * as productsRequests from "./Product";
export * as productsTypeRequests from "./ProductType";
export * as attributeRequests from "./Attribute";
export * as pageRequests from "./Page";
export * as pageTypeRequests from "./PageType";

View file

@ -37,3 +37,5 @@ export * as productDetailsPage from "./catalog/products/productDetailsPage";
export * as priceListComponent from "./catalog/products/priceListComponent";
export * as variantsPage from "./catalog/products/VariantsPage";
export * as channelsPage from "./channelsPage";
export * as pagesPage from "./pagesPage";
export * as pageDetailsPage from "./pageDetailsPage";

View file

@ -0,0 +1,5 @@
import { PAGE_DETAILS_SELECTORS } from "../../elements/pages/page-details";
export function typePageName(pageName) {
return cy.get(PAGE_DETAILS_SELECTORS.nameInput).type(pageName);
}

View file

@ -36,6 +36,20 @@ export function createPage({
attributesTypes[attributeType](attributeValue);
return savePage();
}
export function createPageWithAttribute({
pageName,
pageTypeName,
isPublished = false,
attributeType = "DROPDOWN",
attributeValue,
}) {
cy.get(PAGE_DETAILS_SELECTORS.nameInput).type(pageName);
if (!isPublished) {
cy.get(PAGE_DETAILS_SELECTORS.isNotPublishedCheckbox).click();
}
attributesTypes[attributeType](attributeValue);
return savePage();
}
export function addSelectAttributeValue(attributeValue) {
cy.fillAutocompleteSelect(
@ -81,7 +95,7 @@ function openCreatePageAndFillUpGeneralFields({
}
}
function savePage() {
export function savePage() {
return cy
.addAliasToGraphRequest("PageCreate")
.get(BUTTON_SELECTORS.confirm)
@ -90,3 +104,13 @@ function savePage() {
.waitForRequestAndCheckIfNoErrors("@PageCreate")
.its("response.body.data.pageCreate.page");
}
export function openCreatePageDialog() {
return cy.get(PAGES_LIST_SELECTORS.createPageButton).click();
}
export function selectPageTypeOnIndex(index) {
cy.get(PAGES_LIST_SELECTORS.dialogPageTypeInput).click();
return cy
.get(PAGES_LIST_SELECTORS.dialogPageTypeInputOptions)
.eq(index)
.click();
}