diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index 09dca8bf6..b22ecf97b 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -88,19 +88,26 @@ class Product { price = 1, costPrice = 1 ) { + const channelListings = channelId + ? `channelListings:{ + channelId:"${channelId}" + price:"${price}" + costPrice:"${costPrice}" + }` + : ""; + const stocks = warehouseId + ? `stocks:{ + warehouse:"${warehouseId}" + quantity:${quantity} + }` + : ""; + const mutation = `mutation{ productVariantBulkCreate(product:"${productId}", variants:{ attributes:[] sku:"${sku}" - channelListings:{ - channelId:"${channelId}" - price:"${price}" - costPrice:"${costPrice}" - } - stocks:{ - warehouse:"${warehouseId}" - quantity:${quantity} - } + ${channelListings} + ${stocks} }){ productVariants{ id diff --git a/cypress/integration/channels.js b/cypress/integration/channels.js index 4b3e3354c..3176552ea 100644 --- a/cypress/integration/channels.js +++ b/cypress/integration/channels.js @@ -44,10 +44,13 @@ describe("Channels", () => { it("should create new channel", () => { const randomChannel = `${channelStartsWith} ${faker.random.number()}`; - cy.visit(urlList.channels).waitForGraph("Channels"); + cy.waitForGraph("Channels"); + cy.visit(urlList.channels); + cy.wait("Channels"); + cy.waitForGraph("Channel"); channelsSteps.createChannelByView(randomChannel, currency); // New channel should be visible in channels list - cy.waitForGraph("Channel") + cy.wait("@Channel") .get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList) .click() .get(CHANNELS_SELECTORS.channelsTable) diff --git a/cypress/integration/collections.js b/cypress/integration/collections.js index 8cc5cec26..0ce8c3ec2 100644 --- a/cypress/integration/collections.js +++ b/cypress/integration/collections.js @@ -1,10 +1,8 @@ // import faker from "faker"; -import { COLLECTION_SELECTORS } from "../elements/catalog/collection-selectors"; -import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/products/assign-products-selectors"; -import { MENAGE_CHANNEL_AVAILABILITY_FORM } from "../elements/channels/menage-channel-availability-form"; -import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; +import Product from "../apiRequests/Product"; +import CollectionsSteps from "../steps/collectionsSteps"; import { urlList } from "../url/urlList"; import ChannelsUtils from "../utils/channelsUtils"; import CollectionsUtils from "../utils/collectionsUtils"; @@ -12,10 +10,12 @@ import ProductsUtils from "../utils/productsUtils"; import ShippingUtils from "../utils/shippingUtils"; describe("Collections", () => { + const productRequest = new Product(); const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const collectionsUtils = new CollectionsUtils(); const shippingUtils = new ShippingUtils(); + const collectionsSteps = new CollectionsSteps(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; @@ -34,7 +34,6 @@ describe("Collections", () => { defaultChannel = channel; productsUtils.createTypeAttributeAndCategoryForProduct(name); }) - // .then(() => shippingUtils.createShipping(defaultChannel.id, name, )) .then(() => { const attribute = productsUtils.getAttribute(); const productType = productsUtils.getProductType(); @@ -54,67 +53,81 @@ describe("Collections", () => { beforeEach(() => { cy.clearSessionData().loginUserViaRequest(); - cy.visit(urlList.collections); }); it("should not display hidden collections", () => { const collectionName = `${startsWith}${faker.random.number()}`; + cy.visit(urlList.collections); - cy.get(COLLECTION_SELECTORS.createCollectionButton) - .click() - .get(COLLECTION_SELECTORS.nameInput) - .type(collectionName) - .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsMenageButton) - .click() - .get(MENAGE_CHANNEL_AVAILABILITY_FORM.allChannelsCheckbox) - .click(); - cy.contains( - MENAGE_CHANNEL_AVAILABILITY_FORM.channelRow, - defaultChannel.name - ) - .find(MENAGE_CHANNEL_AVAILABILITY_FORM.channelCheckbox) - .click() - .get(BUTTON_SELECTORS.submit) - .click() - .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsAvailabilityItem) - .click() - .get( - `${MENAGE_CHANNEL_AVAILABILITY_FORM.publishedCheckbox}${MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse}` - ) - .click() - .waitForGraph("CreateCollection") - .get(COLLECTION_SELECTORS.saveButton) - .click(); - collectionsUtils.getCreatedCollection().then(collection => { - cy.get(COLLECTION_SELECTORS.addProductButton) - .click() - .get(ASSIGN_PRODUCTS_SELECTORS.searchInput) - .type(name); - cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, name) - .find(ASSIGN_PRODUCTS_SELECTORS.checkbox) - .click() - .get(ASSIGN_PRODUCTS_SELECTORS.submitButton) - .click() - .loginInShop(); - collectionsUtils - .isCollectionVisible(collection.id, defaultChannel.slug) - .then(isVisible => expect(isVisible).to.equal(true)); - }); + collectionsSteps + .createCollection(collectionName, false, defaultChannel) + .then(collection => { + collectionsSteps.assignProductsToCollection(name); + collectionsUtils.isCollectionVisible( + collection.id, + defaultChannel.slug + ); + }) + .then(isVisible => expect(isVisible).to.equal(false)); + }); + + it("should display collections", () => { + const collectionName = `${startsWith}${faker.random.number()}`; + cy.visit(urlList.collections); + + collectionsSteps + .createCollection(collectionName, true, defaultChannel) + .then(collection => { + collectionsSteps.assignProductsToCollection(name); + collectionsUtils.isCollectionVisible( + collection.id, + defaultChannel.slug + ); + }) + .then(isVisible => expect(isVisible).to.equal(true)); + }); + xit("should not display unavailable in channel collections", () => { + channelsUtils.createChannel(true, name, name, "PLN").then(() => { + productRequest.updateChannelInProduct( + productsUtils.getCreatedProduct().id, + channelsUtils.getCreatedChannel().id + ); + }); + cy.visit(urlList.collections); + collectionsSteps + .createCollection(collectionName, true, channelsUtils.getCreatedChannel()) + .then(collection => { + collectionsSteps.assignProductsToCollection(name); + collectionsUtils.isCollectionVisible( + collection.id, + defaultChannel.slug + ); + }) + .then(isVisible => expect(isVisible).to.equal(true)); + }); + xit("should display products hidden in listing, only in collection", () => { + productsUtils.createProductInChannel( + name, + defaultChannel.id, + null, + null, + productsUtils.getProductType().id, + productsUtils.getAttribute().id, + productsUtils.getCategory().id, + 1 + ); + collectionsSteps + .createCollection(collectionName, true, defaultChannel) + .then(collection => { + collectionsSteps.assignProductsToCollection(name); + collectionsUtils.isProductInCollectionVisible( + collection.id, + defaultChannel.slug + ); + }) + .then(isVisible => { + expect(isVisible).to.equal(true); + // productsUtils.searchForProduct + }); }); - // xit("should display collections", () => { - // createVisibleCollection - // addProductToCollection - // checkIfCollectionIsNotDisplayed - // }); - // xit("should not display unavailable collections", () => { - // createunavailableCollection - // addProductToCollection - // checkIfCollectionIsNotDisplayed - // }); - // xit("should display products hidden in listing only in collection", () => { - // createHiddenInListingsProduct - // createVisibleCollection - // addProductToCollection - // checkIfCollectionIsNotDisplayed - // }); }); diff --git a/cypress/steps/collectionsSteps.js b/cypress/steps/collectionsSteps.js new file mode 100644 index 000000000..90ef78fa2 --- /dev/null +++ b/cypress/steps/collectionsSteps.js @@ -0,0 +1,49 @@ +import { COLLECTION_SELECTORS } from "../elements/catalog/collection-selectors"; +import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/products/assign-products-selectors"; +import { MENAGE_CHANNEL_AVAILABILITY_FORM } from "../elements/channels/menage-channel-availability-form"; +import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; +import CollectionsUtils from "../utils/collectionsUtils"; +class CollectionsSteps { + createCollection(collectionName, isPublished, channel) { + const publishedSelector = isPublished + ? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue + : MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse; + const collectionsUtils = new CollectionsUtils(); + + cy.get(COLLECTION_SELECTORS.createCollectionButton) + .click() + .get(COLLECTION_SELECTORS.nameInput) + .type(collectionName) + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsMenageButton) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.allChannelsCheckbox) + .click(); + cy.contains(MENAGE_CHANNEL_AVAILABILITY_FORM.channelRow, channel.name) + .find(MENAGE_CHANNEL_AVAILABILITY_FORM.channelCheckbox) + .click() + .get(BUTTON_SELECTORS.submit) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsAvailabilityItem) + .click() + .get( + `${MENAGE_CHANNEL_AVAILABILITY_FORM.publishedCheckbox}${publishedSelector}` + ) + .click() + .waitForGraph("CreateCollection") + .get(COLLECTION_SELECTORS.saveButton) + .click(); + return collectionsUtils.waitForCreateCollectionRequest(); + } + assignProductsToCollection(productName) { + cy.get(COLLECTION_SELECTORS.addProductButton) + .click() + .get(ASSIGN_PRODUCTS_SELECTORS.searchInput) + .type(productName); + cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) + .find(ASSIGN_PRODUCTS_SELECTORS.checkbox) + .click() + .get(ASSIGN_PRODUCTS_SELECTORS.submitButton) + .click(); + } +} +export default CollectionsSteps; diff --git a/cypress/utils/channelsUtils.js b/cypress/utils/channelsUtils.js index 81af09c5d..c5e9dc6d0 100644 --- a/cypress/utils/channelsUtils.js +++ b/cypress/utils/channelsUtils.js @@ -2,6 +2,7 @@ import Channels from "../apiRequests/Channels"; class ChannelsUtils { channels = new Channels(); + createdChannel; deleteChannels(nameStartsWith) { this.channels.getChannels().then(resp => { @@ -37,5 +38,15 @@ class ChannelsUtils { })); }); } + createChannel(isActive, name, slug, currencyCode) { + return this.channels + .createChannel(isActive, name, slug, currencyCode) + .then( + resp => (this.createdChannel = resp.body.data.channelCreate.channel) + ); + } + getCreatedChannel() { + return channel; + } } export default ChannelsUtils; diff --git a/cypress/utils/collectionsUtils.js b/cypress/utils/collectionsUtils.js index 41518ceea..b510af4fc 100644 --- a/cypress/utils/collectionsUtils.js +++ b/cypress/utils/collectionsUtils.js @@ -8,10 +8,10 @@ class CollectionsUtils { .getCollection(collectionId, channelSlug) .then(resp => { const collection = resp.body[0].data.collection; - return collection && collection.id === collectionId; + return collection !== null && collection.id === collectionId; }); } - getCreatedCollection() { + waitForCreateCollectionRequest() { return cy .wait(`@CreateCollection`) .its("response.body.data.collectionCreate.collection");