diff --git a/cypress/apiRequests/Attribute.js b/cypress/apiRequests/Attribute.js index f889a0f08..6de9fd2d2 100644 --- a/cypress/apiRequests/Attribute.js +++ b/cypress/apiRequests/Attribute.js @@ -1,10 +1,14 @@ -export function createAttribute(name, attributeValues = ["value"]) { +export function createAttribute({ + name, + attributeValues = ["value"], + type = "PRODUCT_TYPE" +}) { const values = attributeValues.map(element => `{name:"${element}"}`); const mutation = `mutation{ attributeCreate(input:{ name:"${name}" valueRequired:false - type:PRODUCT_TYPE + type:${type} values: [${values}] }){ attribute{ diff --git a/cypress/apiRequests/PageTypes.js b/cypress/apiRequests/PageTypes.js new file mode 100644 index 000000000..74572708a --- /dev/null +++ b/cypress/apiRequests/PageTypes.js @@ -0,0 +1,28 @@ +export function getPageType(pageTypeId) { + const query = `query{ + pageType(id:"${pageTypeId}"){ + id + name + attributes{ + name + } + } + }`; + return cy.sendRequestWithQuery(query).its("body.data.pageType"); +} + +export function createPageType(name) { + const mutation = `mutation{ + pageTypeCreate(input:{ name: "${name}"}){ + pageType{ + name + id + } + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation).its("body.data.pageTypeCreate"); +} diff --git a/cypress/elements/pageTypes/pageTypeDetails.js b/cypress/elements/pageTypes/pageTypeDetails.js new file mode 100644 index 000000000..713892866 --- /dev/null +++ b/cypress/elements/pageTypes/pageTypeDetails.js @@ -0,0 +1,4 @@ +export const PAGE_TYPE_DETAILS = { + nameInput: '[name="name"]', + assignAttributesButton: '[data-test-id="assignAttributes"]' +}; diff --git a/cypress/elements/pageTypes/pageTypesList.js b/cypress/elements/pageTypes/pageTypesList.js new file mode 100644 index 000000000..54f0231dd --- /dev/null +++ b/cypress/elements/pageTypes/pageTypesList.js @@ -0,0 +1,3 @@ +export const PAGE_TYPES_LIST = { + createPageTypeButton: '[data-test-id="createPageType"]' +}; diff --git a/cypress/integration/allEnv/configuration/productTypes.js b/cypress/integration/allEnv/configuration/productTypes.js index a8ed77706..f5ab18967 100644 --- a/cypress/integration/allEnv/configuration/productTypes.js +++ b/cypress/integration/allEnv/configuration/productTypes.js @@ -19,7 +19,7 @@ describe("Tests for product types", () => { before(() => { cy.clearSessionData().loginUserViaRequest(); deleteProductsStartsWith(startsWith); - createAttribute(startsWith); + createAttribute({ name: startsWith }); }); beforeEach(() => { diff --git a/cypress/integration/allEnv/pages/pageTypes.js b/cypress/integration/allEnv/pages/pageTypes.js new file mode 100644 index 000000000..9756f667a --- /dev/null +++ b/cypress/integration/allEnv/pages/pageTypes.js @@ -0,0 +1,61 @@ +import faker from "faker"; + +import { createAttribute } from "../../../apiRequests/Attribute"; +import { createPageType, getPageType } from "../../../apiRequests/PageTypes"; +import { PAGE_TYPE_DETAILS } from "../../../elements/pageTypes/pageTypeDetails"; +import { PAGE_TYPES_LIST } from "../../../elements/pageTypes/pageTypesList"; +import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; +import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; +import { assignElements } from "../../../steps/shared/assignElements"; +import { confirmationMessageShouldDisappear } from "../../../steps/shared/confirmationMessage"; +import { pageTypeDetailsUrl, urlList } from "../../../url/urlList"; + +describe("Tests for page types", () => { + const startsWith = "PageTypes"; + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it("should create page type", () => { + const randomName = startsWith + faker.datatype.number(); + + cy.visit(urlList.pageTypes) + .get(PAGE_TYPES_LIST.createPageTypeButton) + .click() + .get(PAGE_TYPE_DETAILS.nameInput) + .type(randomName) + .addAliasToGraphRequest("PageTypeCreate") + .get(BUTTON_SELECTORS.confirm) + .click(); + confirmationMessageShouldDisappear(); + cy.wait("@PageTypeCreate") + .its("response.body.data.pageTypeCreate.pageType") + .then(pageType => { + getPageType(pageType.id); + }) + .then(pageType => { + expect(pageType.name).to.eq(randomName); + }); + }); + + it("should assign attribute", () => { + const randomName = startsWith + faker.datatype.number(); + + createAttribute({ name: randomName, type: "PAGE_TYPE" }); + createPageType(randomName) + .then(({ pageType }) => { + cy.visit(pageTypeDetailsUrl(pageType.id)) + .get(SHARED_ELEMENTS.progressBar) + .should("be.not.visible") + .get(PAGE_TYPE_DETAILS.assignAttributesButton) + .click(); + assignElements(randomName, false); + confirmationMessageShouldDisappear(); + getPageType(pageType.id); + }) + .then(pageType => { + expect(pageType.attributes[0].name).to.eq(randomName); + }); + }); +}); diff --git a/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js b/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js index 1aa855fde..e4efdba83 100644 --- a/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js +++ b/cypress/integration/allEnv/productTypes/purchaseWithProductTypes.js @@ -62,7 +62,7 @@ describe("Purchase products with all products types", () => { shippingMethod = shippingMethodResp; } ); - createAttribute(name) + createAttribute({ name }) .then(attributeResp => { attribute = attributeResp; createCategory(name); diff --git a/cypress/integration/allEnv/products/createProduct.js b/cypress/integration/allEnv/products/createProduct.js index 572d51b1f..c1b7a8ff4 100644 --- a/cypress/integration/allEnv/products/createProduct.js +++ b/cypress/integration/allEnv/products/createProduct.js @@ -51,7 +51,7 @@ describe("Create product", () => { before(() => { cy.clearSessionData().loginUserViaRequest(); productUtils.deleteProductsStartsWith(startsWith); - createAttribute(name).then(attributeResp => { + createAttribute({ name }).then(attributeResp => { attribute = attributeResp; }); }); diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index 50c10029f..a1acb9d39 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -1,26 +1,28 @@ export const urlList = { apiUri: Cypress.env("API_URI"), + addProduct: "products/add", + apps: "apps/", + attributes: "attributes/", channels: "channels/", + categories: "categories/", + collections: "collections/", configuration: "configuration/", + customers: "customers/", draftOrders: "orders/drafts/", homePage: "/", + newPassword: "new-password/", orders: "orders/", + pageTypes: "page-types/", + permissionsGroups: "permission-groups/", products: "products/", - addProduct: "products/add", - warehouses: "warehouses/", + productTypes: "product-types/", shippingMethods: "shipping/", sales: "discounts/sales/", - collections: "collections/", - vouchers: "discounts/vouchers/", + shippingMethods: "shipping/", staffMembers: "staff/", - newPassword: "new-password/", - permissionsGroups: "permission-groups/", - categories: "categories/", - weightRete: "weight/", - attributes: "attributes/", - productTypes: "product-types/", - apps: "apps/", - customers: "customers/" + vouchers: "discounts/vouchers/", + warehouses: "warehouses/", + weightRete: "weight/" }; export const productDetailsUrl = productId => `${urlList.products}${productId}`; @@ -48,4 +50,7 @@ export const warehouseDetailsUrl = warehouseId => export const productTypeDetailsUrl = productTypeId => `${urlList.productTypes}${productTypeId}`; +export const pageTypeDetailsUrl = pageTypeId => + `${urlList.pageTypes}${pageTypeId}`; + export const appDetailsUrl = appId => `${urlList.apps}custom/${appId}`; diff --git a/cypress/utils/products/productsUtils.js b/cypress/utils/products/productsUtils.js index 6a5f931d8..064842cda 100644 --- a/cypress/utils/products/productsUtils.js +++ b/cypress/utils/products/productsUtils.js @@ -73,7 +73,7 @@ export function createTypeAttributeAndCategoryForProduct( let productType; let category; return attributeRequest - .createAttribute(name, attributeValues) + .createAttribute({ name, attributeValues }) .then(attributeResp => { attribute = attributeResp; createTypeProduct({ name, attributeId: attributeResp.id }); diff --git a/src/pageTypes/components/PageTypeAttributes/PageTypeAttributes.tsx b/src/pageTypes/components/PageTypeAttributes/PageTypeAttributes.tsx index 5009eb254..d91dd1de1 100644 --- a/src/pageTypes/components/PageTypeAttributes/PageTypeAttributes.tsx +++ b/src/pageTypes/components/PageTypeAttributes/PageTypeAttributes.tsx @@ -91,6 +91,7 @@ const PageTypeAttributes: React.FC = props => { color="primary" variant="text" onClick={() => onAttributeAssign(AttributeTypeEnum[type])} + data-test-id="assignAttributes" > = ({ {intl.formatMessage(sectionNames.configuration)} -