Saleor 7780 fix for collection tests (#2227)

* fix fox tests in collection

* removing then() in tests

* fixing failing collection tests and add stable tag to run will all tests
This commit is contained in:
Ewa Czerniak 2022-08-16 13:27:37 +02:00 committed by GitHub
parent 2c57de07e4
commit 29c7f785c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 370 additions and 354 deletions

View file

@ -8,6 +8,7 @@ import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { collectionDetailsUrl, urlList } from "../../fixtures/urlList"; import { collectionDetailsUrl, urlList } from "../../fixtures/urlList";
import { createChannel } from "../../support/api/requests/Channels"; import { createChannel } from "../../support/api/requests/Channels";
import { import {
addChannelToCollection,
addProductToCollection, addProductToCollection,
createCollection as createCollectionRequest, createCollection as createCollectionRequest,
} from "../../support/api/requests/Collections"; } from "../../support/api/requests/Collections";
@ -19,12 +20,6 @@ import { deleteCollectionsStartsWith } from "../../support/api/utils/catalog/col
import * as channelsUtils from "../../support/api/utils/channelsUtils"; import * as channelsUtils from "../../support/api/utils/channelsUtils";
import * as productsUtils from "../../support/api/utils/products/productsUtils"; import * as productsUtils from "../../support/api/utils/products/productsUtils";
import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils"; import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils";
import {
isCollectionVisible,
isProductInCollectionVisible,
} from "../../support/api/utils/storeFront/collectionsUtils";
import { isProductVisibleInSearchResult } from "../../support/api/utils/storeFront/storeFrontProductUtils";
import filterTests from "../../support/filterTests";
import { import {
assignProductsToCollection, assignProductsToCollection,
createCollection, createCollection,
@ -32,368 +27,366 @@ import {
updateCollection, updateCollection,
} from "../../support/pages/catalog/collectionsPage"; } from "../../support/pages/catalog/collectionsPage";
filterTests({ definedTags: ["all"] }, () => { describe("As an admin I want to manage collections.", () => {
describe("As an admin I want to manage collections.", () => { const startsWith = "CyCollections-";
const startsWith = "CyCollections-"; const productName = `${startsWith}${faker.datatype.number()}`;
const name = `${startsWith}${faker.datatype.number()}`;
let attribute; let attribute;
let productType; let productType;
let category; let category;
let product; let product;
let defaultChannel;
let defaultChannel; before(() => {
cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProductsStartsWith(startsWith);
deleteCollectionsStartsWith(startsWith);
deleteShippingStartsWith(startsWith);
channelsUtils.deleteChannelsStartsWith(startsWith);
before(() => { channelsUtils
cy.clearSessionData().loginUserViaRequest(); .getDefaultChannel()
productsUtils.deleteProductsStartsWith(startsWith); .then(channel => {
deleteCollectionsStartsWith(startsWith); defaultChannel = channel;
deleteShippingStartsWith(startsWith); productsUtils.createTypeAttributeAndCategoryForProduct({
channelsUtils.deleteChannelsStartsWith(startsWith); name: productName,
});
})
.then(
({
attribute: attributeResp,
productType: productTypeResp,
category: categoryResp,
}) => {
attribute = attributeResp;
productType = productTypeResp;
category = categoryResp;
productsUtils.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
});
},
)
.then(({ product: productResp }) => (product = productResp));
});
channelsUtils beforeEach(() => {
.getDefaultChannel() cy.clearSessionData().loginUserViaRequest();
.then(channel => { });
defaultChannel = channel;
productsUtils.createTypeAttributeAndCategoryForProduct({ name }); it(
}) "should create hidden collection. TC: SALEOR_0301",
.then( { tags: ["@collection", "@allEnv", "@stable"] },
({ () => {
attribute: attributeResp, const collectionName = `${startsWith}${faker.datatype.number()}`;
productType: productTypeResp, let collection;
category: categoryResp,
}) => { cy.visit(urlList.collections).expectSkeletonIsVisible();
attribute = attributeResp; createCollection(collectionName, false, defaultChannel).then(
productType = productTypeResp; collectionResp => {
category = categoryResp; collection = collectionResp;
productsUtils.createProductInChannel({
name, assignProductsToCollection(productName);
channelId: defaultChannel.id, getCollection({
productTypeId: productType.id, collectionId: collection.id,
attributeId: attribute.id, channelSlug: defaultChannel.slug,
categoryId: category.id, })
}); .its("collection.channelListings.0.isPublished")
.should("eq", false);
},
);
},
);
it(
"should create published collection. TC: SALEOR_0302",
{ tags: ["@collection", "@allEnv", "@stable"] },
() => {
const collectionName = `${startsWith}${faker.datatype.number()}`;
let collection;
cy.visit(urlList.collections).expectSkeletonIsVisible();
createCollection(collectionName, true, defaultChannel).then(
collectionResp => {
collection = collectionResp;
assignProductsToCollection(productName);
getCollection({
collectionId: collection.id,
channelSlug: defaultChannel.slug,
})
.its("collection.channelListings.0.isPublished")
.should("eq", true);
},
);
},
);
it(
"should create collection not available for channel. TC: SALEOR_0303",
{ tags: ["@collection", "@allEnv", "@stable"] },
() => {
const collectionName = `${startsWith}${faker.datatype.number()}`;
let collection;
let channel;
createChannel({ name: collectionName }).then(channelResp => {
channel = channelResp;
updateChannelInProduct(product.id, channel.id);
cy.visit(urlList.collections).expectSkeletonIsVisible();
createCollection(collectionName, false, channel).then(
collectionResp => {
collection = collectionResp;
assignProductsToCollection(productName);
getCollection({
collectionId: collection.id,
channelSlug: defaultChannel.slug,
})
.its("collection")
.should("be.null");
}, },
) );
.then(({ product: productResp }) => (product = productResp)); });
}); },
);
beforeEach(() => { it(
cy.clearSessionData().loginUserViaRequest(); "should create published collection with products hidden in listings. TC: SALEOR_0304",
}); { tags: ["@collection", "@allEnv", "@stable"] },
() => {
// Products "hidden in listings" are not displayed in Category listings or search results,
// but are listed on Collections
const collectionName = `${startsWith}${faker.datatype.number()}`;
let collection;
let createdProduct;
xit( productsUtils
"should create hidden collection. TC: SALEOR_0301", .createProductInChannel({
{ tags: ["@collection", "@allEnv"] }, name: collectionName,
() => { channelId: defaultChannel.id,
const collectionName = `${startsWith}${faker.datatype.number()}`; productTypeId: productType.id,
let collection; attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false,
})
.then(({ product: productResp }) => (createdProduct = productResp));
cy.visit(urlList.collections); cy.visit(urlList.collections).expectSkeletonIsVisible();
cy.expectSkeletonIsVisible(); createCollection(collectionName, true, defaultChannel).then(
collectionResp => {
collection = collectionResp;
createCollection(collectionName, false, defaultChannel) assignProductsToCollection(collectionName);
.then(collectionResp => { getCollection({
collection = collectionResp; collectionId: collection.id,
assignProductsToCollection(name); channelSlug: defaultChannel.slug,
}) })
.then(() => { .its("collection.products.edges.0.node.id")
getCollection({ .should("eq", createdProduct.id);
collectionId: collection.id, searchInShop(createdProduct.name)
channelSlug: defaultChannel.slug, .its("body.data.products.edges")
}); .should("be.empty");
}) },
.then(({ collection: resp }) => { );
const isVisible = isCollectionVisible(resp, collection.id); },
expect(isVisible).to.equal(false); );
});
},
);
it( it(
"should create published collection. TC: SALEOR_0302", "should delete collection. TC: SALEOR_0305",
{ tags: ["@collection", "@allEnv", "@stable"] }, { tags: ["@collection", "@allEnv", "@stable"] },
() => { () => {
const collectionName = `${startsWith}${faker.datatype.number()}`; const collectionName = `${startsWith}${faker.datatype.number()}`;
let collection;
cy.visit(urlList.collections); createCollectionRequest(collectionName).then(collectionResp => {
cy.expectSkeletonIsVisible(); cy.visit(collectionDetailsUrl(collectionResp.id))
.get(BUTTON_SELECTORS.deleteButton)
.click()
.addAliasToGraphRequest("RemoveCollection")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors("@RemoveCollection");
getCollection({ collectionId: collectionResp.id })
.its("collection")
.should("be.null");
});
},
);
createCollection(collectionName, true, defaultChannel) it(
.then(collectionResp => { "should update collection. TC: SALEOR_0306",
collection = collectionResp; { tags: ["@collection", "@allEnv", "@stable"] },
assignProductsToCollection(name); () => {
getCollection({ const collectionName = `${startsWith}${faker.datatype.number()}`;
collectionId: collection.id, const updatedName = `${startsWith}updatedCollection`;
channelSlug: defaultChannel.slug,
});
})
.then(({ collection: resp }) => {
const isVisible = isCollectionVisible(resp, collection.id);
expect(isVisible).to.equal(true);
});
},
);
it( let collection;
"create collection not available for channel. TC: SALEOR_0303",
{ tags: ["@collection", "@allEnv", "@stable"] },
() => {
const collectionName = `${startsWith}${faker.datatype.number()}`;
let collection;
let channel;
createChannel({ name: collectionName }) createCollectionRequest(collectionName).then(collectionResp => {
.then(channelResp => { collection = collectionResp;
channel = channelResp;
updateChannelInProduct(product.id, channel.id);
})
.then(() => {
cy.visit(urlList.collections);
cy.expectSkeletonIsVisible();
createCollection(collectionName, true, channel);
})
.then(collectionResp => {
collection = collectionResp;
assignProductsToCollection(name);
getCollection({
collectionId: collection.id,
channelSlug: defaultChannel.slug,
});
})
.then(({ collection: resp }) => {
const isVisible = isCollectionVisible(resp, collection.id);
expect(isVisible).to.equal(false);
});
},
);
it( cy.visitAndWaitForProgressBarToDisappear(
"create published collection with products hidden in listings. TC: SALEOR_0304", collectionDetailsUrl(collection.id),
{ tags: ["@collection", "@allEnv", "@stable"] }, );
() => { addChannelToCollection({
// Products "hidden in listings" are not displayed in Category listings or search results, collectionId: collection.id,
// but are listed on Collections channelId: defaultChannel.id,
const collectionName = `${startsWith}${faker.datatype.number()}`; });
let collection; updateCollection({ name: updatedName, description: updatedName });
let createdProduct; getCollection({
collectionId: collection.id,
channelSlug: defaultChannel.slug,
})
.its("collection")
.should("include", { name: updatedName })
.its("description")
.should("have.string", `{"text": "${updatedName}"}`);
});
},
);
it(
"should assign product to collection. TC: SALEOR_0307",
{ tags: ["@collection", "@allEnv", "@stable"] },
() => {
const collectionName = `Assign-${startsWith}${faker.datatype.number()}`;
const productName = `Product-To-Assign-${startsWith}${faker.datatype.number()}`;
let collection;
let productToAssign;
createCollectionRequest(collectionName).then(collectionResp => {
collection = collectionResp;
addChannelToCollection({
collectionId: collection.id,
channelId: defaultChannel.id,
});
productsUtils productsUtils
.createProductInChannel({ .createProductInChannel({
name: collectionName, name: productName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id, categoryId: category.id,
visibleInListings: false, visibleInListings: false,
}) })
.then(({ product: productResp }) => (createdProduct = productResp)); .then(({ product: productResp }) => {
cy.visit(urlList.collections); productToAssign = productResp;
cy.expectSkeletonIsVisible();
createCollection(collectionName, true, defaultChannel) cy.visitAndWaitForProgressBarToDisappear(
.then(collectionResp => { collectionDetailsUrl(collection.id),
collection = collectionResp; );
assignProductsToCollection(collectionName); cy.reload();
}) assignProductsToCollection(productToAssign.name);
.then(() => {
getCollection({ getCollection({
collectionId: collection.id, collectionId: collection.id,
channelSlug: defaultChannel.slug, channelSlug: defaultChannel.slug,
}); })
}) .its("collection.products.edges.0.node.id")
.then(({ collection: resp }) => { .should("include", productToAssign.id);
const isVisible = isProductInCollectionVisible(
resp,
createdProduct.id,
);
expect(isVisible).to.equal(true);
})
.then(() => {
searchInShop(createdProduct.name);
})
.then(resp => {
const isVisible = isProductVisibleInSearchResult(
resp,
createdProduct.name,
);
expect(isVisible).to.equal(false);
}); });
}, });
); },
);
it( it(
"should delete collection. TC: SALEOR_0305", "should remove product from collection. TC: SALEOR_0308",
{ tags: ["@collection", "@allEnv", "@stable"] }, { tags: ["@collection", "@allEnv", "@stable"] },
() => { () => {
const collectionName = `${startsWith}${faker.datatype.number()}`; const collectionName = `Remove-With-Assigned-Product-${startsWith}${faker.datatype.number()}`;
const productName = `Product-To-Assign-${startsWith}${faker.datatype.number()}`;
let collection;
let productToAssign;
createCollectionRequest(collectionName).then(collectionResp => { createCollectionRequest(collectionName).then(collectionResp => {
cy.visit(collectionDetailsUrl(collectionResp.id)) collection = collectionResp;
.get(BUTTON_SELECTORS.deleteButton)
.click() addChannelToCollection({
.addAliasToGraphRequest("RemoveCollection") collectionId: collection.id,
.get(BUTTON_SELECTORS.submit) channelId: defaultChannel.id,
.click()
.waitForRequestAndCheckIfNoErrors("@RemoveCollection");
getCollection({ collectionId: collectionResp.id, auth: "auth" })
.its("collection")
.should("be.null");
}); });
}, productsUtils
); .createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false,
})
.then(({ product: productResp }) => {
productToAssign = productResp;
it( addProductToCollection({
"delete several collections on collections list page. TC: SALEOR_0309", collectionId: collection.id,
{ tags: ["@collection", "@allEnv"] }, productId: productToAssign.id,
() => {
const deleteSeveral = "delete-several-";
const firstCollectionName = `${deleteSeveral}${startsWith}${faker.datatype.number()}`;
const secondCollectionName = `${deleteSeveral}${startsWith}${faker.datatype.number()}`;
let firstCollection;
let secondCollection;
createCollectionRequest(firstCollectionName).then(collectionResp => {
firstCollection = collectionResp;
});
createCollectionRequest(secondCollectionName).then(collectionResp => {
secondCollection = collectionResp;
cy.visit(urlList.collections)
.searchInTable(deleteSeveral)
.get(collectionRow(firstCollection.id))
.find(BUTTON_SELECTORS.checkbox)
.click()
.get(collectionRow(secondCollection.id))
.find(BUTTON_SELECTORS.checkbox)
.click()
.get(BUTTON_SELECTORS.deleteIcon)
.click()
.addAliasToGraphRequest("CollectionBulkDelete")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors("@CollectionBulkDelete");
getCollection({ collectionId: firstCollection.id, auth: "auth" })
.its("collection")
.should("be.null");
getCollection({ collectionId: secondCollection.id, auth: "auth" })
.its("collection")
.should("be.null");
});
},
);
xit(
"should assign product to collection. TC: SALEOR_0307",
{ tags: ["@collection", "@allEnv"] },
() => {
const collectionName = `Assign-${startsWith}${faker.datatype.number()}`;
const productName = `Product-To-Assign-${startsWith}${faker.datatype.number()}`;
let collection;
let productToAssign;
createCollectionRequest(collectionName).then(collectionResp => {
collection = collectionResp;
productsUtils
.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false,
})
.then(({ product: productResp }) => {
productToAssign = productResp;
cy.visit(collectionDetailsUrl(collection.id));
assignProductsToCollection(productToAssign.name);
getCollection({ collectionId: collection.id, auth: "auth" })
.its("collection.products.edges")
.should("have.length", 1)
.then(productArray => {
expect(productArray[0].node.id).to.equal(productToAssign.id);
});
}); });
});
},
);
it(
"remove product from collection. TC: SALEOR_0308",
{ tags: ["@collection", "@allEnv"] },
() => {
const collectionName = `Remove-With-Assigned-Product-${startsWith}${faker.datatype.number()}`;
const productName = `Product-To-Assign-${startsWith}${faker.datatype.number()}`;
let collection;
let productToAssign;
createCollectionRequest(collectionName).then(collectionResp => {
collection = collectionResp;
productsUtils
.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false,
})
.then(({ product: productResp }) => {
productToAssign = productResp;
addProductToCollection({
collectionId: collection.id,
productId: productToAssign.id,
});
cy.visit(collectionDetailsUrl(collection.id));
getProductDetails(productToAssign.id, defaultChannel.slug, "auth")
.its("body.data.product.collections")
.should("have.length", 1);
getCollection({ collectionId: collection.id, auth: "auth" })
.its("collection.products.edges")
.should("have.length", 1);
removeProductsFromCollection(productToAssign.name);
getCollection({ collectionId: collection.id, auth: "auth" })
.its("collection.products.edges")
.should("be.empty");
});
});
},
);
it(
"should update collection. TC: SALEOR_0306",
{ tags: ["@collection", "@allEnv"] },
() => {
const collectionName = `${startsWith}${faker.datatype.number()}`;
const updatedName = `${startsWith}updatedCollection`;
createCollectionRequest(collectionName)
.then(collectionResp => {
cy.visitAndWaitForProgressBarToDisappear( cy.visitAndWaitForProgressBarToDisappear(
collectionDetailsUrl(collectionResp.id), collectionDetailsUrl(collection.id),
); );
updateCollection({ name: updatedName, description: updatedName }); getProductDetails(productToAssign.id, defaultChannel.slug)
getCollection({ collectionId: collectionResp.id, auth: "auth" }); .its("body.data.product.collections")
}) .should("have.length", 1);
.then(({ collection: collectionResp }) => { getCollection({
expect(collectionResp.name).to.eq(updatedName); collectionId: collection.id,
const descriptionJson = JSON.parse(collectionResp.description); channelSlug: defaultChannel.slug,
const descriptionText = descriptionJson.blocks[0].data.text; })
expect(descriptionText).to.eq(updatedName); .its("collection.products.edges")
.should("have.length", 1);
removeProductsFromCollection(productToAssign.name);
getCollection({
collectionId: collection.id,
channelSlug: defaultChannel.slug,
})
.its("collection.products.edges")
.should("be.empty");
}); });
}, });
); },
}); );
it(
"delete several collections on collections list page. TC: SALEOR_0309",
{ tags: ["@collection", "@allEnv", "@stable"] },
() => {
const deleteSeveral = "delete-several-";
const firstCollectionName = `${deleteSeveral}${startsWith}${faker.datatype.number()}`;
const secondCollectionName = `${deleteSeveral}${startsWith}${faker.datatype.number()}`;
let firstCollection;
let secondCollection;
createCollectionRequest(firstCollectionName).then(collectionResp => {
firstCollection = collectionResp;
});
createCollectionRequest(secondCollectionName).then(collectionResp => {
secondCollection = collectionResp;
cy.visit(urlList.collections)
.searchInTable(deleteSeveral)
.get(collectionRow(firstCollection.id))
.find(BUTTON_SELECTORS.checkbox)
.click()
.get(collectionRow(secondCollection.id))
.find(BUTTON_SELECTORS.checkbox)
.click()
.get(BUTTON_SELECTORS.deleteIcon)
.click()
.addAliasToGraphRequest("CollectionBulkDelete")
.get(BUTTON_SELECTORS.submit)
.click()
.waitForRequestAndCheckIfNoErrors("@CollectionBulkDelete");
getCollection({ collectionId: firstCollection.id })
.its("collection")
.should("be.null");
getCollection({ collectionId: secondCollection.id })
.its("collection")
.should("be.null");
});
},
);
}); });

