add isVisible utils function

This commit is contained in:
Karolina Rakoczy 2021-03-04 13:35:45 +01:00
parent c9df58727b
commit 44a0a6555e
5 changed files with 68 additions and 48 deletions

View file

@ -6,6 +6,7 @@ class Collections {
slug slug
name name
products(first:100){ products(first:100){
totalCount
edges{ edges{
node{ node{
id id

View file

@ -40,9 +40,10 @@ class CollectionsSteps {
.type(productName); .type(productName);
cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName)
.find(ASSIGN_PRODUCTS_SELECTORS.checkbox) .find(ASSIGN_PRODUCTS_SELECTORS.checkbox)
.click()
.get(ASSIGN_PRODUCTS_SELECTORS.submitButton)
.click(); .click();
cy.addAliasToGraphRequest("CollectionAssignProduct");
cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click();
cy.wait("@CollectionAssignProduct");
} }
} }
export default CollectionsSteps; export default CollectionsSteps;

View file

@ -1,24 +1,23 @@
import Collections from "../../apiRequests/storeFront/Collections"; import Collections from "../../apiRequests/storeFront/Collections";
import { isVisible } from "./utils";
export const isCollectionVisible = (collectionId, channelSlug) => {
const collectionsRequest = new Collections(); const collectionsRequest = new Collections();
return collectionsRequest
.getCollection(collectionId, channelSlug) export const isCollectionVisible = (collectionId, channelSlug) =>
.then(resp => { isVisible({
const collection = resp.body.data.collection; request: collectionsRequest.getCollection(collectionId, channelSlug),
return collection !== null && collection.id === collectionId; respObjectKey: ["collection"],
responseValueKey: ["id"],
value: collectionId
}); });
};
export const isProductInCollectionVisible = ( export const isProductInCollectionVisible = (
collectionId, collectionId,
channelSlug, channelSlug,
productId productId
) => { ) =>
const collectionsRequest = new Collections(); isVisible({
return collectionsRequest request: collectionsRequest.getCollection(collectionId, channelSlug),
.getCollection(collectionId, channelSlug) respObjectKey: ["collection", "products"],
.then(resp => { responseValueKey: ["edges", 0, "node", "id"],
const product = resp.body.data.collection.products.edges[0].node; value: productId
return product !== null && product.id === productId;
}); });
};

View file

@ -1,32 +1,28 @@
import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; import ProductDetails from "../../apiRequests/storeFront/ProductDetails";
import Search from "../../apiRequests/storeFront/Search"; import Search from "../../apiRequests/storeFront/Search";
import { isVisible } from "./utils";
export const isProductVisible = (productId, channelSlug, name) => {
const productDetails = new ProductDetails(); 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 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(); const search = new Search();
return search
.searchInShop(productName, channelSlug) export const isProductVisible = (productId, channelSlug, name) =>
.then( isVisible({
resp => request: productDetails.getProductDetails(productId, channelSlug),
resp.body.data.products.totalCount !== 0 && respObjectKey: ["product"],
resp.body.data.products.edges[0].node.name === productName 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
});

View file

@ -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;
});