diff --git a/cypress/apiRequests/Collections.js b/cypress/apiRequests/Collections.js new file mode 100644 index 000000000..8a9e1aa87 --- /dev/null +++ b/cypress/apiRequests/Collections.js @@ -0,0 +1,37 @@ +class Collections { + getCollections(search) { + const filter = search + ? `, filter:{ + search:"" + }` + : ""; + const query = `query{ + collections(first:100 ${filter}){ + edges{ + node{ + id + name + } + } + } + }`; + return cy + .sendRequestWithQuery(query) + .then(resp => resp.body.data.collections.edges); + } + deleteCollection(collectionId) { + const mutation = `mutation{ + collectionDelete(id:"${collectionId}"){ + collection{ + id + } + collectionErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} +export default Collections; diff --git a/cypress/apiRequests/storeFront/Collections.js b/cypress/apiRequests/storeFront/Collections.js new file mode 100644 index 000000000..54770701e --- /dev/null +++ b/cypress/apiRequests/storeFront/Collections.js @@ -0,0 +1,22 @@ +class Collections { + getCollection(collectionId, channelSlug) { + const query = `query Collection{ + collection(id: "${collectionId}", channel: "${channelSlug}") { + id + slug + name + products(first:100){ + totalCount + edges{ + node{ + id + name + } + } + } + } + }`; + return cy.sendRequestWithQuery(query, "token"); + } +} +export default Collections; diff --git a/cypress/elements/catalog/collection-selectors.js b/cypress/elements/catalog/collection-selectors.js new file mode 100644 index 000000000..5f2e44bed --- /dev/null +++ b/cypress/elements/catalog/collection-selectors.js @@ -0,0 +1,6 @@ +export const COLLECTION_SELECTORS = { + createCollectionButton: "[data-test-id = 'create-collection']", + nameInput: "[name='name']", + saveButton: "[data-test='button-bar-confirm']", + addProductButton: "[data-test-id='add-product']" +}; diff --git a/cypress/elements/catalog/products/assign-products-selectors.js b/cypress/elements/catalog/products/assign-products-selectors.js new file mode 100644 index 000000000..6acac9a80 --- /dev/null +++ b/cypress/elements/catalog/products/assign-products-selectors.js @@ -0,0 +1,6 @@ +export const ASSIGN_PRODUCTS_SELECTORS = { + searchInput: "[name='query']", + tableRow: "[class*='MuiTableRow']", + checkbox: "[type='checkbox']", + submitButton: "[type='submit']" +}; diff --git a/cypress/elements/catalog/product-selectors.js b/cypress/elements/catalog/products/product-selectors.js similarity index 98% rename from cypress/elements/catalog/product-selectors.js rename to cypress/elements/catalog/products/product-selectors.js index c55f5384f..d78adce75 100644 --- a/cypress/elements/catalog/product-selectors.js +++ b/cypress/elements/catalog/products/product-selectors.js @@ -1,4 +1,3 @@ -/* eslint-disable sort-keys */ export const PRODUCTS_SELECTORS = { productsList: "[data-test-id][data-test='id']", products: "[data-test='submenu-item-label'][data-test-id='products']", diff --git a/cypress/elements/channels/menage-channel-availability-form.js b/cypress/elements/channels/menage-channel-availability-form.js new file mode 100644 index 000000000..dfbc48256 --- /dev/null +++ b/cypress/elements/channels/menage-channel-availability-form.js @@ -0,0 +1,10 @@ +export const MENAGE_CHANNEL_AVAILABILITY_FORM = { + channelsMenageButton: "[data-test-id='channels-availiability-manage-button']", + allChannelsCheckbox: "[name='allChannels']", + channelRow: "[data-test-id='channel-row']", + channelCheckbox: "[class*='MuiCheckbox']", + channelsAvailabilityItem: "[data-test='channel-availability-item']", + publishedCheckbox: "[name='isPublished']", + radioButtonsValueTrue: "[value='true']", + radioButtonsValueFalse: "[value='false']" +}; diff --git a/cypress/elements/configuration/configuration-selectors.js b/cypress/elements/configuration/configuration-selectors.js index b1d85c627..a158e2cd8 100644 --- a/cypress/elements/configuration/configuration-selectors.js +++ b/cypress/elements/configuration/configuration-selectors.js @@ -1,4 +1,3 @@ -/* eslint-disable sort-keys */ export const CONFIGURATION_SELECTORS = { channels: "[data-testid='channels']" }; diff --git a/cypress/elements/shared/button-selectors.js b/cypress/elements/shared/button-selectors.js index 12b956298..332c54131 100644 --- a/cypress/elements/shared/button-selectors.js +++ b/cypress/elements/shared/button-selectors.js @@ -1,4 +1,3 @@ -/* eslint-disable sort-keys */ export const BUTTON_SELECTORS = { back: '[data-test="back"]', submit: '[data-test="submit"]' diff --git a/cypress/integration/channels.js b/cypress/integration/channels.js index 0f64da273..9f5e97a38 100644 --- a/cypress/integration/channels.js +++ b/cypress/integration/channels.js @@ -3,7 +3,7 @@ import faker from "faker"; import Channels from "../apiRequests/Channels"; import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors"; -import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors"; +import { PRODUCTS_SELECTORS } from "../elements/catalog/products/product-selectors"; import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors"; import { CHANNEL_FORM_SELECTORS } from "../elements/channels/channel-form-selectors"; import { CHANNELS_SELECTORS } from "../elements/channels/channels-selectors"; @@ -111,8 +111,7 @@ describe("Channels", () => { cy.addAliasToGraphRequest("Channels"); cy.visit(urlList.channels); cy.wait("@Channels"); - cy.get(CHANNELS_SELECTORS.channelName) - .contains(randomChannelToDelete) + cy.contains(CHANNELS_SELECTORS.channelName, randomChannelToDelete) .parentsUntil(CHANNELS_SELECTORS.channelsTable) .find("button") .click(); diff --git a/cypress/integration/collections.js b/cypress/integration/collections.js new file mode 100644 index 000000000..8b854822f --- /dev/null +++ b/cypress/integration/collections.js @@ -0,0 +1,177 @@ +// +import faker from "faker"; + +import Product from "../apiRequests/Product"; +import Collections from "../apiRequests/storeFront/Collections"; +import Search from "../apiRequests/storeFront/Search"; +import CollectionsSteps from "../steps/collectionsSteps"; +import { urlList } from "../url/urlList"; +import ChannelsUtils from "../utils/channelsUtils"; +import CollectionsUtils from "../utils/collectionsUtils"; +import ProductsUtils from "../utils/productsUtils"; +import ShippingUtils from "../utils/shippingUtils"; +import { + isCollectionVisible, + isProductInCollectionVisible +} from "../utils/storeFront/collectionsUtils"; +import { isProductVisibleInSearchResult } from "../utils/storeFront/storeFrontProductUtils"; + +describe("Collections", () => { + const productRequest = new Product(); + const collectionsRequest = new Collections(); + const search = new Search(); + const channelsUtils = new ChannelsUtils(); + const productsUtils = new ProductsUtils(); + const collectionsUtils = new CollectionsUtils(); + const shippingUtils = new ShippingUtils(); + const collectionsSteps = new CollectionsSteps(); + + const startsWith = "Cy-"; + const name = `${startsWith}${faker.random.number()}`; + + let attribute; + let productType; + let category; + + let defaultChannel; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + productsUtils.deleteProperProducts(startsWith); + collectionsUtils.deleteProperCollections(startsWith); + shippingUtils.deleteShipping(startsWith); + + channelsUtils + .getDefaultChannel() + .then(channel => { + defaultChannel = channel; + productsUtils.createTypeAttributeAndCategoryForProduct(name); + }) + .then(() => { + attribute = productsUtils.getAttribute(); + productType = productsUtils.getProductType(); + category = productsUtils.getCategory(); + productsUtils.createProductInChannel({ + name, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id + }); + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it("should not display hidden collections", () => { + const collectionName = `${startsWith}${faker.random.number()}`; + cy.visit(urlList.collections); + let collection; + + collectionsSteps + .createCollection(collectionName, false, defaultChannel) + .then(collectionResp => { + collection = collectionResp; + collectionsSteps.assignProductsToCollection(name); + }) + .then(() => { + collectionsRequest.getCollection(collection.id, defaultChannel.slug); + }) + .then(resp => { + const isVisible = isCollectionVisible(resp, collection.id); + expect(isVisible).to.equal(false); + }); + }); + + it("should display collections", () => { + const collectionName = `${startsWith}${faker.random.number()}`; + let collection; + cy.visit(urlList.collections); + collectionsSteps + .createCollection(collectionName, true, defaultChannel) + .then(collectionResp => { + collection = collectionResp; + collectionsSteps.assignProductsToCollection(name); + collectionsRequest.getCollection(collection.id, defaultChannel.slug); + }) + .then(resp => { + const isVisible = isCollectionVisible(resp, collection.id); + expect(isVisible).to.equal(true); + }); + }); + it("should not display collection not set as available in channel", () => { + const collectionName = `${startsWith}${faker.random.number()}`; + let collection; + + channelsUtils + .createChannel({ name: collectionName }) + .then(() => { + productRequest.updateChannelInProduct( + productsUtils.getCreatedProduct().id, + channelsUtils.getCreatedChannel().id + ); + }) + .then(() => { + cy.visit(urlList.collections); + collectionsSteps.createCollection( + collectionName, + true, + channelsUtils.getCreatedChannel() + ); + }) + .then(collectionResp => { + collection = collectionResp; + collectionsSteps.assignProductsToCollection(name); + collectionsRequest.getCollection(collection.id, defaultChannel.slug); + }) + .then(resp => { + const isVisible = isCollectionVisible(resp, collection.id); + expect(isVisible).to.equal(false); + }); + }); + it("should display products hidden in listing", () => { + // Products "hidden in listings" are not displayed in Category listings or search results, + // but are listed on Collections + const randomName = `${startsWith}${faker.random.number()}`; + const hiddenProductUtils = new ProductsUtils(); + let collection; + + hiddenProductUtils.createProductInChannel({ + name: randomName, + channelId: defaultChannel.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + visibleInListings: false + }); + cy.visit(urlList.collections); + collectionsSteps + .createCollection(randomName, true, defaultChannel) + .then(collectionResp => { + collection = collectionResp; + collectionsSteps.assignProductsToCollection(randomName); + }) + .then(() => { + collectionsRequest.getCollection(collection.id, defaultChannel.slug); + }) + .then(resp => { + const isVisible = isProductInCollectionVisible( + resp, + hiddenProductUtils.getCreatedProduct().id + ); + expect(isVisible).to.equal(true); + }) + .then(() => { + search.searchInShop(hiddenProductUtils.getCreatedProduct().name); + }) + .then(resp => { + const isVisible = isProductVisibleInSearchResult( + resp, + hiddenProductUtils.getCreatedProduct().name + ); + expect(isVisible).to.equal(false); + }); + }); +}); diff --git a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js index aa33c504e..d7a86e084 100644 --- a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js +++ b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js @@ -1,5 +1,6 @@ import faker from "faker"; +import ProductDetails from "../../../apiRequests/storeFront/ProductDetails"; import ProductSteps from "../../../steps/products/productSteps"; import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; @@ -9,6 +10,7 @@ import { isProductAvailableForPurchase } from "../../../utils/storeFront/storeFr // describe("Products available in listings", () => { + const productDetails = new ProductDetails(); const shippingUtils = new ShippingUtils(); const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); @@ -73,14 +75,13 @@ describe("Products available in listings", () => { productSteps.updateProductIsAvailableForPurchase(productUrl, true); }) .then(() => { - isProductAvailableForPurchase( + productDetails.getProductDetails( productsUtils.getCreatedProduct().id, - defaultChannel.slug, - productName + defaultChannel.slug ); }) - .then(isVisibleResp => { - expect(isVisibleResp).to.be.eq(true); + .then(resp => { + expect(isProductAvailableForPurchase(resp)).to.be.eq(true); }); }); it("should update product to not available for purchase", () => { @@ -101,14 +102,13 @@ describe("Products available in listings", () => { productSteps.updateProductIsAvailableForPurchase(productUrl, false); }) .then(() => { - isProductAvailableForPurchase( + productDetails.getProductDetails( productsUtils.getCreatedProduct().id, - defaultChannel.slug, - productName + defaultChannel.slug ); }) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(false); + .then(resp => { + expect(isProductAvailableForPurchase(resp)).to.be.eq(false); }); }); }); diff --git a/cypress/integration/products/menageProducts/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js index e5661b7bf..ab5548a93 100644 --- a/cypress/integration/products/menageProducts/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -1,5 +1,6 @@ import faker from "faker"; +import ProductDetails from "../../../apiRequests/storeFront/ProductDetails"; import ProductSteps from "../../../steps/products/productSteps"; import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; @@ -8,6 +9,7 @@ import { isProductVisible } from "../../../utils/storeFront/storeFrontProductUti // describe("Published products", () => { + const productDetails = new ProductDetails(); const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); @@ -52,9 +54,10 @@ describe("Published products", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, true); - isProductVisible(product.id, defaultChannel.slug, productName); + productDetails.getProductDetails(product.id, defaultChannel.slug); }) - .then(isVisible => { + .then(resp => { + const isVisible = isProductVisible(resp, productName); expect(isVisible).to.be.eq(true); }); }); @@ -79,16 +82,18 @@ describe("Published products", () => { product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, false); - isProductVisible(product.id, defaultChannel.slug, productName); + productDetails.getProductDetails(product.id, defaultChannel.slug); }) - .then(isVisible => { + .then(resp => { + const isVisible = isProductVisible(resp, productName); expect(isVisible).to.be.eq(false); cy.loginInShop(); }) .then(() => { - isProductVisible(product.id, defaultChannel.slug, productName); + productDetails.getProductDetails(product.id, defaultChannel.slug); }) - .then(isVisible => { + .then(resp => { + const isVisible = isProductVisible(resp, productName); expect(isVisible).to.be.eq(true); }); }); diff --git a/cypress/integration/products/menageProducts/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js index e34e1c413..9d5d06c54 100644 --- a/cypress/integration/products/menageProducts/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -1,5 +1,6 @@ import faker from "faker"; +import Search from "../../../apiRequests/storeFront/Search"; import ProductSteps from "../../../steps/products/productSteps"; import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; @@ -8,6 +9,7 @@ import { isProductVisibleInSearchResult } from "../../../utils/storeFront/storeF // describe("Products displayed in listings", () => { + const search = new Search(); const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); @@ -52,9 +54,13 @@ describe("Products displayed in listings", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); - isProductVisibleInSearchResult(productName, defaultChannel.slug); + search.searchInShop(productName); }) - .then(isProductVisible => { + .then(resp => { + const isProductVisible = isProductVisibleInSearchResult( + resp, + productName + ); expect(isProductVisible).to.be.eq(true); }); }); @@ -78,17 +84,24 @@ describe("Products displayed in listings", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); - isProductVisibleInSearchResult(productName, defaultChannel.slug).then( - isProductVisible => { - expect(isProductVisible).to.be.eq(false); - } - ); + + search.searchInShop(productName).then(resp => { + const isProductVisible = isProductVisibleInSearchResult( + resp, + productName + ); + expect(isProductVisible).to.be.eq(false); + }); cy.loginInShop(); }) .then(() => { - isProductVisibleInSearchResult(productName, defaultChannel.slug); + search.searchInShop(productName); }) - .then(isProductVisible => { + .then(resp => { + const isProductVisible = isProductVisibleInSearchResult( + resp, + productName + ); expect(isProductVisible).to.be.eq(true); }); }); diff --git a/cypress/integration/products/products.js b/cypress/integration/products/products.js index 87960c269..f594d32d5 100644 --- a/cypress/integration/products/products.js +++ b/cypress/integration/products/products.js @@ -1,6 +1,6 @@ // import { LEFT_MENU_SELECTORS } from "../../elements/account/left-menu/left-menu-selectors"; -import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; +import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors"; import { urlList } from "../../url/urlList"; describe("Products", () => { diff --git a/cypress/steps/collectionsSteps.js b/cypress/steps/collectionsSteps.js new file mode 100644 index 000000000..ca0f72e9b --- /dev/null +++ b/cypress/steps/collectionsSteps.js @@ -0,0 +1,49 @@ +import { COLLECTION_SELECTORS } from "../elements/catalog/collection-selectors"; +import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/products/assign-products-selectors"; +import { MENAGE_CHANNEL_AVAILABILITY_FORM } from "../elements/channels/menage-channel-availability-form"; +import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; +class CollectionsSteps { + createCollection(collectionName, isPublished, channel) { + const publishedSelector = isPublished + ? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue + : MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse; + + cy.get(COLLECTION_SELECTORS.createCollectionButton) + .click() + .get(COLLECTION_SELECTORS.nameInput) + .type(collectionName) + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsMenageButton) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.allChannelsCheckbox) + .click(); + cy.contains(MENAGE_CHANNEL_AVAILABILITY_FORM.channelRow, channel.name) + .find(MENAGE_CHANNEL_AVAILABILITY_FORM.channelCheckbox) + .click() + .get(BUTTON_SELECTORS.submit) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsAvailabilityItem) + .click() + .get( + `${MENAGE_CHANNEL_AVAILABILITY_FORM.publishedCheckbox}${publishedSelector}` + ) + .click(); + cy.addAliasToGraphRequest("CreateCollection"); + cy.get(COLLECTION_SELECTORS.saveButton).click(); + return cy + .wait("@CreateCollection") + .its("response.body.data.collectionCreate.collection"); + } + assignProductsToCollection(productName) { + cy.get(COLLECTION_SELECTORS.addProductButton) + .click() + .get(ASSIGN_PRODUCTS_SELECTORS.searchInput) + .type(productName); + cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) + .find(ASSIGN_PRODUCTS_SELECTORS.checkbox) + .click(); + cy.addAliasToGraphRequest("CollectionAssignProduct"); + cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click(); + cy.wait("@CollectionAssignProduct"); + } +} +export default CollectionsSteps; diff --git a/cypress/steps/products/VariantsSteps.js b/cypress/steps/products/VariantsSteps.js index d1baba221..0234d5faf 100644 --- a/cypress/steps/products/VariantsSteps.js +++ b/cypress/steps/products/VariantsSteps.js @@ -1,4 +1,4 @@ -import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; +import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; class VariantsSteps { diff --git a/cypress/steps/products/productSteps.js b/cypress/steps/products/productSteps.js index 57fb4e90c..78d5870d1 100644 --- a/cypress/steps/products/productSteps.js +++ b/cypress/steps/products/productSteps.js @@ -1,4 +1,4 @@ -import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; +import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors"; class ProductSteps { valueTrue = PRODUCTS_SELECTORS.radioButtonsValueTrue; diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index c469ba6e6..995a67ccc 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -5,6 +5,7 @@ export const urlList = { homePage: "/", orders: "orders/", products: "products/", - warehouses: "warehouses/" + warehouses: "warehouses/", + collections: "collections/" }; export const productDetailsUrl = productId => `${urlList.products}${productId}`; diff --git a/cypress/utils/channelsUtils.js b/cypress/utils/channelsUtils.js index 81af09c5d..a67a1b404 100644 --- a/cypress/utils/channelsUtils.js +++ b/cypress/utils/channelsUtils.js @@ -2,6 +2,7 @@ import Channels from "../apiRequests/Channels"; class ChannelsUtils { channels = new Channels(); + createdChannel; deleteChannels(nameStartsWith) { this.channels.getChannels().then(resp => { @@ -37,5 +38,15 @@ class ChannelsUtils { })); }); } + createChannel({ isActive = true, name, slug = name, currencyCode = "PLN" }) { + return this.channels + .createChannel(isActive, name, slug, currencyCode) + .then( + resp => (this.createdChannel = resp.body.data.channelCreate.channel) + ); + } + getCreatedChannel() { + return this.createdChannel; + } } export default ChannelsUtils; diff --git a/cypress/utils/collectionsUtils.js b/cypress/utils/collectionsUtils.js new file mode 100644 index 000000000..bf80f36ec --- /dev/null +++ b/cypress/utils/collectionsUtils.js @@ -0,0 +1,15 @@ +import Collections from "../apiRequests/Collections"; + +class CollectionsUtils { + collectionsRequest = new Collections(); + + deleteProperCollections(startsWith) { + cy.deleteProperElements( + this.collectionsRequest.deleteCollection, + this.collectionsRequest.getCollections, + startsWith, + "collection" + ); + } +} +export default CollectionsUtils; diff --git a/cypress/utils/storeFront/collectionsUtils.js b/cypress/utils/storeFront/collectionsUtils.js new file mode 100644 index 000000000..278300ce9 --- /dev/null +++ b/cypress/utils/storeFront/collectionsUtils.js @@ -0,0 +1,11 @@ +export const isCollectionVisible = (resp, collectionId) => { + const collection = resp.body.data.collection; + return collection !== null && collection.id === collectionId; +}; + +export const isProductInCollectionVisible = (resp, productId) => { + const productsList = resp.body.data.collection.products; + return ( + productsList.totalCount !== 0 && productsList.edges[0].node.id === productId + ); +}; diff --git a/cypress/utils/storeFront/storeFrontProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js index a02981716..54c3a1205 100644 --- a/cypress/utils/storeFront/storeFrontProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -1,35 +1,21 @@ import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; -import Search from "../../apiRequests/storeFront/Search"; -export const isProductVisible = (productId, channelSlug, name) => { - const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then(productDetailsResp => { - const product = productDetailsResp.body.data.product; - return product !== null && product.name === name; - }); +export const isProductVisible = (resp, name) => { + const product = resp.body.data.product; + return product !== null && product.name === name; }; -export const isProductAvailableForPurchase = (productId, channelSlug) => { - const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then( - productDetailsResp => - productDetailsResp.body.data.product.isAvailableForPurchase - ); +export const isProductAvailableForPurchase = resp => { + const product = resp.body.data.product; + return product.isAvailableForPurchase; }; -export const isProductVisibleInSearchResult = (productName, channelSlug) => { - const search = new Search(); - return search - .searchInShop(productName, channelSlug) - .then( - resp => - resp.body.data.products.totalCount !== 0 && - resp.body.data.products.edges[0].node.name === productName - ); +export const isProductVisibleInSearchResult = (resp, productName) => { + const productsList = resp.body.data.products; + return ( + productsList.totalCount !== 0 && + productsList.edges[0].node.name === productName + ); }; export const getProductVariants = (productId, channelSlug) => { diff --git a/src/collections/components/CollectionListPage/CollectionListPage.tsx b/src/collections/components/CollectionListPage/CollectionListPage.tsx index 31c89ad86..ddb5d1e78 100644 --- a/src/collections/components/CollectionListPage/CollectionListPage.tsx +++ b/src/collections/components/CollectionListPage/CollectionListPage.tsx @@ -55,6 +55,7 @@ const CollectionListPage: React.FC = ({ disabled={disabled} variant="contained" onClick={onAdd} + data-test-id="create-collection" > = props => { } toolbar={