diff --git a/cypress/apiRequests/storeFront/Collections.js b/cypress/apiRequests/storeFront/Collections.js index 8bda6429e..54770701e 100644 --- a/cypress/apiRequests/storeFront/Collections.js +++ b/cypress/apiRequests/storeFront/Collections.js @@ -6,6 +6,7 @@ class Collections { slug name products(first:100){ + totalCount edges{ node{ id diff --git a/cypress/steps/collectionsSteps.js b/cypress/steps/collectionsSteps.js index a2eb97db8..ca0f72e9b 100644 --- a/cypress/steps/collectionsSteps.js +++ b/cypress/steps/collectionsSteps.js @@ -40,9 +40,10 @@ class CollectionsSteps { .type(productName); cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) .find(ASSIGN_PRODUCTS_SELECTORS.checkbox) - .click() - .get(ASSIGN_PRODUCTS_SELECTORS.submitButton) .click(); + cy.addAliasToGraphRequest("CollectionAssignProduct"); + cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click(); + cy.wait("@CollectionAssignProduct"); } } export default CollectionsSteps; diff --git a/cypress/utils/storeFront/collectionsUtils.js b/cypress/utils/storeFront/collectionsUtils.js index 57d50b252..e94345f70 100644 --- a/cypress/utils/storeFront/collectionsUtils.js +++ b/cypress/utils/storeFront/collectionsUtils.js @@ -1,24 +1,23 @@ import Collections from "../../apiRequests/storeFront/Collections"; +import { isVisible } from "./utils"; -export const isCollectionVisible = (collectionId, channelSlug) => { - const collectionsRequest = new Collections(); - return collectionsRequest - .getCollection(collectionId, channelSlug) - .then(resp => { - const collection = resp.body.data.collection; - return collection !== null && collection.id === collectionId; - }); -}; +const collectionsRequest = new Collections(); + +export const isCollectionVisible = (collectionId, channelSlug) => + isVisible({ + request: collectionsRequest.getCollection(collectionId, channelSlug), + respObjectKey: ["collection"], + responseValueKey: ["id"], + value: collectionId + }); export const isProductInCollectionVisible = ( collectionId, channelSlug, productId -) => { - const collectionsRequest = new Collections(); - return collectionsRequest - .getCollection(collectionId, channelSlug) - .then(resp => { - const product = resp.body.data.collection.products.edges[0].node; - return product !== null && product.id === productId; - }); -}; +) => + isVisible({ + request: collectionsRequest.getCollection(collectionId, channelSlug), + respObjectKey: ["collection", "products"], + responseValueKey: ["edges", 0, "node", "id"], + value: productId + }); diff --git a/cypress/utils/storeFront/storeFrontProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js index 854c3f79a..e020465e7 100644 --- a/cypress/utils/storeFront/storeFrontProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -1,32 +1,28 @@ import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; import Search from "../../apiRequests/storeFront/Search"; +import { isVisible } from "./utils"; -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; - }); -}; +const productDetails = new ProductDetails(); +const search = new Search(); -export const isProductAvailableForPurchase = (productId, channelSlug) => { - const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then( - productDetailsResp => - productDetailsResp.body.data.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 isProductVisible = (productId, channelSlug, name) => + isVisible({ + request: productDetails.getProductDetails(productId, channelSlug), + respObjectKey: ["product"], + responseValueKey: ["name"], + value: name + }); + +export const isProductAvailableForPurchase = (productId, channelSlug) => + isVisible({ + request: productDetails.getProductDetails(productId, channelSlug), + respObjectKey: ["product"], + responseValueKey: ["isAvailableForPurchase"] + }); +export const isProductVisibleInSearchResult = (productName, channelSlug) => + isVisible({ + request: search.searchInShop(productName, channelSlug), + respObjectKey: ["products"], + responseValueKey: ["edges", 0, "node", "name"], + value: productName + }); diff --git a/cypress/utils/storeFront/utils.js b/cypress/utils/storeFront/utils.js new file mode 100644 index 000000000..a16911fe4 --- /dev/null +++ b/cypress/utils/storeFront/utils.js @@ -0,0 +1,23 @@ +export const isVisible = ({ + request, + respObjectKey, + responseValueKey, + value = true +}) => + request.then(resp => { + resp = resp.body.data; + respObjectKey.forEach(element => { + resp = resp[element]; + }); + if (resp === null) { + return false; + } + if ("totalCount" in resp && resp.totalCount === 0) { + return false; + } + let respValue = resp; + responseValueKey.forEach(element => { + respValue = respValue[element]; + }); + return respValue === value; + });