2021-09-27 10:04:21 +00:00
|
|
|
import { COLLECTION_SELECTORS } from "../../../elements/catalog/collection-selectors";
|
|
|
|
import { AVAILABLE_CHANNELS_FORM } from "../../../elements/channels/available-channels-form";
|
|
|
|
import { SELECT_CHANNELS_TO_ASSIGN } from "../../../elements/channels/select-channels-to-assign";
|
|
|
|
import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors";
|
|
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
2021-02-22 12:10:51 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function createCollection(collectionName, isPublished, channel) {
|
|
|
|
const publishedSelector = isPublished
|
2021-04-01 12:33:36 +00:00
|
|
|
? AVAILABLE_CHANNELS_FORM.radioButtonsValueTrue
|
|
|
|
: AVAILABLE_CHANNELS_FORM.radioButtonsValueFalse;
|
2021-03-12 12:14:18 +00:00
|
|
|
|
|
|
|
cy.get(COLLECTION_SELECTORS.createCollectionButton)
|
|
|
|
.click()
|
|
|
|
.get(COLLECTION_SELECTORS.nameInput)
|
|
|
|
.type(collectionName)
|
2021-04-01 12:33:36 +00:00
|
|
|
.get(AVAILABLE_CHANNELS_FORM.menageChannelsButton)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click()
|
2021-04-01 12:33:36 +00:00
|
|
|
.get(SELECT_CHANNELS_TO_ASSIGN.allChannelsCheckbox)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click();
|
2021-12-22 11:27:28 +00:00
|
|
|
cy.contains(SELECT_CHANNELS_TO_ASSIGN.channelRow, channel.name)
|
2021-04-01 12:33:36 +00:00
|
|
|
.find(SELECT_CHANNELS_TO_ASSIGN.channelCheckbox)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click()
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click()
|
2021-04-01 12:33:36 +00:00
|
|
|
.get(AVAILABLE_CHANNELS_FORM.availableChannel)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click()
|
2021-04-01 12:33:36 +00:00
|
|
|
.get(`${AVAILABLE_CHANNELS_FORM.publishedRadioButtons}${publishedSelector}`)
|
2021-12-22 11:27:28 +00:00
|
|
|
.click();
|
|
|
|
return saveCollection().its("response.body.data.collectionCreate.collection");
|
|
|
|
}
|
|
|
|
export function saveCollection(alias = "CreateCollection") {
|
|
|
|
return cy
|
|
|
|
.addAliasToGraphRequest(alias)
|
2021-09-27 10:04:21 +00:00
|
|
|
.get(COLLECTION_SELECTORS.saveButton)
|
|
|
|
.click()
|
|
|
|
.confirmationMessageShouldDisappear()
|
2021-12-22 11:27:28 +00:00
|
|
|
.waitForRequestAndCheckIfNoErrors(`@${alias}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateCollection({ name, description }) {
|
2022-06-06 10:27:18 +00:00
|
|
|
cy.get(COLLECTION_SELECTORS.nameInput)
|
|
|
|
.should("be.enabled")
|
2021-12-22 11:27:28 +00:00
|
|
|
.get(COLLECTION_SELECTORS.descriptionInput)
|
2022-06-06 10:27:18 +00:00
|
|
|
.find(COLLECTION_SELECTORS.placeholder)
|
|
|
|
.type(description)
|
2021-12-22 11:27:28 +00:00
|
|
|
.get(COLLECTION_SELECTORS.nameInput)
|
|
|
|
.clearAndType(name);
|
|
|
|
return saveCollection("CollectionUpdate");
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function assignProductsToCollection(productName) {
|
2022-08-16 11:27:37 +00:00
|
|
|
cy.waitForProgressBarToNotBeVisible()
|
|
|
|
.get(COLLECTION_SELECTORS.addProductButton)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click()
|
2022-03-03 10:25:27 +00:00
|
|
|
.addAliasToGraphRequest("SearchProducts")
|
2021-07-05 10:21:35 +00:00
|
|
|
.get(ASSIGN_ELEMENTS_SELECTORS.searchInput)
|
2022-03-03 10:25:27 +00:00
|
|
|
.type(productName)
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@SearchProducts");
|
2021-07-05 10:21:35 +00:00
|
|
|
cy.contains(ASSIGN_ELEMENTS_SELECTORS.tableRow, productName)
|
|
|
|
.find(ASSIGN_ELEMENTS_SELECTORS.checkbox)
|
2021-03-12 12:14:18 +00:00
|
|
|
.click();
|
|
|
|
cy.addAliasToGraphRequest("CollectionAssignProduct");
|
2021-07-05 10:21:35 +00:00
|
|
|
cy.get(ASSIGN_ELEMENTS_SELECTORS.submitButton).click();
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.waitForRequestAndCheckIfNoErrors("@CollectionAssignProduct");
|
2021-02-22 12:10:51 +00:00
|
|
|
}
|
2022-04-27 11:14:05 +00:00
|
|
|
|
|
|
|
export function removeProductsFromCollection(productName) {
|
|
|
|
cy.contains(ASSIGN_ELEMENTS_SELECTORS.tableRow, productName)
|
|
|
|
.find(ASSIGN_ELEMENTS_SELECTORS.checkbox)
|
|
|
|
.click()
|
|
|
|
.addAliasToGraphRequest("UnassignCollectionProduct")
|
|
|
|
.get(BUTTON_SELECTORS.deleteIcon)
|
|
|
|
.click()
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@UnassignCollectionProduct");
|
|
|
|
}
|