From b7f6a932b978e239b873d5051791f1b6fbd2ae3f Mon Sep 17 00:00:00 2001 From: Karolina Rakoczy Date: Tue, 8 Feb 2022 11:23:46 +0100 Subject: [PATCH] merge (#1821) --- .../catalog/categories/categories-list.js | 2 + cypress/integration/catalog/categories.js | 91 ++++++++++++++++--- .../checkout/purchaseWithProductTypes.js | 2 +- .../integration/configuration/translations.js | 4 +- .../integration/products/updatingProducts.js | 2 +- cypress/support/api/requests/Category.js | 5 +- .../api/utils/products/productsUtils.js | 2 +- .../sharedElementsOperations/tables.js | 2 + src/categories/views/CategoryDetails.tsx | 1 + .../views/CategoryList/CategoryList.tsx | 1 + 10 files changed, 94 insertions(+), 18 deletions(-) diff --git a/cypress/elements/catalog/categories/categories-list.js b/cypress/elements/catalog/categories/categories-list.js index 4e9627da0..d67101909 100644 --- a/cypress/elements/catalog/categories/categories-list.js +++ b/cypress/elements/catalog/categories/categories-list.js @@ -1,3 +1,5 @@ export const CATEGORIES_LIST = { addCategoryButton: '[data-test-id="createCategory"]' }; + +export const categoryRow = categoryId => `[data-test-id="${categoryId}"]`; diff --git a/cypress/integration/catalog/categories.js b/cypress/integration/catalog/categories.js index f77caf965..fa05c3540 100644 --- a/cypress/integration/catalog/categories.js +++ b/cypress/integration/catalog/categories.js @@ -3,7 +3,10 @@ import faker from "faker"; -import { CATEGORIES_LIST } from "../../elements/catalog/categories/categories-list"; +import { + CATEGORIES_LIST, + categoryRow +} from "../../elements/catalog/categories/categories-list"; import { CATEGORY_DETAILS } from "../../elements/catalog/categories/category-details"; import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements"; @@ -21,8 +24,8 @@ import { } from "../../support/pages/catalog/categoriesPage"; filterTests({ definedTags: ["all"] }, () => { - describe("Categories", () => { - const startsWith = "CyCollections"; + describe("As an admin I want to manage categories", () => { + const startsWith = "CyCategories"; const name = `${startsWith}${faker.datatype.number()}`; let attribute; @@ -70,7 +73,7 @@ filterTests({ definedTags: ["all"] }, () => { cy.clearSessionData().loginUserViaRequest(); }); - it("should create category", () => { + it("should be able to create category. TC: SALEOR_0201", () => { const categoryName = `${startsWith}${faker.datatype.number()}`; cy.visit(urlList.categories) @@ -88,7 +91,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should add subcategory", () => { + it("should be able to create category as subcategory. TC: SALEOR_0202", () => { const categoryName = `${startsWith}${faker.datatype.number()}`; cy.visit(categoryDetailsUrl(category.id)) @@ -103,7 +106,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should add product to category", () => { + it("should be able to add product to category. TC: SALEOR_0203", () => { cy.visit(categoryDetailsUrl(category.id)) .get(CATEGORY_DETAILS.productsTab) .click() @@ -113,7 +116,7 @@ filterTests({ definedTags: ["all"] }, () => { .should("include", urlList.addProduct); }); - it("should remove product from category", () => { + it("should be able to remove product from category. TC: SALEOR_0204", () => { cy.visit(categoryDetailsUrl(category.id)) .get(CATEGORY_DETAILS.productsTab) .click(); @@ -134,7 +137,7 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should enter category details page", () => { + it("should be able to enter category details page. TC: SALEOR_0205", () => { cy.visit(urlList.categories) .get(SHARED_ELEMENTS.searchInput) .type(category.name); @@ -142,10 +145,10 @@ filterTests({ definedTags: ["all"] }, () => { cy.contains(SHARED_ELEMENTS.header, category.name).should("be.visible"); }); - it("should delete category", () => { + it("should be able to delete category. TC: SALEOR_0206", () => { const categoryName = `${startsWith}${faker.datatype.number()}`; - createCategoryRequest(categoryName).then(categoryResp => { + createCategoryRequest({ name: categoryName }).then(categoryResp => { cy.visit(categoryDetailsUrl(categoryResp.id)) .get(BUTTON_SELECTORS.deleteButton) .click() @@ -157,11 +160,11 @@ filterTests({ definedTags: ["all"] }, () => { }); }); - it("should update category", () => { + it("should be able to update category. TC: SALEOR_0207", () => { const categoryName = `${startsWith}${faker.datatype.number()}`; const updatedName = `${startsWith}updatedCategory`; - createCategoryRequest(categoryName) + createCategoryRequest({ name: categoryName }) .then(categoryResp => { cy.visitAndWaitForProgressBarToDisappear( categoryDetailsUrl(categoryResp.id) @@ -176,5 +179,69 @@ filterTests({ definedTags: ["all"] }, () => { expect(descriptionText).to.eq(updatedName); }); }); + + it("should be able to delete several categories on categories list page. TC: SALEOR_0209", () => { + const firstCategoryName = `${startsWith}${faker.datatype.number()}`; + const secondCategoryName = `${startsWith}${faker.datatype.number()}`; + let firstCategory; + let secondCategory; + + createCategoryRequest({ name: firstCategoryName }).then(categoryResp => { + firstCategory = categoryResp; + }); + createCategoryRequest({ name: secondCategoryName }).then(categoryResp => { + secondCategory = categoryResp; + cy.visit(urlList.categories) + .searchInTable(startsWith) + .get(categoryRow(firstCategory.id)) + .find(BUTTON_SELECTORS.checkbox) + .click() + .get(categoryRow(secondCategory.id)) + .find(BUTTON_SELECTORS.checkbox) + .click() + .get(BUTTON_SELECTORS.deleteIcon) + .click() + .addAliasToGraphRequest("CategoryBulkDelete") + .get(BUTTON_SELECTORS.submit) + .click() + .waitForRequestAndCheckIfNoErrors("@CategoryBulkDelete"); + getCategory(firstCategory.id).should("be.null"); + getCategory(secondCategory.id).should("be.null"); + }); + }); + + it("should be able to remove subcategory from category. TC: SALEOR_0208", () => { + const subCategoryName = `${startsWith}${faker.datatype.number()}`; + const mainCategoryName = `${startsWith}${faker.datatype.number()}`; + let subCategory; + let mainCategory; + + createCategoryRequest({ name: mainCategoryName }) + .then(categoryResp => { + mainCategory = categoryResp; + createCategoryRequest({ + name: subCategoryName, + parent: mainCategory.id + }); + }) + .then(categoryResp => { + subCategory = categoryResp; + cy.visit(categoryDetailsUrl(mainCategory.id)) + .get(categoryRow(subCategory.id)) + .find(BUTTON_SELECTORS.checkbox) + .click() + .get(BUTTON_SELECTORS.deleteIcon) + .click() + .addAliasToGraphRequest("CategoryBulkDelete") + .get(BUTTON_SELECTORS.submit) + .click() + .waitForRequestAndCheckIfNoErrors("@CategoryBulkDelete"); + getCategory(subCategory.id).should("be.null"); + getCategory(mainCategory.id); + }) + .then(categoryResp => { + expect(categoryResp.children.edges).to.be.empty; + }); + }); }); }); diff --git a/cypress/integration/checkout/purchaseWithProductTypes.js b/cypress/integration/checkout/purchaseWithProductTypes.js index 46fb1ca25..658bc80c7 100644 --- a/cypress/integration/checkout/purchaseWithProductTypes.js +++ b/cypress/integration/checkout/purchaseWithProductTypes.js @@ -79,7 +79,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => { createAttribute({ name }) .then(attributeResp => { attribute = attributeResp; - createCategory(name); + createCategory({ name }); }) .then(categoryResp => { category = categoryResp; diff --git a/cypress/integration/configuration/translations.js b/cypress/integration/configuration/translations.js index 9388e2df3..8e7f545c1 100644 --- a/cypress/integration/configuration/translations.js +++ b/cypress/integration/configuration/translations.js @@ -27,7 +27,9 @@ filterTests({ definedTags: ["all"], version: "3.0.0" }, () => { before(() => { cy.clearSessionData().loginUserViaRequest(); deleteCategoriesStartsWith(startsWith); - createCategory(name).then(categoryResp => (category = categoryResp)); + createCategory({ name: startsWith }).then( + categoryResp => (category = categoryResp) + ); }); beforeEach(() => { diff --git a/cypress/integration/products/updatingProducts.js b/cypress/integration/products/updatingProducts.js index 8e40bcd74..d6306291d 100644 --- a/cypress/integration/products/updatingProducts.js +++ b/cypress/integration/products/updatingProducts.js @@ -67,7 +67,7 @@ filterTests({ definedTags: ["all"] }, () => { const updatedName = `${startsWith}${faker.random.number()}`; let updatedCategory; let updatedCollection; - createCategory(updatedName) + createCategory({ name: updatedName }) .then(categoryResp => { updatedCategory = categoryResp; createCollection(updatedName); diff --git a/cypress/support/api/requests/Category.js b/cypress/support/api/requests/Category.js index ee94bb68c..1de223784 100644 --- a/cypress/support/api/requests/Category.js +++ b/cypress/support/api/requests/Category.js @@ -1,8 +1,9 @@ import { getValueWithDefault } from "./utils/Utils"; -export function createCategory(name, slug = name) { +export function createCategory({ name, slug = name, parent }) { + const parentLine = getValueWithDefault(parent, `parent:"${parent}"`); const mutation = `mutation{ - categoryCreate(input:{name:"${name}", slug: "${slug}"}){ + categoryCreate(input:{name:"${name}", slug: "${slug}"} ${parentLine}){ productErrors{ field message diff --git a/cypress/support/api/utils/products/productsUtils.js b/cypress/support/api/utils/products/productsUtils.js index 15201c4ee..e68ec18c9 100644 --- a/cypress/support/api/utils/products/productsUtils.js +++ b/cypress/support/api/utils/products/productsUtils.js @@ -93,7 +93,7 @@ export function createTypeAttributeAndCategoryForProduct({ attributeId: attribute.id }); } - categoryRequest.createCategory(name); + categoryRequest.createCategory({ name }); }) .then(categoryResp => { category = categoryResp; diff --git a/cypress/support/customCommands/sharedElementsOperations/tables.js b/cypress/support/customCommands/sharedElementsOperations/tables.js index dd8d6d80a..7371f82e0 100644 --- a/cypress/support/customCommands/sharedElementsOperations/tables.js +++ b/cypress/support/customCommands/sharedElementsOperations/tables.js @@ -21,5 +21,7 @@ Cypress.Commands.add("findElementOnTable", (elementName, alias) => { Cypress.Commands.add("searchInTable", query => { cy.get(SHARED_ELEMENTS.searchInput) .type(query) + .get(SHARED_ELEMENTS.progressBar) + .should("be.visible") .waitForProgressBarToNotExist(); }); diff --git a/src/categories/views/CategoryDetails.tsx b/src/categories/views/CategoryDetails.tsx index c774218ad..6b2b3e7e2 100644 --- a/src/categories/views/CategoryDetails.tsx +++ b/src/categories/views/CategoryDetails.tsx @@ -252,6 +252,7 @@ export const CategoryDetails: React.FC = ({ subcategories={mapEdgesToItems(data?.category?.children)} subcategoryListToolbar={ diff --git a/src/categories/views/CategoryList/CategoryList.tsx b/src/categories/views/CategoryList/CategoryList.tsx index 5132f5c59..97a10c0e3 100644 --- a/src/categories/views/CategoryList/CategoryList.tsx +++ b/src/categories/views/CategoryList/CategoryList.tsx @@ -170,6 +170,7 @@ export const CategoryList: React.FC = ({ params }) => { openModal("delete", { ids: listElements