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
|
slug
|
||||||
name
|
name
|
||||||
products(first:100){
|
products(first:100){
|
||||||
|
totalCount
|
||||||
edges{
|
edges{
|
||||||
node{
|
node{
|
||||||
id
|
id
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
export const isCollectionVisible = (collectionId, channelSlug) =>
|
||||||
.getCollection(collectionId, channelSlug)
|
isVisible({
|
||||||
.then(resp => {
|
request: collectionsRequest.getCollection(collectionId, channelSlug),
|
||||||
const collection = resp.body.data.collection;
|
respObjectKey: ["collection"],
|
||||||
return collection !== null && collection.id === collectionId;
|
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;
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
|
@ -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();
|
const search = new Search();
|
||||||
return productDetails
|
|
||||||
.getProductDetails(productId, channelSlug)
|
export const isProductVisible = (productId, channelSlug, name) =>
|
||||||
.then(productDetailsResp => {
|
isVisible({
|
||||||
const product = productDetailsResp.body.data.product;
|
request: productDetails.getProductDetails(productId, channelSlug),
|
||||||
return product !== null && product.name === name;
|
respObjectKey: ["product"],
|
||||||
|
responseValueKey: ["name"],
|
||||||
|
value: name
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
export const isProductAvailableForPurchase = (productId, channelSlug) => {
|
export const isProductAvailableForPurchase = (productId, channelSlug) =>
|
||||||
const productDetails = new ProductDetails();
|
isVisible({
|
||||||
return productDetails
|
request: productDetails.getProductDetails(productId, channelSlug),
|
||||||
.getProductDetails(productId, channelSlug)
|
respObjectKey: ["product"],
|
||||||
.then(
|
responseValueKey: ["isAvailableForPurchase"]
|
||||||
productDetailsResp =>
|
});
|
||||||
productDetailsResp.body.data.product.isAvailableForPurchase
|
export const isProductVisibleInSearchResult = (productName, channelSlug) =>
|
||||||
);
|
isVisible({
|
||||||
};
|
request: search.searchInShop(productName, channelSlug),
|
||||||
export const isProductVisibleInSearchResult = (productName, channelSlug) => {
|
respObjectKey: ["products"],
|
||||||
const search = new Search();
|
responseValueKey: ["edges", 0, "node", "name"],
|
||||||
return search
|
value: productName
|
||||||
.searchInShop(productName, channelSlug)
|
});
|
||||||
.then(
|
|
||||||
resp =>
|
|
||||||
resp.body.data.products.totalCount !== 0 &&
|
|
||||||
resp.body.data.products.edges[0].node.name === 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