add frontShop request
This commit is contained in:
parent
2a9e420420
commit
9278208639
8 changed files with 61 additions and 67 deletions
|
@ -1,13 +0,0 @@
|
||||||
class ShopInfo {
|
|
||||||
getShopInfo() {
|
|
||||||
const query = `query{
|
|
||||||
shop{
|
|
||||||
domain{
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`;
|
|
||||||
return cy.sendRequestWithQuery(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default ShopInfo;
|
|
|
@ -1,3 +0,0 @@
|
||||||
export const CART_SELECTORS = {
|
|
||||||
productInCart: "[data-test='cartRow']"
|
|
||||||
};
|
|
|
@ -1,3 +0,0 @@
|
||||||
export const PRODUCTS_DETAILS_SELECTORS = {
|
|
||||||
addToCartButton: "[data-test='addProductToCartButton']"
|
|
||||||
};
|
|
|
@ -1,5 +0,0 @@
|
||||||
export const SEARCH_SELECTORS = {
|
|
||||||
searchButton: "[data-test='menuSearchOverlayLink']",
|
|
||||||
searchInputField: "[placeholder='search']",
|
|
||||||
productItem: ".search__products__item"
|
|
||||||
};
|
|
|
@ -1,11 +1,6 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
import ShopInfo from "../../apiRequests/ShopInfo";
|
|
||||||
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
|
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
|
||||||
import { CART_SELECTORS } from "../../elements/frontend-elements/cart-selectors";
|
|
||||||
import { PRODUCTS_DETAILS_SELECTORS } from "../../elements/frontend-elements/product-details-selectors";
|
|
||||||
import { SEARCH_SELECTORS } from "../../elements/frontend-elements/search-selectors";
|
|
||||||
import SearchSteps from "../../steps/frontendSteps/searchSteps";
|
|
||||||
import { URL_LIST } from "../../url/url-list";
|
import { URL_LIST } from "../../url/url-list";
|
||||||
import ChannelsUtils from "../../utils/channelsUtils";
|
import ChannelsUtils from "../../utils/channelsUtils";
|
||||||
import ProductsUtils from "../../utils/productsUtils";
|
import ProductsUtils from "../../utils/productsUtils";
|
||||||
|
@ -16,9 +11,6 @@ describe("Products", () => {
|
||||||
const shippingUtils = new ShippingUtils();
|
const shippingUtils = new ShippingUtils();
|
||||||
const channelsUtils = new ChannelsUtils();
|
const channelsUtils = new ChannelsUtils();
|
||||||
const productsUtils = new ProductsUtils();
|
const productsUtils = new ProductsUtils();
|
||||||
const searchSteps = new SearchSteps();
|
|
||||||
|
|
||||||
const shopInfo = new ShopInfo();
|
|
||||||
|
|
||||||
const startsWith = "Cy-";
|
const startsWith = "Cy-";
|
||||||
const name = `${startsWith}${faker.random.number()}`;
|
const name = `${startsWith}${faker.random.number()}`;
|
||||||
|
@ -52,10 +44,6 @@ describe("Products", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearSessionData().loginUserViaRequest();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
shopInfo
|
|
||||||
.getShopInfo()
|
|
||||||
.its("body.data.shop.domain.url")
|
|
||||||
.as("shopUrl");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be possible to add to cart available for purchase product", () => {
|
it("should be possible to add to cart available for purchase product", () => {
|
||||||
|
@ -87,21 +75,19 @@ describe("Products", () => {
|
||||||
.get(PRODUCTS_SELECTORS.saveBtn)
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
||||||
.click()
|
.click()
|
||||||
.waitForGraph("ProductChannelListingUpdate")
|
.waitForGraph("ProductChannelListingUpdate")
|
||||||
.get("@shopUrl")
|
.getProductDetails(
|
||||||
.then(shopUrl => {
|
productsUtils.getCreatedProductId(),
|
||||||
cy.visit(shopUrl);
|
defaultChannel.slug
|
||||||
searchSteps.searchFor(productName);
|
)
|
||||||
cy.get(SEARCH_SELECTORS.productItem)
|
.then(productDetailsResp => {
|
||||||
.contains(productName)
|
expect(productDetailsResp.body[0].data.product.name).to.equal(
|
||||||
.click()
|
productName
|
||||||
.get(PRODUCTS_DETAILS_SELECTORS.addToCartButton)
|
);
|
||||||
.click()
|
// expect(productDetailsResp.body[0].data.product.isAvailableForPurchase).to.be.true
|
||||||
.get(CART_SELECTORS.productInCart)
|
|
||||||
.contains(productName);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("shouldn't be possible to add to cart not available for purchase product", () => {
|
xit("shouldn't be possible to add to cart not available for purchase product", () => {
|
||||||
const productName = `${startsWith}${faker.random.number()}`;
|
const productName = `${startsWith}${faker.random.number()}`;
|
||||||
productsUtils
|
productsUtils
|
||||||
.createProductInChannel(
|
.createProductInChannel(
|
||||||
|
@ -131,14 +117,15 @@ describe("Products", () => {
|
||||||
.click()
|
.click()
|
||||||
.waitForGraph("ProductChannelListingUpdate")
|
.waitForGraph("ProductChannelListingUpdate")
|
||||||
.get("@shopUrl")
|
.get("@shopUrl")
|
||||||
.then(shopUrl => {
|
.getProductDetails(
|
||||||
cy.visit(shopUrl);
|
productsUtils.getCreatedProductId(),
|
||||||
searchSteps.searchFor(productName);
|
defaultChannel.slug
|
||||||
cy.get(SEARCH_SELECTORS.productItem)
|
)
|
||||||
.contains(productName)
|
.then(productDetailsResp => {
|
||||||
.click()
|
expect(productDetailsResp.body[0].data.product.name).to.equal(
|
||||||
.get(PRODUCTS_DETAILS_SELECTORS.addToCartButton)
|
productName
|
||||||
.should("be.disabled");
|
);
|
||||||
|
// expect(productDetailsResp.body[0].data.product.isAvailableForPurchase).to.be.false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
import { SEARCH_SELECTORS } from "../../elements/frontend-elements/search-selectors";
|
|
||||||
|
|
||||||
class SearchSteps {
|
|
||||||
searchFor(query) {
|
|
||||||
cy.get(SEARCH_SELECTORS.searchButton)
|
|
||||||
.click()
|
|
||||||
.get(SEARCH_SELECTORS.searchInputField)
|
|
||||||
.type(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default SearchSteps;
|
|
41
cypress/support/frontShop/index.js
Normal file
41
cypress/support/frontShop/index.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* eslint-disable sort-keys */
|
||||||
|
|
||||||
|
Cypress.Commands.add("searchInShop", searchQuery =>
|
||||||
|
cy.request({
|
||||||
|
method: "POST",
|
||||||
|
url: Cypress.env("API_URI"),
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
operationName: "SearchProducts",
|
||||||
|
variables: {
|
||||||
|
attributes: {},
|
||||||
|
channel: "default-channel",
|
||||||
|
pageSize: 6,
|
||||||
|
priceGte: null,
|
||||||
|
priceLte: null,
|
||||||
|
query: searchQuery,
|
||||||
|
sortBy: null
|
||||||
|
},
|
||||||
|
query:
|
||||||
|
"fragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery SearchProducts($query: String!, $channel: String!, $attributes: [AttributeInput], $pageSize: Int, $sortBy: ProductOrder, $after: String) {\n products(channel: $channel, filter: {search: $query, attributes: $attributes}, first: $pageSize, sortBy: $sortBy, after: $after) {\n totalCount\n edges {\n node {\n ...ProductPricingField\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n category {\n id\n name\n __typename\n }\n __typename\n }\n __typename\n }\n pageInfo {\n endCursor\n hasNextPage\n __typename\n }\n __typename\n }\n attributes(filter: {filterableInStorefront: true}, first: 100) {\n edges {\n node {\n id\n name\n slug\n values {\n id\n name\n slug\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n}\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
Cypress.Commands.add("getProductDetails", (productId, channelId) =>
|
||||||
|
cy.request({
|
||||||
|
method: "POST",
|
||||||
|
url: Cypress.env("API_URI"),
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
operationName: "ProductDetails",
|
||||||
|
variables: {
|
||||||
|
channel: channelId,
|
||||||
|
id: productId
|
||||||
|
},
|
||||||
|
query:
|
||||||
|
"fragment BasicProductFields on Product {\n id\n name\n thumbnail {\n url\n alt\n __typename\n }\n thumbnail2x: thumbnail(size: 510) {\n url\n __typename\n }\n __typename\n}\n\nfragment SelectedAttributeFields on SelectedAttribute {\n attribute {\n id\n name\n __typename\n }\n values {\n id\n name\n __typename\n }\n __typename\n}\n\nfragment Price on TaxedMoney {\n gross {\n amount\n currency\n __typename\n }\n net {\n amount\n currency\n __typename\n }\n __typename\n}\n\nfragment ProductVariantFields on ProductVariant {\n id\n sku\n name\n quantityAvailable(countryCode: $countryCode)\n images {\n id\n url\n alt\n __typename\n }\n pricing {\n onSale\n priceUndiscounted {\n ...Price\n __typename\n }\n price {\n ...Price\n __typename\n }\n __typename\n }\n attributes(variantSelection: VARIANT_SELECTION) {\n attribute {\n id\n name\n slug\n __typename\n }\n values {\n id\n name\n value: name\n __typename\n }\n __typename\n }\n __typename\n}\n\nfragment ProductPricingField on Product {\n pricing {\n onSale\n priceRangeUndiscounted {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n priceRange {\n start {\n ...Price\n __typename\n }\n stop {\n ...Price\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery ProductDetails($id: ID!, $channel: String, $countryCode: CountryCode) {\n product(id: $id, channel: $channel) {\n ...BasicProductFields\n ...ProductPricingField\n description\n category {\n id\n name\n products(first: 3, channel: $channel) {\n edges {\n node {\n ...BasicProductFields\n ...ProductPricingField\n __typename\n }\n __typename\n }\n __typename\n }\n __typename\n }\n images {\n id\n alt\n url\n __typename\n }\n attributes {\n ...SelectedAttributeFields\n __typename\n }\n variants {\n ...ProductVariantFields\n __typename\n }\n seoDescription\n seoTitle\n isAvailable\n isAvailableForPurchase\n availableForPurchase\n __typename\n }\n}\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
|
@ -1,4 +1,5 @@
|
||||||
import "./user";
|
import "./user";
|
||||||
|
import "./frontShop";
|
||||||
|
|
||||||
Cypress.Commands.add("clearSessionData", () => {
|
Cypress.Commands.add("clearSessionData", () => {
|
||||||
// Because of known cypress bug, not all local storage data are cleared.
|
// Because of known cypress bug, not all local storage data are cleared.
|
||||||
|
|
Loading…
Reference in a new issue