Skip to content

Commit

Permalink
add const for select error and valid style
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesikot committed Sep 20, 2024
1 parent 8a38ded commit 17f9fbc
Showing 1 changed file with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,8 @@ import EditorNavigation, {
EntityType,
} from "../../../../../../support/Pages/EditorNavigation";

const hexToRgb = (hex: string) => {
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);

const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? `rgb(${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)})`
: null;
};

const validateSelectBorderColor = (color: string) => {
agHelper
.GetElement(commonlocators.singleSelectWidgetButtonControl)
.then(($el) => {
const borderDangerColor = getComputedStyle($el[0]).getPropertyValue(
color,
);
const borderDangerColorRgb = hexToRgb(borderDangerColor);
cy.wrap($el).should("have.css", "border-color", borderDangerColorRgb);
});
};
const TABLE_SELECT_WIDGET_ERROR_BORDER = "rgb(217, 25, 33)";
const TABLE_SELECT_WIDGET_VALID_BORDER = "rgb(85, 61, 233)";

describe(
"Table widget - Select column validation",
Expand Down Expand Up @@ -83,7 +64,9 @@ describe(
agHelper.GetElement(table._saveNewRow).should("be.disabled");

// Expect select to have an error color
validateSelectBorderColor("--wds-color-border-danger");
agHelper
.GetElement(commonlocators.singleSelectWidgetButtonControl)
.should("have.css", "border-color", TABLE_SELECT_WIDGET_ERROR_BORDER);

// Select a valid option from the select table cell
agHelper.GetNClick(commonlocators.singleSelectWidgetButtonControl);
Expand All @@ -95,6 +78,11 @@ describe(
// Expect the save row option to be enabled
agHelper.GetElement(table._saveNewRow).should("be.enabled");

// Expect button to have a valid color
agHelper
.GetElement(commonlocators.singleSelectWidgetButtonControl)
.should("have.css", "border-color", TABLE_SELECT_WIDGET_VALID_BORDER);

// Discard save new row
agHelper.GetElement(table._discardRow).click({ force: true });
});
Expand Down Expand Up @@ -131,7 +119,9 @@ describe(
table.ClickOnEditIcon(0, 0, true);

// Exect the select to have an error color
validateSelectBorderColor("--wds-color-border-danger");
agHelper
.GetElement(commonlocators.singleSelectWidgetButtonControl)
.should("have.css", "border-color", TABLE_SELECT_WIDGET_ERROR_BORDER);
});
},
);

0 comments on commit 17f9fbc

Please sign in to comment.