2021-09-27 10:04:21 +00:00
|
|
|
import { ATTRIBUTES_DETAILS } from "../../elements/attribute/attributes_details";
|
|
|
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
2021-12-14 11:14:40 +00:00
|
|
|
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { attributeDetailsUrl } from "../../fixtures/urlList";
|
2021-07-09 09:43:45 +00:00
|
|
|
|
|
|
|
export function createAttributeWithInputType({
|
|
|
|
name,
|
|
|
|
attributeType,
|
|
|
|
entityType,
|
|
|
|
numericSystemType,
|
2021-12-14 11:14:40 +00:00
|
|
|
swatchImage,
|
2023-05-04 08:57:18 +00:00
|
|
|
valueRequired = true,
|
2021-07-09 09:43:45 +00:00
|
|
|
}) {
|
|
|
|
fillUpAttributeCreateFields({ name, attributeType, valueRequired });
|
2021-12-14 11:14:40 +00:00
|
|
|
if (
|
|
|
|
attributeType === "DROPDOWN" ||
|
|
|
|
attributeType === "MULTISELECT" ||
|
|
|
|
(attributeType === "SWATCH" && !swatchImage)
|
|
|
|
) {
|
2021-07-09 09:43:45 +00:00
|
|
|
addSingleValue(name);
|
|
|
|
}
|
|
|
|
if (attributeType === "REFERENCE") {
|
|
|
|
selectEntityType(entityType);
|
|
|
|
}
|
|
|
|
if (attributeType === "NUMERIC" && numericSystemType.unitsOf) {
|
|
|
|
selectNumericSystem(numericSystemType);
|
|
|
|
}
|
2021-12-14 11:14:40 +00:00
|
|
|
if (attributeType === "SWATCH" && swatchImage) {
|
|
|
|
selectSwatchImage(name, swatchImage);
|
|
|
|
}
|
2021-07-09 09:43:45 +00:00
|
|
|
return saveAttribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fillUpAttributeCreateFields({
|
|
|
|
name,
|
|
|
|
attributeType,
|
2023-05-04 08:57:18 +00:00
|
|
|
valueRequired,
|
2021-07-09 09:43:45 +00:00
|
|
|
}) {
|
2022-01-17 10:03:52 +00:00
|
|
|
fillUpAttributeNameAndCode(name);
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.inputTypeSelect)
|
2021-07-09 09:43:45 +00:00
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.attributesInputTypes[attributeType])
|
|
|
|
.click();
|
|
|
|
if (!valueRequired) {
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.valueRequired).click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 10:03:52 +00:00
|
|
|
export function fillUpAttributeNameAndCode(name, code = name) {
|
|
|
|
return cy
|
|
|
|
.get(ATTRIBUTES_DETAILS.nameInput)
|
2023-05-04 08:57:18 +00:00
|
|
|
.clear()
|
|
|
|
.type(name)
|
2022-01-17 10:03:52 +00:00
|
|
|
.get(ATTRIBUTES_DETAILS.codeInput)
|
2023-05-04 08:57:18 +00:00
|
|
|
.clear()
|
|
|
|
.type(code);
|
2022-01-17 10:03:52 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 09:43:45 +00:00
|
|
|
export function saveAttribute() {
|
2021-08-18 11:58:07 +00:00
|
|
|
cy.addAliasToGraphRequest("AttributeCreate");
|
|
|
|
submitAttribute();
|
2021-09-27 10:04:21 +00:00
|
|
|
return cy
|
|
|
|
.waitForRequestAndCheckIfNoErrors("@AttributeCreate")
|
|
|
|
.its("response.body.data.attributeCreate");
|
2021-08-18 11:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function submitAttribute() {
|
2023-05-04 08:57:18 +00:00
|
|
|
cy.get(BUTTON_SELECTORS.confirm).click().confirmationMessageShouldDisappear();
|
2021-07-09 09:43:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function addSingleValue(valueName) {
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.assignValuesButton)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.valueNameInput)
|
|
|
|
.type(valueName)
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function selectEntityType(entityType) {
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.entityTypeSelect)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.entityTypeOptions[entityType])
|
|
|
|
.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function selectNumericSystem({ unitSystem, unitsOf, unit }) {
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.selectUnitCheckbox)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitSystemSelect)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitSystemsOptions[unitSystem])
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitOfSelect)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitsOfOptions[unitsOf])
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitSelect)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.unitsOptions[unit])
|
|
|
|
.click();
|
|
|
|
}
|
2021-08-18 11:58:07 +00:00
|
|
|
|
|
|
|
export function enterAttributeAndChanegeIsFilterableInDashbord(attributeId) {
|
2021-09-27 10:04:21 +00:00
|
|
|
cy.visit(attributeDetailsUrl(attributeId))
|
|
|
|
.waitForProgressBarToNotBeVisible()
|
|
|
|
.get(ATTRIBUTES_DETAILS.dashboardProperties.useInFilteringCheckbox)
|
|
|
|
.click();
|
2021-08-18 11:58:07 +00:00
|
|
|
submitAttribute();
|
|
|
|
}
|
2021-12-14 11:14:40 +00:00
|
|
|
|
|
|
|
export function selectSwatchImage(valueName, image) {
|
|
|
|
cy.get(ATTRIBUTES_DETAILS.assignValuesButton)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.valueNameInput)
|
|
|
|
.type(valueName)
|
|
|
|
.get(ATTRIBUTES_DETAILS.imageCheckbox)
|
|
|
|
.click()
|
|
|
|
.get(ATTRIBUTES_DETAILS.uploadFileButton)
|
|
|
|
.click()
|
|
|
|
.get(SHARED_ELEMENTS.fileInput)
|
|
|
|
.attachFile(image)
|
|
|
|
.get(ATTRIBUTES_DETAILS.uploadFileButton)
|
|
|
|
.should("be.enabled")
|
|
|
|
.get(BUTTON_SELECTORS.submit)
|
|
|
|
.click();
|
|
|
|
}
|