tests for filters (#1250)

This commit is contained in:
Karolina Rakoczy 2021-08-18 13:58:07 +02:00 committed by GitHub
parent f50e3bdde1
commit 2c916e6566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 166 additions and 31 deletions

View file

@ -16,6 +16,7 @@ export function createAttribute({
attribute{ attribute{
id id
name name
slug
choices(first: 100){ choices(first: 100){
edges{ edges{
node{ node{
@ -82,3 +83,17 @@ export function getAttribute(attributeId) {
}`; }`;
return cy.sendRequestWithQuery(query).its("body.data.attribute"); return cy.sendRequestWithQuery(query).its("body.data.attribute");
} }
export function updateAttribute({ filterableInDashboard }) {
const mutation = `mutation{
attributeUpdate(id:"" input:{
filterableInDashboard:false
}){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}

View file

@ -87,6 +87,7 @@ export function updateChannelPriceInVariant(variantId, channelId) {
} }
export function createProduct({ export function createProduct({
attributeId, attributeId,
attributeValue,
name, name,
productTypeId, productTypeId,
categoryId, categoryId,
@ -102,10 +103,15 @@ export function createProduct({
description, description,
`description:"{\\"blocks\\":[{\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}]}"` `description:"{\\"blocks\\":[{\\"type\\":\\"paragraph\\",\\"data\\":{\\"text\\":\\"${description}\\"}}]}"`
); );
const attributeValuesLine = getValueWithDefault(
attributeValue,
`values:["${attributeValue}"]`
);
const mutation = `mutation{ const mutation = `mutation{
productCreate(input:{ productCreate(input:{
attributes:[{ attributes:[{
id:"${attributeId}" id:"${attributeId}"
${attributeValuesLine}
}] }]
name:"${name}" name:"${name}"
slug:"${name}" slug:"${name}"

View file

@ -5,6 +5,9 @@ export const ATTRIBUTES_DETAILS = {
assignValuesButton: '[data-test-id="assignValueButton"]', assignValuesButton: '[data-test-id="assignValueButton"]',
valueRequired: '[name="valueRequired"]', valueRequired: '[name="valueRequired"]',
valueNameInput: '[data-test-id="valueName"]', valueNameInput: '[data-test-id="valueName"]',
dashboardProperties: {
useInFilteringCheckbox: '[name="filterableInDashboard"]'
},
attributesInputTypes: { attributesInputTypes: {
DROPDOWN: '[data-test-id="DROPDOWN"]', DROPDOWN: '[data-test-id="DROPDOWN"]',
MULTISELECT: '[data-test-id="MULTISELECT"]', MULTISELECT: '[data-test-id="MULTISELECT"]',

View file

@ -29,6 +29,7 @@ export const PRODUCTS_LIST = {
channel: '[data-test="filterGroupActive"][data-test-id="channel"]' channel: '[data-test="filterGroupActive"][data-test-id="channel"]'
}, },
filterField: { filterField: {
filterField: '[data-test="filter-field"]',
category: '[data-test="filter-field"][data-test-id="categories"]', category: '[data-test="filter-field"][data-test-id="categories"]',
collection: '[data-test="filter-field"][data-test-id="collections"]', collection: '[data-test="filter-field"][data-test-id="collections"]',
productType: '[data-test="filter-field"][data-test-id="productType"]', productType: '[data-test="filter-field"][data-test-id="productType"]',

View file

@ -11,6 +11,9 @@ export const SHARED_ELEMENTS = {
selectOption: '[data-test="selectFieldOption"]', selectOption: '[data-test="selectFieldOption"]',
richTextEditor: { richTextEditor: {
empty: '[class*="codex-editor--empty"]' empty: '[class*="codex-editor--empty"]'
},
filters: {
filterGroupActivateCheckbox: '[data-test="filterGroupActive"]'
} }
}; };

View file

@ -9,7 +9,7 @@ import { SHARED_ELEMENTS } from "../elements/shared/sharedElements";
import { createCategory } from "../steps/categoriesSteps"; import { createCategory } from "../steps/categoriesSteps";
import { confirmationMessageShouldDisappear } from "../steps/shared/confirmationMessages"; import { confirmationMessageShouldDisappear } from "../steps/shared/confirmationMessages";
import filterTests from "../support/filterTests"; import filterTests from "../support/filterTests";
import { categoryDetails, urlList } from "../url/urlList"; import { categoryDetailsUrl, urlList } from "../url/urlList";
import { deleteCategoriesStartsWith } from "../utils/categoryUtils"; import { deleteCategoriesStartsWith } from "../utils/categoryUtils";
import * as channelsUtils from "../utils/channelsUtils"; import * as channelsUtils from "../utils/channelsUtils";
import * as productsUtils from "../utils/products/productsUtils"; import * as productsUtils from "../utils/products/productsUtils";
@ -85,11 +85,11 @@ filterTests(["all"], () => {
it("should add subcategory", () => { it("should add subcategory", () => {
const categoryName = `${startsWith}${faker.datatype.number()}`; const categoryName = `${startsWith}${faker.datatype.number()}`;
cy.visit(categoryDetails(category.id)) cy.visit(categoryDetailsUrl(category.id))
.get(CATEGORY_DETAILS.createSubcategoryButton) .get(CATEGORY_DETAILS.createSubcategoryButton)
.click(); .click();
createCategory({ name: categoryName, description: categoryName }) createCategory({ name: categoryName, description: categoryName })
.visit(categoryDetails(category.id)) .visit(categoryDetailsUrl(category.id))
.contains(CATEGORY_DETAILS.categoryChildrenRow, categoryName) .contains(CATEGORY_DETAILS.categoryChildrenRow, categoryName)
.should("be.visible"); .should("be.visible");
getCategory(category.id).then(categoryResp => { getCategory(category.id).then(categoryResp => {
@ -98,7 +98,7 @@ filterTests(["all"], () => {
}); });
it("should add product to category", () => { it("should add product to category", () => {
cy.visit(categoryDetails(category.id)) cy.visit(categoryDetailsUrl(category.id))
.get(CATEGORY_DETAILS.productsTab) .get(CATEGORY_DETAILS.productsTab)
.click() .click()
.get(CATEGORY_DETAILS.addProducts) .get(CATEGORY_DETAILS.addProducts)
@ -108,7 +108,7 @@ filterTests(["all"], () => {
}); });
it("should remove product from category", () => { it("should remove product from category", () => {
cy.visit(categoryDetails(category.id)) cy.visit(categoryDetailsUrl(category.id))
.get(CATEGORY_DETAILS.productsTab) .get(CATEGORY_DETAILS.productsTab)
.click(); .click();
cy.contains(CATEGORY_DETAILS.productRow, product.name) cy.contains(CATEGORY_DETAILS.productRow, product.name)

View file

@ -0,0 +1,52 @@
import { updateAttribute } from "../../../apiRequests/Attribute";
import { createProduct } from "../../../apiRequests/Product";
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
import { enterAttributeAndChanegeIsFilterableInDashbord } from "../../../steps/attributesSteps";
import {
enterProductListPage,
selectAttributeFilter,
showFilters
} from "../../../steps/catalog/products/productsListSteps";
import {
createTypeAttributeAndCategoryForProduct,
deleteProductsStartsWith
} from "../../../utils/products/productsUtils";
describe("Tests for using attributes in filters", () => {
const startsWith = "AttrFilter";
let attribute;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteProductsStartsWith(startsWith);
createTypeAttributeAndCategoryForProduct(startsWith, [startsWith]).then(
({ attribute: attributeResp, category, productType }) => {
attribute = attributeResp;
createProduct({
attributeId: attribute.id,
attributeValue: startsWith,
categoryId: category.id,
productTypeId: productType.id,
name: startsWith
});
}
);
});
it("should use attribute as filter", () => {
updateAttribute({ filterableInDashboard: false });
enterAttributeAndChanegeIsFilterableInDashbord(attribute.id);
enterProductListPage();
selectAttributeFilter(attribute.slug, startsWith);
cy.contains(SHARED_ELEMENTS.tableRow, startsWith).should("be.visible");
});
it("should remove attribute from filters", () => {
updateAttribute({ filterableInDashboard: false });
enterAttributeAndChanegeIsFilterableInDashbord(attribute.id);
enterProductListPage();
showFilters();
cy.contains(attribute.name).should("not.exist");
});
});

View file

@ -1,5 +1,7 @@
import { ATTRIBUTES_DETAILS } from "../elements/attribute/attributes_details"; import { ATTRIBUTES_DETAILS } from "../elements/attribute/attributes_details";
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
import { attributeDetailsUrl } from "../url/urlList";
import { confirmationMessageShouldDisappear } from "./shared/confirmationMessages";
export function createAttributeWithInputType({ export function createAttributeWithInputType({
name, name,
@ -40,12 +42,14 @@ export function fillUpAttributeCreateFields({
} }
export function saveAttribute() { export function saveAttribute() {
return cy cy.addAliasToGraphRequest("AttributeCreate");
.addAliasToGraphRequest("AttributeCreate") submitAttribute();
.get(BUTTON_SELECTORS.confirm) return cy.wait("@AttributeCreate").its("response.body.data.attributeCreate");
.click() }
.wait("@AttributeCreate")
.its("response.body.data.attributeCreate"); export function submitAttribute() {
cy.get(BUTTON_SELECTORS.confirm).click();
confirmationMessageShouldDisappear();
} }
export function addSingleValue(valueName) { export function addSingleValue(valueName) {
@ -80,3 +84,10 @@ export function selectNumericSystem({ unitSystem, unitsOf, unit }) {
.get(ATTRIBUTES_DETAILS.unitsOptions[unit]) .get(ATTRIBUTES_DETAILS.unitsOptions[unit])
.click(); .click();
} }
export function enterAttributeAndChanegeIsFilterableInDashbord(attributeId) {
cy.visit(attributeDetailsUrl(attributeId))
.get(ATTRIBUTES_DETAILS.dashboardProperties.useInFilteringCheckbox)
.click();
submitAttribute();
}

View file

@ -1,6 +1,10 @@
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list"; import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { getElementByDataTestId } from "../../../elements/shared/sharedElements"; import {
getElementByDataTestId,
SHARED_ELEMENTS
} from "../../../elements/shared/sharedElements";
import { urlList } from "../../../url/urlList";
import { waitForProgressBarToNotExist } from "../../shared/progressBar"; import { waitForProgressBarToNotExist } from "../../shared/progressBar";
export function isNumberOfProductsSameAsInSelectResultsOnPage() { export function isNumberOfProductsSameAsInSelectResultsOnPage() {
@ -21,6 +25,7 @@ export function isNumberOfProductsSameAsInSelectResultsOnPage() {
productsList => productsList.length === parseInt(numberOfResults, 10) productsList => productsList.length === parseInt(numberOfResults, 10)
); );
} }
export function getDisplayedColumnArray(columnName) { export function getDisplayedColumnArray(columnName) {
let productsList = new Array(); let productsList = new Array();
return cy return cy
@ -45,6 +50,23 @@ export function selectFilterOption(filter, optionName) {
.click(); .click();
submitFilters(); submitFilters();
} }
export function selectAttributeFilter(attributeSlug, attributeValue) {
selectFilterByAttribute(attributeSlug);
cy.get(
`${getElementByDataTestId(attributeSlug)}${
PRODUCTS_LIST.filters.filterField.filterField
}`
)
.find(PRODUCTS_LIST.filters.filterOption)
.should("be.visible")
.contains(attributeValue)
.should("be.visible")
.find(BUTTON_SELECTORS.checkbox)
.click();
submitFilters();
}
export function selectProductsOutOfStock() { export function selectProductsOutOfStock() {
cy.get(PRODUCTS_LIST.filters.filterBy.stock) cy.get(PRODUCTS_LIST.filters.filterBy.stock)
.click() .click()
@ -52,14 +74,27 @@ export function selectProductsOutOfStock() {
.click(); .click();
submitFilters(); submitFilters();
} }
export function selectFilterBy(filter) { export function selectFilterBy(filter) {
return cy return showFilters()
.get(PRODUCTS_LIST.showFiltersButton)
.click()
.get(PRODUCTS_LIST.filters.filterBy[filter]) .get(PRODUCTS_LIST.filters.filterBy[filter])
.click(); .click();
} }
export function selectFilterByAttribute(attributeSlug) {
return showFilters()
.get(
`${getElementByDataTestId(attributeSlug)}${
SHARED_ELEMENTS.filters.filterGroupActivateCheckbox
}`
)
.click();
}
export function showFilters() {
return cy.get(PRODUCTS_LIST.showFiltersButton).click();
}
export function selectChannel(channelSlug) { export function selectChannel(channelSlug) {
selectFilterBy("channel"); selectFilterBy("channel");
cy.get(getElementByDataTestId(channelSlug)).click(); cy.get(getElementByDataTestId(channelSlug)).click();
@ -71,3 +106,8 @@ function submitFilters() {
.get(PRODUCTS_LIST.emptyProductRow) .get(PRODUCTS_LIST.emptyProductRow)
.should("not.exist"); .should("not.exist");
} }
export function enterProductListPage() {
cy.visit(urlList.products).softExpectSkeletonIsVisible();
waitForProgressBarToNotExist();
}

View file

@ -27,22 +27,35 @@ export const urlList = {
vouchers: "discounts/vouchers/" vouchers: "discounts/vouchers/"
}; };
export const productDetailsUrl = productId => `${urlList.products}${productId}`; export const appDetailsUrl = appId => `${urlList.apps}custom/${appId}`;
export const userDetailsUrl = userId => `${urlList.staffMembers}${userId}`; export const attributeDetailsUrl = attributeId =>
`${urlList.attributes}${attributeId}`;
export const staffMemberDetailsUrl = staffMemberId => export const categoryDetailsUrl = categoryId =>
`${urlList.staffMembers}${staffMemberId}`; `${urlList.categories}${categoryId}`;
export const customerDetailsUrl = customerId =>
`${urlList.customers}${customerId}`;
export const menuDetailsUrl = menuId => `${urlList.navigation}${menuId}`;
export const pageTypeDetailsUrl = pageTypeId =>
`${urlList.pageTypes}${pageTypeId}`;
export const permissionGroupDetails = permissionGroupId => export const permissionGroupDetails = permissionGroupId =>
`${urlList.permissionsGroups}${permissionGroupId}`; `${urlList.permissionsGroups}${permissionGroupId}`;
export const categoryDetails = categoryId => export const productDetailsUrl = productId => `${urlList.products}${productId}`;
`${urlList.categories}${categoryId}`;
export const staffMemberDetailsUrl = staffMemberId =>
`${urlList.staffMembers}${staffMemberId}`;
export const shippingZoneDetailsUrl = shippingZoneId => export const shippingZoneDetailsUrl = shippingZoneId =>
`${urlList.shippingMethods}${shippingZoneId}`; `${urlList.shippingMethods}${shippingZoneId}`;
export const userDetailsUrl = userId => `${urlList.staffMembers}${userId}`;
export const weightRateUrl = (shippingZoneId, weightRateId) => export const weightRateUrl = (shippingZoneId, weightRateId) =>
`${urlList.shippingMethods}${shippingZoneId}/${urlList.weightRete}${weightRateId}`; `${urlList.shippingMethods}${shippingZoneId}/${urlList.weightRete}${weightRateId}`;
@ -51,13 +64,3 @@ export const warehouseDetailsUrl = warehouseId =>
export const productTypeDetailsUrl = productTypeId => export const productTypeDetailsUrl = productTypeId =>
`${urlList.productTypes}${productTypeId}`; `${urlList.productTypes}${productTypeId}`;
export const menuDetailsUrl = menuId => `${urlList.navigation}${menuId}`;
export const customerDetailsUrl = customerId =>
`${urlList.customers}${customerId}`;
export const pageTypeDetailsUrl = pageTypeId =>
`${urlList.pageTypes}${pageTypeId}`;
export const appDetailsUrl = appId => `${urlList.apps}custom/${appId}`;

View file

@ -87,6 +87,7 @@ export function createTypeAttributeAndCategoryForProduct(
return { attribute, category, productType }; return { attribute, category, productType };
}); });
} }
export function deleteProductsStartsWith(startsWith) { export function deleteProductsStartsWith(startsWith) {
deleteAttributesStartsWith(startsWith); deleteAttributesStartsWith(startsWith);
cy.deleteElementsStartsWith(deleteProductType, getProductTypes, startsWith); cy.deleteElementsStartsWith(deleteProductType, getProductTypes, startsWith);