add isVisible utils function
This commit is contained in:
parent
c9df58727b
commit
44a0a6555e
5 changed files with 68 additions and 48 deletions
|
@ -6,6 +6,7 @@ class Collections {
|
|||
slug
|
||||
name
|
||||
products(first:100){
|
||||
totalCount
|
||||
edges{
|
||||
node{
|
||||
id
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
23
cypress/utils/storeFront/utils.js
Normal file
23
cypress/utils/storeFront/utils.js
Normal 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;
|
||||
});
|
Loading…
Reference in a new issue