saleor-dashboard/cypress/integration/collections.js

178 lines
5.8 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";
2021-03-04 14:51:55 +00:00
import Collections from "../apiRequests/storeFront/Collections";
import Search from "../apiRequests/storeFront/Search";
2021-02-22 12:10:51 +00:00
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-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", () => {
2021-02-22 12:10:51 +00:00
const productRequest = new Product();
2021-03-04 14:51:55 +00:00
const collectionsRequest = new Collections();
const search = new Search();
2021-02-18 09:00:08 +00:00
const channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
2021-02-19 11:08:10 +00:00
const collectionsUtils = new CollectionsUtils();
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);
2021-03-01 12:25:13 +00:00
let collection;
2021-02-22 12:10:51 +00:00
collectionsSteps
.createCollection(collectionName, false, defaultChannel)
2021-03-01 12:25:13 +00:00
.then(collectionResp => {
collection = collectionResp;
2021-02-22 12:10:51 +00:00
collectionsSteps.assignProductsToCollection(name);
2021-03-01 12:25:13 +00:00
})
.then(() => {
2021-03-04 14:51:55 +00:00
collectionsRequest.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.random.number()}`;
2021-03-04 14:51:55 +00:00
let collection;
2021-02-22 12:10:51 +00:00
cy.visit(urlList.collections);
collectionsSteps
.createCollection(collectionName, true, defaultChannel)
2021-03-04 14:51:55 +00:00
.then(collectionResp => {
collection = collectionResp;
2021-02-22 12:10:51 +00:00
collectionsSteps.assignProductsToCollection(name);
2021-03-04 14:51:55 +00:00
collectionsRequest.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-02-24 13:21:19 +00:00
const collectionName = `${startsWith}${faker.random.number()}`;
2021-03-04 14:51:55 +00:00
let collection;
2021-02-24 13:21:19 +00:00
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-03-04 14:51:55 +00:00
.then(collectionResp => {
collection = collectionResp;
2021-02-22 12:10:51 +00:00
collectionsSteps.assignProductsToCollection(name);
2021-03-04 14:51:55 +00:00
collectionsRequest.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-02-24 13:21:19 +00:00
const randomName = `${startsWith}${faker.random.number()}`;
const hiddenProductUtils = new ProductsUtils();
2021-03-01 12:25:13 +00:00
let collection;
2021-02-24 13:21:19 +00:00
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-03-01 12:25:13 +00:00
.then(collectionResp => {
collection = collectionResp;
2021-02-24 13:21:19 +00:00
collectionsSteps.assignProductsToCollection(randomName);
2021-03-01 12:25:13 +00:00
})
.then(() => {
2021-03-04 14:51:55 +00:00
collectionsRequest.getCollection(collection.id, defaultChannel.slug);
})
.then(resp => {
const isVisible = isProductInCollectionVisible(
resp,
2021-02-24 13:21:19 +00:00
hiddenProductUtils.getCreatedProduct().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-04 14:51:55 +00:00
search.searchInShop(hiddenProductUtils.getCreatedProduct().name);
2021-02-24 13:21:19 +00:00
})
2021-03-04 14:51:55 +00:00
.then(resp => {
const isVisible = isProductVisibleInSearchResult(
resp,
hiddenProductUtils.getCreatedProduct().name
);
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
});
});