Skip to content

Commit

Permalink
add getBorders, getPaddings float variant (#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
miherlosev authored Jan 30, 2023
1 parent f7ba03a commit 89f7876
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testcafe-hammerhead",
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
"version": "28.2.9",
"version": "28.3.0",
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
"bugs": {
"url": "https://github.com/DevExpress/testcafe-hammerhead/issues"
Expand Down
47 changes: 35 additions & 12 deletions src/client/utils/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ import { ScrollState } from '../../typings/client';
// NOTE: For Chrome.
const MIN_SELECT_SIZE_VALUE = 4;

function getIntValue (value) {
function getParsedValue (value, parseFn) {
value = value || '';

const parsedValue = parseInt(value.replace('px', ''), 10);
const parsedValue = parseFn(value.replace('px', ''), 10);

return isNaN(parsedValue) ? 0 : parsedValue;
}

function getIntValue (value) {
return getParsedValue(value, parseInt);
}

function getFloatValue (value) {
return getParsedValue(value, parseFloat);
}

export function get (el, property: string, doc?: Document, win?: Window) {
el = el.documentElement || el;

Expand All @@ -28,15 +36,23 @@ export function set (el, property, value) {
el.style[property] = value;
}

export function getBordersWidth (el) {
export function getBordersWidthInternal (el, parseFn) {
return {
bottom: getIntValue(get(el, 'borderBottomWidth')),
left: getIntValue(get(el, 'borderLeftWidth')),
right: getIntValue(get(el, 'borderRightWidth')),
top: getIntValue(get(el, 'borderTopWidth')),
bottom: parseFn(get(el, 'borderBottomWidth')),
left: parseFn(get(el, 'borderLeftWidth')),
right: parseFn(get(el, 'borderRightWidth')),
top: parseFn(get(el, 'borderTopWidth')),
};
}

export function getBordersWidth (el) {
return getBordersWidthInternal(el, getIntValue);
}

export function getBordersWidthFloat (el) {
return getBordersWidthInternal(el, getFloatValue);
}

export function getComputedStyle (el, doc, win) {
// NOTE: In Firefox, after calling the 'document.write' function for nested iframes with html src value
// document.defaultView equals 'null'. But 'window.document' equals 'document'.
Expand All @@ -58,14 +74,21 @@ export function getElementMargin (el) {
};
}

export function getElementPadding (el) {
export function getElementPaddingInternal (el, parseFn) {
return {
bottom: getIntValue(get(el, 'paddingBottom')),
left: getIntValue(get(el, 'paddingLeft')),
right: getIntValue(get(el, 'paddingRight')),
top: getIntValue(get(el, 'paddingTop')),
bottom: parseFn(get(el, 'paddingBottom')),
left: parseFn(get(el, 'paddingLeft')),
right: parseFn(get(el, 'paddingRight')),
top: parseFn(get(el, 'paddingTop')),
};
}
export function getElementPadding (el) {
return getElementPaddingInternal(el, getIntValue);
}

export function getElementPaddingFloat (el) {
return getElementPaddingInternal(el, getFloatValue);
}

export function getElementScroll (el: any): ScrollState {
const isHtmlElement = domUtils.isHtmlElement(el);
Expand Down

0 comments on commit 89f7876

Please sign in to comment.