150 lines
5.4 KiB
JavaScript
150 lines
5.4 KiB
JavaScript
// <reference types="cypress" />
|
|
import faker from "faker";
|
|
|
|
import { createChannel } from "../../../apiRequests/Channels";
|
|
import { ONE_PERMISSION_USERS } from "../../../Data/users";
|
|
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
|
|
import { ADD_CHANNEL_FORM_SELECTORS } from "../../../elements/channels/add-channel-form-selectors";
|
|
import { AVAILABLE_CHANNELS_FORM } from "../../../elements/channels/available-channels-form";
|
|
import { CHANNEL_FORM_SELECTORS } from "../../../elements/channels/channel-form-selectors";
|
|
import { CHANNELS_SELECTORS } from "../../../elements/channels/channels-selectors";
|
|
import { SELECT_CHANNELS_TO_ASSIGN } from "../../../elements/channels/select-channels-to-assign";
|
|
import { HEADER_SELECTORS } from "../../../elements/header/header-selectors";
|
|
import { DRAFT_ORDER_SELECTORS } from "../../../elements/orders/draft-order-selectors";
|
|
import { ORDERS_SELECTORS } from "../../../elements/orders/orders-selectors";
|
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
|
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
|
import { createChannelByView } from "../../../steps/channelsSteps";
|
|
import { urlList } from "../../../url/urlList";
|
|
import { deleteChannelsStartsWith } from "../../../utils/channelsUtils";
|
|
|
|
describe("Channels", () => {
|
|
const channelStartsWith = `CyChannels:`;
|
|
const currency = "PLN";
|
|
|
|
before(() => {
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
deleteChannelsStartsWith(channelStartsWith);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
cy.clearSessionData().loginUserViaRequest(
|
|
"auth",
|
|
ONE_PERMISSION_USERS.channel
|
|
);
|
|
});
|
|
|
|
it("should create new channel", () => {
|
|
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
|
|
cy.addAliasToGraphRequest("Channels");
|
|
cy.visit(urlList.channels);
|
|
cy.wait("@Channels");
|
|
cy.addAliasToGraphRequest("Channel");
|
|
createChannelByView(randomChannel, currency);
|
|
// New channel should be visible in channels list
|
|
cy.wait("@Channel")
|
|
.get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList)
|
|
.click()
|
|
.get(CHANNELS_SELECTORS.channelsTable)
|
|
.contains(randomChannel);
|
|
|
|
// new channel should be visible in channel selector
|
|
cy.visit(urlList.homePage)
|
|
.get(HEADER_SELECTORS.channelSelect)
|
|
.click()
|
|
.get(HEADER_SELECTORS.channelSelectList)
|
|
.contains(randomChannel)
|
|
.click();
|
|
|
|
// new channel should be visible at product availability form
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
cy.addAliasToGraphRequest("InitialProductFilterAttributes");
|
|
cy.visit(urlList.products);
|
|
cy.wait("@InitialProductFilterAttributes");
|
|
cy.get(SHARED_ELEMENTS.progressBar).should("not.exist");
|
|
cy.get(PRODUCTS_LIST.emptyProductRow).should("not.exist");
|
|
cy.get(PRODUCTS_LIST.productsList)
|
|
.first()
|
|
.click()
|
|
.get(AVAILABLE_CHANNELS_FORM.menageChannelsButton)
|
|
.click()
|
|
.get(SELECT_CHANNELS_TO_ASSIGN.listOfChannels)
|
|
.contains(randomChannel);
|
|
});
|
|
|
|
it("should validate slug name", () => {
|
|
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
|
|
createChannel({
|
|
isActive: false,
|
|
name: randomChannel,
|
|
slug: randomChannel,
|
|
currencyCode: currency
|
|
});
|
|
cy.visit(urlList.channels);
|
|
createChannelByView(randomChannel, currency);
|
|
cy.get(ADD_CHANNEL_FORM_SELECTORS.slugValidationMessage).should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
|
|
it("should validate duplicated currency", () => {
|
|
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
|
|
cy.visit(urlList.channels);
|
|
createChannelByView(randomChannel, "notExistingCurrency");
|
|
cy.get(ADD_CHANNEL_FORM_SELECTORS.currencyValidationMessage).should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
|
|
it("should delete channel", () => {
|
|
const randomChannelToDelete = `${channelStartsWith} ${faker.datatype.number()}`;
|
|
createChannel({
|
|
isActive: false,
|
|
name: randomChannelToDelete,
|
|
slug: randomChannelToDelete,
|
|
currencyCode: currency
|
|
});
|
|
cy.addAliasToGraphRequest("Channels");
|
|
cy.visit(urlList.channels);
|
|
cy.wait("@Channels");
|
|
cy.contains(CHANNELS_SELECTORS.channelName, randomChannelToDelete)
|
|
.parentsUntil(CHANNELS_SELECTORS.channelsTable)
|
|
.find("button")
|
|
.click();
|
|
cy.addAliasToGraphRequest("Channels");
|
|
cy.get(BUTTON_SELECTORS.submit).click();
|
|
cy.wait("@Channels");
|
|
|
|
cy.get(CHANNELS_SELECTORS.channelName)
|
|
.contains(randomChannelToDelete)
|
|
.should("not.exist");
|
|
});
|
|
|
|
it("should not be possible to add products to order with inactive channel", () => {
|
|
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
|
|
createChannel({
|
|
isActive: false,
|
|
name: randomChannel,
|
|
slug: randomChannel,
|
|
currencyCode: currency
|
|
});
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
cy.visit(urlList.orders)
|
|
.get(ORDERS_SELECTORS.createOrder)
|
|
.click()
|
|
.get(CHANNEL_FORM_SELECTORS.channelSelect)
|
|
.click()
|
|
.get(CHANNEL_FORM_SELECTORS.channelOption)
|
|
.contains(randomChannel)
|
|
.click()
|
|
.get(CHANNEL_FORM_SELECTORS.confirmButton)
|
|
.click();
|
|
cy.location()
|
|
.should(loc => {
|
|
const urlRegex = new RegExp(`${urlList.orders}.+`, "g");
|
|
expect(loc.pathname).to.match(urlRegex);
|
|
})
|
|
.get(DRAFT_ORDER_SELECTORS.addProducts)
|
|
.should("not.exist");
|
|
});
|
|
});
|