saleor-dashboard/cypress/integration/allEnv/collections.js

177 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-02-18 09:00:08 +00:00
// <reference types="cypress" />
import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import { updateChannelInProduct } from "../../apiRequests/Product";
import { getCollection } from "../../apiRequests/storeFront/Collections";
import { searchInShop } from "../../apiRequests/storeFront/Search";
import {
assignProductsToCollection,
createCollection
} 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
} from "../../utils/storeFront/collectionsUtils";
import { isProductVisibleInSearchResult } from "../../utils/storeFront/storeFrontProductUtils";
2021-02-18 09:00:08 +00:00
describe("Collections", () => {
const startsWith = "CyCollections-";
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;
let product;
2021-02-24 13:21:19 +00:00
2021-02-18 09:00:08 +00:00
let defaultChannel;
before(() => {
cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProductsStartsWith(startsWith);
deleteCollectionsStartsWith(startsWith);
deleteShippingStartsWith(startsWith);
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);
})
.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", () => {
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
createCollection(collectionName, false, defaultChannel)
2021-03-01 12:25:13 +00:00
.then(collectionResp => {
collection = collectionResp;
assignProductsToCollection(name);
2021-03-01 12:25:13 +00:00
})
.then(() => {
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", () => {
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();
createCollection(collectionName, true, defaultChannel)
2021-03-04 14:51:55 +00:00
.then(collectionResp => {
collection = collectionResp;
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", () => {
const collectionName = `${startsWith}${faker.datatype.number()}`;
2021-03-04 14:51:55 +00:00
let collection;
let channel;
2021-03-04 14:51:55 +00:00
createChannel({ name: collectionName })
.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();
createCollection(collectionName, true, channel);
2021-02-24 13:21:19 +00:00
})
2021-03-04 14:51:55 +00:00
.then(collectionResp => {
collection = collectionResp;
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
const randomName = `${startsWith}${faker.datatype.number()}`;
2021-03-01 12:25:13 +00:00
let collection;
let createdProduct;
2021-03-01 12:25:13 +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();
createCollection(randomName, true, defaultChannel)
2021-03-01 12:25:13 +00:00
.then(collectionResp => {
collection = collectionResp;
assignProductsToCollection(randomName);
2021-03-01 12:25:13 +00:00
})
.then(() => {
getCollection(collection.id, defaultChannel.slug);
2021-03-04 14:51:55 +00:00
})
.then(resp => {
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(() => {
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,
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
});
});