diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index e7e0c11d7..035c6f083 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -27,7 +27,8 @@ class Product { productId, channelId, isPublished, - isAvailableForPurchase + isAvailableForPurchase, + visibleInListings ) { const mutation = `mutation{ productChannelListingUpdate(id:"${productId}", @@ -36,7 +37,7 @@ class Product { channelId:"${channelId}" isPublished:${isPublished} isAvailableForPurchase:${isAvailableForPurchase} - visibleInListings:true + visibleInListings:${visibleInListings} } }){ product{ diff --git a/cypress/elements/catalog/product-selectors.js b/cypress/elements/catalog/product-selectors.js index b61b38a11..a4d1b6437 100644 --- a/cypress/elements/catalog/product-selectors.js +++ b/cypress/elements/catalog/product-selectors.js @@ -23,5 +23,6 @@ export const PRODUCTS_SELECTORS = { channelAvailabilityList: "ul[role='menu']", goBackButton: "[data-test-id='app-header-back-button']", assignedChannels: "[data-test='channel-availability-item']", - publishedRadioButton: "[role=radiogroup]" + publishedRadioButton: "[role=radiogroup]", + visibleInListingsButton: "[class*='MuiFormControlLabel']" }; diff --git a/cypress/fixtures/addresses.json b/cypress/fixtures/addresses.json index 5a346904f..08fad0466 100644 --- a/cypress/fixtures/addresses.json +++ b/cypress/fixtures/addresses.json @@ -1,5 +1,13 @@ { - "plAddress":{ + "plAddress": { + "companyName": "Test3", + "streetAddress1": "Smolna", + "streetAddress2": "13/1", + "city": "Wrocław", + "postalCode": "53-346", + "country": "PL", + "countryArea": "Dolny Śląsk", + "phone": "123456787", "currency": "PLN" } } \ No newline at end of file diff --git a/cypress/integration/products/availableForPurchase.js b/cypress/integration/products/availableForPurchase.js index 1aa2c3685..18a73cd29 100644 --- a/cypress/integration/products/availableForPurchase.js +++ b/cypress/integration/products/availableForPurchase.js @@ -33,8 +33,8 @@ describe("Products", () => { shippingUtils.deleteShipping(startsWith); productsUtils.deleteProducts(startsWith); - channelsUtils.findDefaultChannel().then(() => { - defaultChannel = channelsUtils.getDefaultChannel(); + channelsUtils.getDefaultChannel().then(channel => { + defaultChannel = channel; cy.fixture("addresses").then(json => { shippingUtils .createShipping(defaultChannel, name, json.plAddress, 10) @@ -66,15 +66,18 @@ describe("Products", () => { productTypeId, attributeId, categoryId, - defaultChannel, + defaultChannel.id, true, false, + true, warehouseId, 10, 10 ) .then(() => { - const productUrl = `${URL_LIST.products}${productsUtils.getCreatedProductId}`; + const productUrl = `${ + URL_LIST.products + }${productsUtils.getCreatedProductId()}`; cy.visit(productUrl) .get(PRODUCTS_SELECTORS.assignedChannels) .click() @@ -87,7 +90,7 @@ describe("Products", () => { .get("@shopUrl") .then(shopUrl => { cy.visit(shopUrl); - searchSteps.searchFor(name); + searchSteps.searchFor(productName); cy.get(SEARCH_SELECTORS.productItem) .contains(productName) .click() @@ -98,4 +101,45 @@ describe("Products", () => { }); }); }); + it("shouldn't be possible to add to cart not available for purchase product", () => { + const productName = `${startsWith}${faker.random.number()}`; + productsUtils + .createProductInChannel( + productName, + productTypeId, + attributeId, + categoryId, + defaultChannel.id, + true, + true, + true, + warehouseId, + 10, + 10 + ) + .then(() => { + const productUrl = `${ + URL_LIST.products + }${productsUtils.getCreatedProductId()}`; + cy.visit(productUrl) + .get(PRODUCTS_SELECTORS.assignedChannels) + .click() + .get(PRODUCTS_SELECTORS.publishedRadioButton) + .contains("Niedostępne do zakupu") + .click() + .get(PRODUCTS_SELECTORS.saveBtn) + .click() + .waitForGraph("ProductChannelListingUpdate") + .get("@shopUrl") + .then(shopUrl => { + cy.visit(shopUrl); + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem) + .contains(productName) + .click() + .get(PRODUCTS_DETAILS_SELECTORS.addToCartButton) + .should("be.disabled"); + }); + }); + }); }); diff --git a/cypress/integration/products/publish.js b/cypress/integration/products/publish.js index ebd7588fc..aa274dee4 100644 --- a/cypress/integration/products/publish.js +++ b/cypress/integration/products/publish.js @@ -39,7 +39,7 @@ describe("Products", () => { .its("body.data.shop.domain.url") .as("shopUrl"); }); - xit("should display on frontend only published products", () => { + it("should display on frontend only published products", () => { const productName = `${startsWith}${faker.random.number()}`; channelsUtils.getDefaultChannel().then(defaultChannel => { productsUtils @@ -50,7 +50,8 @@ describe("Products", () => { categoryId, defaultChannel.id, false, - false + false, + true ) .then(() => { cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) @@ -65,8 +66,8 @@ describe("Products", () => { .get("@shopUrl") .then(shopUrl => { cy.visit(shopUrl); - searchSteps.searchFor(name); - cy.get(SEARCH_SELECTORS.productItem).contains(name); + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem).contains(productName); }); }); }); @@ -82,7 +83,8 @@ describe("Products", () => { categoryId, defaultChannel.id, true, - false + false, + true ) .then(() => { cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) @@ -97,13 +99,13 @@ describe("Products", () => { .get("@shopUrl") .then(shopUrl => { cy.visit(shopUrl); - searchSteps.searchFor(name); + searchSteps.searchFor(productName); cy.get(SEARCH_SELECTORS.productItem).should("not.exist"); }); }); }); }); - xit("should display not published product for staff member", () => { + it("should display not published product for staff member", () => { const productName = `${startsWith}${faker.random.number()}`; channelsUtils.getDefaultChannel().then(defaultChannel => { productsUtils @@ -114,7 +116,8 @@ describe("Products", () => { categoryId, defaultChannel.id, true, - false + false, + true ) .then(() => { cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) @@ -131,8 +134,8 @@ describe("Products", () => { cy.visit(shopUrl) .loginInShop() .then(() => { - searchSteps.searchFor(name); - cy.get(SEARCH_SELECTORS.productItem).contains(name); + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem).contains(productName); }); }); }); diff --git a/cypress/integration/products/showInListings.js b/cypress/integration/products/showInListings.js new file mode 100644 index 000000000..a4a67fe72 --- /dev/null +++ b/cypress/integration/products/showInListings.js @@ -0,0 +1,144 @@ +import faker from "faker"; + +import ShopInfo from "../../apiRequests/ShopInfo"; +import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; +import { SEARCH_SELECTORS } from "../../elements/frontend-elements/search-selectors"; +import SearchSteps from "../../steps/frontendSteps/searchSteps"; +import { URL_LIST } from "../../url/url-list"; +import ChannelsUtils from "../../utils/channelsUtils"; +import ProductsUtils from "../../utils/productsUtils"; + +// +describe("Products", () => { + const channelsUtils = new ChannelsUtils(); + const productsUtils = new ProductsUtils(); + const searchSteps = new SearchSteps(); + + const shopInfo = new ShopInfo(); + + const startsWith = "Cy-"; + const name = `${startsWith}${faker.random.number()}`; + let productTypeId; + let attributeId; + let categoryId; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + productsUtils.deleteProducts(startsWith); + productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { + productTypeId = productsUtils.getProductTypeId(); + attributeId = productsUtils.getAttributeId(); + categoryId = productsUtils.getCategoryId(); + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + shopInfo + .getShopInfo() + .its("body.data.shop.domain.url") + .as("shopUrl"); + }); + it("should display on frontend only visible in listings products", () => { + const productName = `${startsWith}${faker.random.number()}`; + channelsUtils.getDefaultChannel().then(defaultChannel => { + productsUtils + .createProductInChannel( + productName, + productTypeId, + attributeId, + categoryId, + defaultChannel.id, + true, + false, + false + ) + .then(() => { + cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) + .get(PRODUCTS_SELECTORS.assignedChannels) + .click() + .get(PRODUCTS_SELECTORS.visibleInListingsButton) + .contains("Wyświetlaj na liście produktów") + .click() + .get(PRODUCTS_SELECTORS.saveBtn) + .click() + .waitForGraph("ProductChannelListingUpdate") + .get("@shopUrl") + .then(shopUrl => { + cy.visit(shopUrl); + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem).contains(productName); + }); + }); + }); + }); + it("shouldn't display not visible in listing product for unlogged user", () => { + const productName = `${startsWith}${faker.random.number()}`; + channelsUtils.getDefaultChannel().then(defaultChannel => { + productsUtils + .createProductInChannel( + productName, + productTypeId, + attributeId, + categoryId, + defaultChannel.id, + true, + false, + true + ) + .then(() => { + cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) + .get(PRODUCTS_SELECTORS.assignedChannels) + .click() + .get(PRODUCTS_SELECTORS.visibleInListingsButton) + .contains("Wyświetlaj na liście produktów") + .click() + .get(PRODUCTS_SELECTORS.saveBtn) + .click() + .waitForGraph("ProductChannelListingUpdate") + .get("@shopUrl") + .then(shopUrl => { + cy.visit(shopUrl); + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem).should("not.exist"); + }); + }); + }); + }); + it("should display not visible in listing product for staff member", () => { + const productName = `${startsWith}${faker.random.number()}`; + channelsUtils.getDefaultChannel().then(defaultChannel => { + productsUtils + .createProductInChannel( + productName, + productTypeId, + attributeId, + categoryId, + defaultChannel.id, + true, + false, + true + ) + .then(() => { + cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) + .get(PRODUCTS_SELECTORS.assignedChannels) + .click() + .get(PRODUCTS_SELECTORS.visibleInListingsButton) + .contains("Wyświetlaj na liście produktów") + .click() + .get(PRODUCTS_SELECTORS.saveBtn) + .click() + .waitForGraph("ProductChannelListingUpdate") + .get("@shopUrl") + .then(shopUrl => { + cy.visit(shopUrl) + .loginInShop() + .then(() => { + searchSteps.searchFor(productName); + cy.get(SEARCH_SELECTORS.productItem).contains(productName); + }); + }); + }); + }); + }); +}); diff --git a/cypress/utils/channelsUtils.js b/cypress/utils/channelsUtils.js index 7e1e58973..dbb053c6e 100644 --- a/cypress/utils/channelsUtils.js +++ b/cypress/utils/channelsUtils.js @@ -3,8 +3,6 @@ import Channels from "../apiRequests/Channels"; class ChannelsUtils { channels = new Channels(); - defaultChannel; - deleteChannels(nameStartsWith) { this.channels.getChannels().then(resp => { const channelsArray = new Set(resp.body.data.channels); @@ -28,7 +26,7 @@ class ChannelsUtils { } }); } - findDefaultChannel() { + getDefaultChannel() { return this.channels.getChannels().then(resp => { const channelsArray = resp.body.data.channels; return (this.defaultChannel = channelsArray.find(function( @@ -38,8 +36,5 @@ class ChannelsUtils { })); }); } - getDefaultChannel() { - return this.defaultChannel; - } } export default ChannelsUtils; diff --git a/cypress/utils/productsUtils.js b/cypress/utils/productsUtils.js index eda29a95b..914e51aaa 100644 --- a/cypress/utils/productsUtils.js +++ b/cypress/utils/productsUtils.js @@ -42,6 +42,7 @@ class ProductsUtils { channelId, isPublished, isAvailableForPurchase, + visibleInListings, warehouseId, quantityInWarehouse, price @@ -57,7 +58,8 @@ class ProductsUtils { this.createdProductId, channelId, isPublished, - isAvailableForPurchase + isAvailableForPurchase, + visibleInListings ) .then(() => product