View file

@ -61,6 +61,17 @@ export function addProductToCollection({ collectionId, productId }) {
collectionId: "${collectionId}" collectionId: "${collectionId}"
products: ["${productId}"] products: ["${productId}"]
) { ) {
collection{
products(first:100){
totalCount
edges{
node{
id
name
}
}
}
}
errors { errors {
message message
} }
@ -68,3 +79,26 @@ export function addProductToCollection({ collectionId, productId }) {
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
export function addChannelToCollection({
collectionId,
channelId,
isPublished = true,
}) {
const mutation = `mutation collectionChannelListingUpdate {
collectionChannelListingUpdate(
id: "${collectionId}",
input: {
addChannels: {
channelId: "${channelId}"
isPublished: ${isPublished}
}
}) {
errors {
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}

View file

@ -1,16 +1,13 @@
import { getValueWithDefault } from "../utils/Utils"; export function getCollection({ collectionId, channelSlug, auth }) {
export function getCollection({ collectionId, channelSlug, auth = "token" }) {
const channelLine = getValueWithDefault(
channelSlug,
`channel: "${channelSlug}"`
);
const query = `query Collection{ const query = `query Collection{
collection(id: "${collectionId}" ${channelLine}) { collection(id: "${collectionId}" channel: "${channelSlug}") {
id id
slug slug
name name
description description
channelListings{
isPublished
}
products(first:100){ products(first:100){
totalCount totalCount
edges{ edges{

View file

@ -3,7 +3,7 @@ import { getValueWithDefault } from "../utils/Utils";
export function getProductDetails(productId, channelSlug, auth = "token") { export function getProductDetails(productId, channelSlug, auth = "token") {
const privateMetadataLine = getValueWithDefault( const privateMetadataLine = getValueWithDefault(
auth === "auth", auth === "auth",
`privateMetadata{key value}` `privateMetadata{key value}`,
); );
const query = `fragment BasicProductFields on Product { const query = `fragment BasicProductFields on Product {
@ -80,14 +80,14 @@ export function getProductMetadata({
productId, productId,
channelSlug, channelSlug,
auth, auth,
withPrivateMetadata withPrivateMetadata,
}) { }) {
const privateMetadata = getValueWithDefault( const privateMetadata = getValueWithDefault(
withPrivateMetadata, withPrivateMetadata,
`privateMetadata{ `privateMetadata{
key key
value value
}` }`,
); );
const query = `query{ const query = `query{

View file

@ -1,9 +0,0 @@
export const isCollectionVisible = (collection, collectionId) =>
collection !== null && collection.id === collectionId;
export const isProductInCollectionVisible = (collection, productId) => {
const productsList = collection.products;
return (
productsList.totalCount !== 0 && productsList.edges[0].node.id === productId
);
};

View file

@ -50,7 +50,8 @@ export function updateCollection({ name, description }) {
} }
export function assignProductsToCollection(productName) { export function assignProductsToCollection(productName) {
cy.get(COLLECTION_SELECTORS.addProductButton) cy.waitForProgressBarToNotBeVisible()
.get(COLLECTION_SELECTORS.addProductButton)
.click() .click()
.addAliasToGraphRequest("SearchProducts") .addAliasToGraphRequest("SearchProducts")
.get(ASSIGN_ELEMENTS_SELECTORS.searchInput) .get(ASSIGN_ELEMENTS_SELECTORS.searchInput)