diff --git a/cypress/e2e/pages/pages.js b/cypress/e2e/pages/pages.js index 23db1883a..47cfeeb97 100644 --- a/cypress/e2e/pages/pages.js +++ b/cypress/e2e/pages/pages.js @@ -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); diff --git a/cypress/elements/pages/pages-list.js b/cypress/elements/pages/pages-list.js index 267cc68c4..a7e010ba9 100644 --- a/cypress/elements/pages/pages-list.js +++ b/cypress/elements/pages/pages-list.js @@ -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']", }; diff --git a/cypress/fixtures/urlList.js b/cypress/fixtures/urlList.js index f5ae45b8c..9c88c758c 100644 --- a/cypress/fixtures/urlList.js +++ b/cypress/fixtures/urlList.js @@ -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/", diff --git a/cypress/support/api/requests/index.js b/cypress/support/api/requests/index.js index d34cee4c8..8a2aa38f9 100644 --- a/cypress/support/api/requests/index.js +++ b/cypress/support/api/requests/index.js @@ -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"; diff --git a/cypress/support/pages/index.js b/cypress/support/pages/index.js index 0b0660124..43934874b 100644 --- a/cypress/support/pages/index.js +++ b/cypress/support/pages/index.js @@ -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"; diff --git a/cypress/support/pages/pageDetailsPage.js b/cypress/support/pages/pageDetailsPage.js new file mode 100644 index 000000000..ef2ffcf54 --- /dev/null +++ b/cypress/support/pages/pageDetailsPage.js @@ -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); +} diff --git a/cypress/support/pages/pagesPage.js b/cypress/support/pages/pagesPage.js index fe4585d3d..caa70c505 100644 --- a/cypress/support/pages/pagesPage.js +++ b/cypress/support/pages/pagesPage.js @@ -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(); +}