Skip to content

Commit

Permalink
fix: UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Dec 7, 2023
1 parent c0b5047 commit f8e2cb4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
10 changes: 10 additions & 0 deletions lib/colorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,25 @@ function isColorProperty(prop) {
'color',
'background',
'backgroundColor',
'background-color',
'borderColor',
'border-color',
'borderBottomColor',
'border-bottom-color',
'borderLeftColor',
'border-left-color',
'borderRightColor',
'borderTopColor',
'caretColor',
'columnRuleColor',
'outlineColor',
'textDecorationColor',
'border-right-color',
'border-top-color',
'caret-color',
'column-rule-color',
'outline-color',
'text-decoration-color',
].indexOf(prop) > -1;
}

Expand Down
17 changes: 7 additions & 10 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2119,29 +2119,26 @@ class Playwright extends Helper {

const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
const elemAmount = res.length;
const commands = [];
let props = [];

for (const element of res) {
const cssProperties = await element.evaluate((el) => getComputedStyle(el));

Object.keys(cssPropertiesCamelCase).forEach(prop => {
for (const prop of Object.keys(cssProperties)) {
const cssProp = await this.grabCssPropertyFrom(locator, prop);
if (isColorProperty(prop)) {
props.push(convertColorToRGBA(cssProperties[prop]));
props.push(convertColorToRGBA(cssProp));
} else {
props.push(cssProperties[prop]);
props.push(cssProp);
}
});
}
}

const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
if (!Array.isArray(props)) props = [props];
let chunked = chunkArray(props, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(val[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
if (_actual !== _expected) return false;
// eslint-disable-next-line eqeqeq
if (val[i] != values[i]) return false;
}
return true;
});
Expand Down
30 changes: 10 additions & 20 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,31 +1770,21 @@ class Puppeteer extends Helper {

const cssPropertiesCamelCase = convertCssPropertiesToCamelCase(cssProperties);
const elemAmount = res.length;
const commands = [];
res.forEach((el) => {
Object.keys(cssPropertiesCamelCase).forEach((prop) => {
commands.push(el.executionContext()
.evaluate((el) => {
const style = window.getComputedStyle ? getComputedStyle(el) : el.currentStyle;
return JSON.parse(JSON.stringify(style));
}, el)
.then((props) => {
if (isColorProperty(prop)) {
return convertColorToRGBA(props[prop]);
}
return props[prop];
}));
});
});
let props = await Promise.all(commands);
let props = [];

for (const element of res) {
for (const prop of Object.keys(cssProperties)) {
props.push(await this.grabCssPropertyFrom(locator, prop));
}
}

const values = Object.keys(cssPropertiesCamelCase).map(key => cssPropertiesCamelCase[key]);
if (!Array.isArray(props)) props = [props];
let chunked = chunkArray(props, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
const _acutal = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
if (_acutal !== _expected) return false;
// eslint-disable-next-line eqeqeq
if (val[i] != values[i]) return false;
}
return true;
});
Expand Down

0 comments on commit f8e2cb4

Please sign in to comment.