2021-02-18 09:00:08 +00:00
|
|
|
// <reference types="cypress" />
|
|
|
|
import faker from "faker";
|
|
|
|
|
2021-05-16 11:38:53 +00:00
|
|
|
import { createChannel } from "../../apiRequests/Channels";
|
|
|
|
import { updateChannelInProduct } from "../../apiRequests/Product";
|
|
|
|
import { getCollection } from "../../apiRequests/storeFront/Collections";
|
|
|
|
import { searchInShop } from "../../apiRequests/storeFront/Search";
|
2021-03-12 12:14:18 +00:00
|
|
|
import {
|
|
|
|
assignProductsToCollection,
|
|
|
|
createCollection
|
2021-05-16 11:38:53 +00:00
|
|
|
} from "../../steps/collectionsSteps";
|
|
|
|
import { urlList } from "../../url/urlList";
|
|
|
|
import * as channelsUtils from "../../utils/channelsUtils";
|
|
|
|
import { deleteCollectionsStartsWith } from "../../utils/collectionsUtils";
|
|
|
|
import * as productsUtils from "../../utils/products/productsUtils";
|
|
|
|
import { deleteShippingStartsWith } from "../../utils/shippingUtils";
|
2021-03-01 12:25:13 +00:00
|
|
|
import {
|
|
|
|
isCollectionVisible,
|
|
|
|
isProductInCollectionVisible
|
2021-05-16 11:38:53 +00:00
|
|
|
} from "../../utils/storeFront/collectionsUtils";
|
|
|
|
import { isProductVisibleInSearchResult } from "../../utils/storeFront/storeFrontProductUtils";
|
2021-02-18 09:00:08 +00:00
|
|
|
|
|
|
|
describe("Collections", () => {
|
2021-04-16 11:36:24 +00:00
|
|
|
const startsWith = "CyCollections-";
|
2021-04-21 08:02:48 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2021-02-18 09:00:08 +00:00
|
|
|
|
2021-02-24 13:21:19 +00:00
|
|
|
let attribute;
|
|
|
|
let productType;
|
|
|
|
let category;
|
2021-03-12 12:14:18 +00:00
|
|
|
let product;
|
2021-02-24 13:21:19 +00:00
|
|
|
|
2021-02-18 09:00:08 +00:00
|
|
|
let defaultChannel;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
2021-03-12 12:14:18 +00:00
|
|
|
productsUtils.deleteProductsStartsWith(startsWith);
|
|
|
|
deleteCollectionsStartsWith(startsWith);
|
|
|
|
deleteShippingStartsWith(startsWith);
|
2021-04-21 08:02:48 +00:00
|
|
|
channelsUtils.deleteChannelsStartsWith(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);
|
|
|
|
})
|
2021-03-12 12:14:18 +00:00
|
|
|
.then(
|
|
|
|
({
|
|
|
|
attribute: attributeResp,
|
|
|
|
productType: productTypeResp,
|
|
|
|
category: categoryResp
|
|
|
|
}) => {
|
|
|
|
attribute = attributeResp;
|
|
|
|
productType = productTypeResp;
|
|
|
|
category = categoryResp;
|
|
|
|
productsUtils.createProductInChannel({
|
|
|
|
name,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(({ product: productResp }) => (product = productResp));
|
2021-02-18 09:00:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not display hidden collections", () => {
|
2021-04-21 13:14:38 +00:00
|
|
|
const collectionName = `${startsWith}${faker.datatype.number()}`;
|
2021-02-22 12:10:51 +00:00
|
|
|
cy.visit(urlList.collections);
|
2021-07-12 13:35:26 +00:00
|
|
|
cy.softExpectSkeletonIsVisible();
|
2021-03-01 12:25:13 +00:00
|
|
|
let collection;
|
2021-02-22 12:10:51 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
createCollection(collectionName, false, defaultChannel)
|
2021-03-01 12:25:13 +00:00
|
|
|
.then(collectionResp => {
|
|
|
|
collection = collectionResp;
|
2021-03-12 12:14:18 +00:00
|
|
|
assignProductsToCollection(name);
|
2021-03-01 12:25:13 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-03-12 12:14:18 +00:00
|
|
|
getCollection(collection.id, defaultChannel.slug);
|
2021-02-22 12:10:51 +00:00
|
|
|
})
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(resp => {
|
|
|
|
const isVisible = isCollectionVisible(resp, collection.id);
|
|
|
|
expect(isVisible).to.equal(false);
|
|
|
|
});
|
2021-02-22 12:10:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should display collections", () => {
|
2021-04-21 13:14:38 +00:00
|
|
|
const collectionName = `${startsWith}${faker.datatype.number()}`;
|
2021-03-04 14:51:55 +00:00
|
|
|
let collection;
|
2021-02-22 12:10:51 +00:00
|
|
|
cy.visit(urlList.collections);
|
2021-07-12 13:35:26 +00:00
|
|
|
cy.softExpectSkeletonIsVisible();
|
2021-03-12 12:14:18 +00:00
|
|
|
|
|
|
|
createCollection(collectionName, true, defaultChannel)
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(collectionResp => {
|
|
|
|
collection = collectionResp;
|
2021-03-12 12:14:18 +00:00
|
|
|
assignProductsToCollection(name);
|
|
|
|
getCollection(collection.id, defaultChannel.slug);
|
2021-02-22 12:10:51 +00:00
|
|
|
})
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(resp => {
|
|
|
|
const isVisible = isCollectionVisible(resp, collection.id);
|
|
|
|
expect(isVisible).to.equal(true);
|
|
|
|
});
|
2021-02-22 12:10:51 +00:00
|
|
|
});
|
2021-03-03 08:42:07 +00:00
|
|
|
it("should not display collection not set as available in channel", () => {
|
2021-04-21 13:14:38 +00:00
|
|
|
const collectionName = `${startsWith}${faker.datatype.number()}`;
|
2021-03-04 14:51:55 +00:00
|
|
|
let collection;
|
2021-03-12 12:14:18 +00:00
|
|
|
let channel;
|
2021-03-04 14:51:55 +00:00
|
|
|
|
2021-04-28 13:10:47 +00:00
|
|
|
createChannel({ name: collectionName })
|
2021-03-12 12:14:18 +00:00
|
|
|
.then(channelResp => {
|
|
|
|
channel = channelResp;
|
|
|
|
updateChannelInProduct(product.id, channel.id);
|
2021-02-24 13:21:19 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
cy.visit(urlList.collections);
|
2021-07-12 13:35:26 +00:00
|
|
|
cy.softExpectSkeletonIsVisible();
|
2021-03-12 12:14:18 +00:00
|
|
|
createCollection(collectionName, true, channel);
|
2021-02-24 13:21:19 +00:00
|
|
|
})
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(collectionResp => {
|
|
|
|
collection = collectionResp;
|
2021-03-12 12:14:18 +00:00
|
|
|
assignProductsToCollection(name);
|
|
|
|
getCollection(collection.id, defaultChannel.slug);
|
2021-02-22 12:10:51 +00:00
|
|
|
})
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(resp => {
|
|
|
|
const isVisible = isCollectionVisible(resp, collection.id);
|
|
|
|
expect(isVisible).to.equal(false);
|
|
|
|
});
|
2021-02-22 12:10:51 +00:00
|
|
|
});
|
2021-03-03 10:40:33 +00:00
|
|
|
it("should display products hidden in listing", () => {
|
|
|
|
// Products "hidden in listings" are not displayed in Category listings or search results,
|
|
|
|
// but are listed on Collections
|
2021-04-21 13:14:38 +00:00
|
|
|
const randomName = `${startsWith}${faker.datatype.number()}`;
|
2021-03-01 12:25:13 +00:00
|
|
|
let collection;
|
2021-03-12 12:14:18 +00:00
|
|
|
let createdProduct;
|
2021-03-01 12:25:13 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
productsUtils
|
|
|
|
.createProductInChannel({
|
|
|
|
name: randomName,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
productTypeId: productType.id,
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
|
|
|
visibleInListings: false
|
|
|
|
})
|
|
|
|
.then(({ product: productResp }) => (createdProduct = productResp));
|
2021-02-24 13:21:19 +00:00
|
|
|
cy.visit(urlList.collections);
|
2021-07-12 13:35:26 +00:00
|
|
|
cy.softExpectSkeletonIsVisible();
|
2021-03-12 12:14:18 +00:00
|
|
|
createCollection(randomName, true, defaultChannel)
|
2021-03-01 12:25:13 +00:00
|
|
|
.then(collectionResp => {
|
|
|
|
collection = collectionResp;
|
2021-03-12 12:14:18 +00:00
|
|
|
assignProductsToCollection(randomName);
|
2021-03-01 12:25:13 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-03-12 12:14:18 +00:00
|
|
|
getCollection(collection.id, defaultChannel.slug);
|
2021-03-04 14:51:55 +00:00
|
|
|
})
|
|
|
|
.then(resp => {
|
2021-03-12 12:14:18 +00:00
|
|
|
const isVisible = isProductInCollectionVisible(resp, createdProduct.id);
|
2021-02-22 12:10:51 +00:00
|
|
|
expect(isVisible).to.equal(true);
|
2021-03-03 10:40:33 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-03-12 12:14:18 +00:00
|
|
|
searchInShop(createdProduct.name);
|
2021-02-24 13:21:19 +00:00
|
|
|
})
|
2021-03-04 14:51:55 +00:00
|
|
|
.then(resp => {
|
|
|
|
const isVisible = isProductVisibleInSearchResult(
|
|
|
|
resp,
|
2021-03-12 12:14:18 +00:00
|
|
|
createdProduct.name
|
2021-03-04 14:51:55 +00:00
|
|
|
);
|
2021-02-24 13:21:19 +00:00
|
|
|
expect(isVisible).to.equal(false);
|
2021-02-22 12:10:51 +00:00
|
|
|
});
|
2021-02-18 09:00:08 +00:00
|
|
|
});
|
|
|
|
});
|