This commit is contained in:
Karolina Rakoczy 2022-02-08 11:23:46 +01:00 committed by GitHub
parent f088095335
commit b7f6a932b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 94 additions and 18 deletions

View file

@ -1,3 +1,5 @@
export const CATEGORIES_LIST = { export const CATEGORIES_LIST = {
addCategoryButton: '[data-test-id="createCategory"]' addCategoryButton: '[data-test-id="createCategory"]'
}; };
export const categoryRow = categoryId => `[data-test-id="${categoryId}"]`;

View file

@ -3,7 +3,10 @@
import faker from "faker"; 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 { CATEGORY_DETAILS } from "../../elements/catalog/categories/category-details";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements"; import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
@ -21,8 +24,8 @@ import {
} from "../../support/pages/catalog/categoriesPage"; } from "../../support/pages/catalog/categoriesPage";
filterTests({ definedTags: ["all"] }, () => { filterTests({ definedTags: ["all"] }, () => {
describe("Categories", () => { describe("As an admin I want to manage categories", () => {
const startsWith = "CyCollections"; const startsWith = "CyCategories";
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
let attribute; let attribute;
@ -70,7 +73,7 @@ filterTests({ definedTags: ["all"] }, () => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
}); });
it("should create category", () => { it("should be able to create category. TC: SALEOR_0201", () => {
const categoryName = `${startsWith}${faker.datatype.number()}`; const categoryName = `${startsWith}${faker.datatype.number()}`;
cy.visit(urlList.categories) 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()}`; const categoryName = `${startsWith}${faker.datatype.number()}`;
cy.visit(categoryDetailsUrl(category.id)) 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)) cy.visit(categoryDetailsUrl(category.id))
.get(CATEGORY_DETAILS.productsTab) .get(CATEGORY_DETAILS.productsTab)
.click() .click()
@ -113,7 +116,7 @@ filterTests({ definedTags: ["all"] }, () => {
.should("include", urlList.addProduct); .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)) cy.visit(categoryDetailsUrl(category.id))
.get(CATEGORY_DETAILS.productsTab) .get(CATEGORY_DETAILS.productsTab)
.click(); .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) cy.visit(urlList.categories)
.get(SHARED_ELEMENTS.searchInput) .get(SHARED_ELEMENTS.searchInput)
.type(category.name); .type(category.name);
@ -142,10 +145,10 @@ filterTests({ definedTags: ["all"] }, () => {
cy.contains(SHARED_ELEMENTS.header, category.name).should("be.visible"); 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()}`; const categoryName = `${startsWith}${faker.datatype.number()}`;
createCategoryRequest(categoryName).then(categoryResp => { createCategoryRequest({ name: categoryName }).then(categoryResp => {
cy.visit(categoryDetailsUrl(categoryResp.id)) cy.visit(categoryDetailsUrl(categoryResp.id))
.get(BUTTON_SELECTORS.deleteButton) .get(BUTTON_SELECTORS.deleteButton)
.click() .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 categoryName = `${startsWith}${faker.datatype.number()}`;
const updatedName = `${startsWith}updatedCategory`; const updatedName = `${startsWith}updatedCategory`;
createCategoryRequest(categoryName) createCategoryRequest({ name: categoryName })
.then(categoryResp => { .then(categoryResp => {
cy.visitAndWaitForProgressBarToDisappear( cy.visitAndWaitForProgressBarToDisappear(
categoryDetailsUrl(categoryResp.id) categoryDetailsUrl(categoryResp.id)
@ -176,5 +179,69 @@ filterTests({ definedTags: ["all"] }, () => {
expect(descriptionText).to.eq(updatedName); 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;
});
});
}); });
}); });

View file

@ -79,7 +79,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
createAttribute({ name }) createAttribute({ name })
.then(attributeResp => { .then(attributeResp => {
attribute = attributeResp; attribute = attributeResp;
createCategory(name); createCategory({ name });
}) })
.then(categoryResp => { .then(categoryResp => {
category = categoryResp; category = categoryResp;

View file

@ -27,7 +27,9 @@ filterTests({ definedTags: ["all"], version: "3.0.0" }, () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
deleteCategoriesStartsWith(startsWith); deleteCategoriesStartsWith(startsWith);
createCategory(name).then(categoryResp => (category = categoryResp)); createCategory({ name: startsWith }).then(
categoryResp => (category = categoryResp)
);
}); });
beforeEach(() => { beforeEach(() => {

View file

@ -67,7 +67,7 @@ filterTests({ definedTags: ["all"] }, () => {
const updatedName = `${startsWith}${faker.random.number()}`; const updatedName = `${startsWith}${faker.random.number()}`;
let updatedCategory; let updatedCategory;
let updatedCollection; let updatedCollection;
createCategory(updatedName) createCategory({ name: updatedName })
.then(categoryResp => { .then(categoryResp => {
updatedCategory = categoryResp; updatedCategory = categoryResp;
createCollection(updatedName); createCollection(updatedName);

View file

@ -1,8 +1,9 @@
import { getValueWithDefault } from "./utils/Utils"; 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{ const mutation = `mutation{
categoryCreate(input:{name:"${name}", slug: "${slug}"}){ categoryCreate(input:{name:"${name}", slug: "${slug}"} ${parentLine}){
productErrors{ productErrors{
field field
message message

View file

@ -93,7 +93,7 @@ export function createTypeAttributeAndCategoryForProduct({
attributeId: attribute.id attributeId: attribute.id
}); });
} }
categoryRequest.createCategory(name); categoryRequest.createCategory({ name });
}) })
.then(categoryResp => { .then(categoryResp => {
category = categoryResp; category = categoryResp;

View file

@ -21,5 +21,7 @@ Cypress.Commands.add("findElementOnTable", (elementName, alias) => {
Cypress.Commands.add("searchInTable", query => { Cypress.Commands.add("searchInTable", query => {
cy.get(SHARED_ELEMENTS.searchInput) cy.get(SHARED_ELEMENTS.searchInput)
.type(query) .type(query)
.get(SHARED_ELEMENTS.progressBar)
.should("be.visible")
.waitForProgressBarToNotExist(); .waitForProgressBarToNotExist();
}); });

View file

@ -252,6 +252,7 @@ export const CategoryDetails: React.FC<CategoryDetailsProps> = ({
subcategories={mapEdgesToItems(data?.category?.children)} subcategories={mapEdgesToItems(data?.category?.children)}
subcategoryListToolbar={ subcategoryListToolbar={
<IconButton <IconButton
data-test-id="delete-icon"
variant="secondary" variant="secondary"
color="primary" color="primary"
onClick={() => onClick={() =>

View file

@ -170,6 +170,7 @@ export const CategoryList: React.FC<CategoryListProps> = ({ params }) => {
<IconButton <IconButton
variant="secondary" variant="secondary"
color="primary" color="primary"
data-test-id="delete-icon"
onClick={() => onClick={() =>
openModal("delete", { openModal("delete", {
ids: listElements ids: listElements