saleor-dashboard/cypress/integration/collections.js

155 lines
5 KiB
JavaScript
Raw Normal View History

2021-02-18 09:00:08 +00:00
// <reference types="cypress" />
import faker from "faker";
2021-02-22 12:10:51 +00:00
import Product from "../apiRequests/Product";
import CollectionsSteps from "../steps/collectionsSteps";
2021-02-18 09:00:08 +00:00
import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils";
import CollectionsUtils from "../utils/collectionsUtils";
import ProductsUtils from "../utils/productsUtils";
2021-02-19 12:41:40 +00:00
import ShippingUtils from "../utils/shippingUtils";
2021-02-24 13:21:19 +00:00
import StoreFrontCollectionUtils from "../utils/storeFront/collectionsUtils";
import StoreFrontProductUtils from "../utils/storeFront/storeFrontProductUtils";
2021-02-18 09:00:08 +00:00
describe("Collections", () => {
2021-02-22 12:10:51 +00:00
const productRequest = new Product();
2021-02-18 09:00:08 +00:00
const channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
2021-02-24 13:21:19 +00:00
const storeFrontProductUtils = new StoreFrontProductUtils();
2021-02-19 11:08:10 +00:00
const collectionsUtils = new CollectionsUtils();
2021-02-24 13:21:19 +00:00
const storeFrontCollectionUtils = new StoreFrontCollectionUtils();
2021-02-19 12:41:40 +00:00
const shippingUtils = new ShippingUtils();
2021-02-22 12:10:51 +00:00
const collectionsSteps = new CollectionsSteps();
2021-02-18 09:00:08 +00:00
const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`;
2021-02-24 13:21:19 +00:00
let attribute;
let productType;
let category;
2021-02-18 09:00:08 +00:00
let defaultChannel;
before(() => {
cy.clearSessionData().loginUserViaRequest();
2021-02-19 11:08:10 +00:00
productsUtils.deleteProperProducts(startsWith);
2021-02-19 12:41:40 +00:00
collectionsUtils.deleteProperCollections(startsWith);
shippingUtils.deleteShipping(startsWith);
2021-02-19 11:08:10 +00:00
2021-02-18 09:00:08 +00:00
channelsUtils
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createTypeAttributeAndCategoryForProduct(name);
})
.then(() => {
2021-02-24 13:21:19 +00:00
attribute = productsUtils.getAttribute();
productType = productsUtils.getProductType();
category = productsUtils.getCategory();
productsUtils.createProductInChannel({
2021-02-18 09:00:08 +00:00
name,
2021-02-24 13:21:19 +00:00
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id
});
2021-02-18 09:00:08 +00:00
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should not display hidden collections", () => {
const collectionName = `${startsWith}${faker.random.number()}`;
2021-02-22 12:10:51 +00:00
cy.visit(urlList.collections);
collectionsSteps
.createCollection(collectionName, false, defaultChannel)
.then(collection => {
collectionsSteps.assignProductsToCollection(name);
2021-02-24 13:21:19 +00:00
storeFrontCollectionUtils.isCollectionVisible(
2021-02-22 12:10:51 +00:00
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);
2021-02-18 09:00:08 +00:00
2021-02-22 12:10:51 +00:00
collectionsSteps
.createCollection(collectionName, true, defaultChannel)
.then(collection => {
collectionsSteps.assignProductsToCollection(name);
2021-02-24 13:21:19 +00:00
storeFrontCollectionUtils.isCollectionVisible(
2021-02-22 12:10:51 +00:00
collection.id,
defaultChannel.slug
);
})
.then(isVisible => expect(isVisible).to.equal(true));
});
2021-02-24 13:21:19 +00:00
it("should not display unavailable in channel collections", () => {
const collectionName = `${startsWith}${faker.random.number()}`;
channelsUtils
.createChannel({ name: collectionName })
.then(() => {
productRequest.updateChannelInProduct(
productsUtils.getCreatedProduct().id,
channelsUtils.getCreatedChannel().id
);
})
.then(() => {
cy.visit(urlList.collections);
collectionsSteps.createCollection(
collectionName,
true,
channelsUtils.getCreatedChannel()
);
})
2021-02-22 12:10:51 +00:00
.then(collection => {
collectionsSteps.assignProductsToCollection(name);
2021-02-24 13:21:19 +00:00
storeFrontCollectionUtils.isCollectionVisible(
2021-02-22 12:10:51 +00:00
collection.id,
defaultChannel.slug
);
})
2021-02-24 13:21:19 +00:00
.then(isVisible => expect(isVisible).to.equal(false));
2021-02-22 12:10:51 +00:00
});
2021-02-24 13:21:19 +00:00
it("should display products hidden in listing, only in collection", () => {
const randomName = `${startsWith}${faker.random.number()}`;
const hiddenProductUtils = new ProductsUtils();
hiddenProductUtils.createProductInChannel({
name: randomName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false
});
cy.visit(urlList.collections);
2021-02-22 12:10:51 +00:00
collectionsSteps
2021-02-24 13:21:19 +00:00
.createCollection(randomName, true, defaultChannel)
2021-02-22 12:10:51 +00:00
.then(collection => {
2021-02-24 13:21:19 +00:00
collectionsSteps.assignProductsToCollection(randomName);
storeFrontCollectionUtils.isProductInCollectionVisible(
2021-02-22 12:10:51 +00:00
collection.id,
2021-02-24 13:21:19 +00:00
defaultChannel.slug,
hiddenProductUtils.getCreatedProduct().id
2021-02-22 12:10:51 +00:00
);
})
.then(isVisible => {
expect(isVisible).to.equal(true);
2021-02-24 13:21:19 +00:00
storeFrontProductUtils.isProductVisibleInSearchResult(
hiddenProductUtils.getCreatedProduct().name,
defaultChannel.slug
);
})
.then(isVisible => {
expect(isVisible).to.equal(false);
2021-02-22 12:10:51 +00:00
});
2021-02-18 09:00:08 +00:00
});
});