diff --git a/cypress/e2e/products/productsList/deleteProducts.js b/cypress/e2e/products/productsList/deleteProducts.js new file mode 100644 index 000000000..74547f3bf --- /dev/null +++ b/cypress/e2e/products/productsList/deleteProducts.js @@ -0,0 +1,70 @@ +/// +/// +import faker from "faker"; + +import { BUTTON_SELECTORS, PRODUCTS_LIST } from "../../../elements/"; +import { DIALOGS_MESSAGES } from "../../../fixtures/"; +import { urlList } from "../../../fixtures/urlList"; +import { getDefaultChannel, productsUtils } from "../../../support/api/utils/"; +import { ensureCanvasStatic } from "../../../support/customCommands/sharedElementsOperations/canvas"; + +describe("Test for deleting products", () => { + const startsWith = "AABulkDeleteCypress"; + const name = `${startsWith}${faker.datatype.number()}`; + const name2 = `${startsWith}${faker.datatype.number()}`; + let channel; + let product; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + productsUtils.deleteProductsStartsWith(startsWith); + getDefaultChannel() + .then(channelResp => { + channel = channelResp; + productsUtils.createTypeAttributeAndCategoryForProduct({ name }); + }) + .then(({ attribute, category, productType }) => { + productsUtils.createProductInChannel({ + attributeId: attribute.id, + categoryId: category.id, + channelId: channel.id, + name, + productTypeId: productType.id, + }); + productsUtils.createProductInChannel({ + attributeId: attribute.id, + categoryId: category.id, + channelId: channel.id, + name: name2, + productTypeId: productType.id, + }); + }) + .then(({ product: productResp }) => { + product = productResp; + cy.checkIfDataAreNotNull({ channel, product }); + }); + }); + + it( + "should delete 2 first products on products grid view - SALEOR_2709", + { tags: ["@metadata", "@allEnv", "@stable"] }, + () => { + cy.clearSessionData().loginUserViaRequest(); + cy.visit(urlList.products); + // checks two first rows on products data grid + cy.clickGridCell(0, 0); + cy.clickGridCell(0, 1); + cy.clickOnElement(BUTTON_SELECTORS.deleteProductsButton); + cy.contains(DIALOGS_MESSAGES.confirmProductsDeletion).should( + "be.visible", + ); + cy.addAliasToGraphRequest("productBulkDelete") + .clickSubmitButton() + .waitForRequestAndCheckIfNoErrors("@productBulkDelete"); + ensureCanvasStatic(PRODUCTS_LIST.dataGridTable); + cy.get(BUTTON_SELECTORS.submit).should("not.exist"); + cy.contains(name).should("not.exist"); + cy.contains(name2).should("not.exist"); + }, + ); +}); diff --git a/cypress/elements/catalog/products/index.js b/cypress/elements/catalog/products/index.js index 78aa608f3..ef7ef6834 100644 --- a/cypress/elements/catalog/products/index.js +++ b/cypress/elements/catalog/products/index.js @@ -1,4 +1,2 @@ -import { PRODUCT_DETAILS } from "./product-details"; -import { PRODUCTS_LIST } from "./products-list"; - -export { PRODUCT_DETAILS, PRODUCTS_LIST }; +export { PRODUCT_DETAILS } from "./product-details"; +export { PRODUCTS_LIST } from "./products-list"; diff --git a/cypress/elements/shared/button-selectors.js b/cypress/elements/shared/button-selectors.js index 06de37812..b2bc90720 100644 --- a/cypress/elements/shared/button-selectors.js +++ b/cypress/elements/shared/button-selectors.js @@ -8,6 +8,7 @@ export const BUTTON_SELECTORS = { selectOption: "[data-test-id*='select-option']", notSelectedOption: ":not([aria-selected])", deleteButton: '[data-test-id="button-bar-delete"]', + deleteProductsButton: '[data-test-id="delete-products-button"]', deleteItemsButton: '[data-test-id="button-delete-items"]', confirmDeleteButton: '[data-test-id="confirm-delete"]', expandIcon: '[data-test-id="expand-icon"]', diff --git a/cypress/elements/shared/index.js b/cypress/elements/shared/index.js index 5e22b5298..9c6ae5eec 100644 --- a/cypress/elements/shared/index.js +++ b/cypress/elements/shared/index.js @@ -1,12 +1,4 @@ -import { ADDRESS_SELECTORS } from "./addressForm"; -import { BUTTON_SELECTORS } from "./button-selectors"; -import { PRESETS, SEARCH } from "./presetsAndSearch"; -import { SHARED_ELEMENTS } from "./sharedElements"; - -export { - ADDRESS_SELECTORS, - BUTTON_SELECTORS, - PRESETS, - SEARCH, - SHARED_ELEMENTS, -}; +export { ADDRESS_SELECTORS } from "./addressForm"; +export { BUTTON_SELECTORS } from "./button-selectors"; +export { PRESETS, SEARCH } from "./presetsAndSearch"; +export { SHARED_ELEMENTS } from "./sharedElements"; diff --git a/cypress/fixtures/index.js b/cypress/fixtures/index.js index 9e7b92b82..8bcbd7c7e 100644 --- a/cypress/fixtures/index.js +++ b/cypress/fixtures/index.js @@ -2,3 +2,4 @@ export { bodyMockHomePage } from "./bodyMocks"; export { orderDraftCreateDemoResponse } from "./errors/demo/orderDratCreate"; export { urlList } from "./urlList"; export { ONE_PERMISSION_USERS } from "./users"; +export { DIALOGS_MESSAGES } from "./messages"; diff --git a/cypress/fixtures/messages.js b/cypress/fixtures/messages.js new file mode 100644 index 000000000..17fb592e5 --- /dev/null +++ b/cypress/fixtures/messages.js @@ -0,0 +1,3 @@ +export const DIALOGS_MESSAGES = { + confirmProductsDeletion: "Are you sure you want to delete 2 products?", +}; diff --git a/cypress/support/api/requests/index.js b/cypress/support/api/requests/index.js index 24158d763..87a73a2df 100644 --- a/cypress/support/api/requests/index.js +++ b/cypress/support/api/requests/index.js @@ -1,3 +1,5 @@ export { createChannel, updateChannelOrderSettings } from "./Channels"; export { createCustomer, deleteCustomersStartsWith } from "./Customer"; -export { getOrder } from "./Order"; +export { createDraftOrder, getOrder } from "./Order"; +export { updateMetadata, updatePrivateMetadata } from "./Metadata"; +export { getProductMetadata } from "./storeFront/ProductDetails"; diff --git a/cypress/support/api/utils/index.js b/cypress/support/api/utils/index.js index 895b484e6..35e62e456 100644 --- a/cypress/support/api/utils/index.js +++ b/cypress/support/api/utils/index.js @@ -1,4 +1,4 @@ -export { deleteChannelsStartsWith } from "./channelsUtils"; +export { deleteChannelsStartsWith, getDefaultChannel } from "./channelsUtils"; export { createOrder, createReadyToFulfillOrder } from "./ordersUtils"; export { createShipping, deleteShippingStartsWith } from "./shippingUtils"; export { diff --git a/src/products/components/ProductListDeleteButton/ProductListDeleteButton.tsx b/src/products/components/ProductListDeleteButton/ProductListDeleteButton.tsx index c78bc66d9..41026fd51 100644 --- a/src/products/components/ProductListDeleteButton/ProductListDeleteButton.tsx +++ b/src/products/components/ProductListDeleteButton/ProductListDeleteButton.tsx @@ -23,6 +23,7 @@ export const ProductListDeleteButton = forwardRef< onClick={onClick} icon={} variant="secondary" + data-test-id="delete-products-button" />