setup automated testing for padding
This commit is contained in:
@@ -34,15 +34,20 @@ function computeDOMLayout(node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transferSpacing(div, node, type) {
|
||||||
|
transfer(div, node, type, 'px');
|
||||||
|
transfer(div, node, type + 'Left', 'px');
|
||||||
|
transfer(div, node, type + 'Top', 'px');
|
||||||
|
transfer(div, node, type + 'Bottom', 'px');
|
||||||
|
transfer(div, node, type + 'Right', 'px');
|
||||||
|
}
|
||||||
|
|
||||||
function renderNode(parent, node) {
|
function renderNode(parent, node) {
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
transfer(div, node, 'width', 'px');
|
transfer(div, node, 'width', 'px');
|
||||||
transfer(div, node, 'height', 'px');
|
transfer(div, node, 'height', 'px');
|
||||||
transfer(div, node, 'margin', 'px');
|
transferSpacing(div, node, 'margin');
|
||||||
transfer(div, node, 'marginLeft', 'px');
|
transferSpacing(div, node, 'padding');
|
||||||
transfer(div, node, 'marginTop', 'px');
|
|
||||||
transfer(div, node, 'marginBottom', 'px');
|
|
||||||
transfer(div, node, 'marginRight', 'px');
|
|
||||||
transfer(div, node, 'flexDirection');
|
transfer(div, node, 'flexDirection');
|
||||||
transfer(div, node, 'flex');
|
transfer(div, node, 'flex');
|
||||||
transfer(div, node, 'justifyContent');
|
transfer(div, node, 'justifyContent');
|
||||||
@@ -496,15 +501,19 @@ describe('Layout', function() {
|
|||||||
node.children.push(generateRandomNode());
|
node.children.push(generateRandomNode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function randSpacing(node, chance, type, min, max) {
|
||||||
|
randMinMax(node, chance, type, min, max);
|
||||||
|
randMinMax(node, chance, type + 'Left', min, max);
|
||||||
|
randMinMax(node, chance, type + 'Top', min, max);
|
||||||
|
randMinMax(node, chance, type + 'Right', min, max);
|
||||||
|
randMinMax(node, chance, type + 'Bottom', min, max);
|
||||||
|
}
|
||||||
function generateRandomNode() {
|
function generateRandomNode() {
|
||||||
var node = {style: {}};
|
var node = {style: {}};
|
||||||
randMinMax(node, 0.1, 'width', 0, 1000);
|
randMinMax(node, 0.1, 'width', 0, 1000);
|
||||||
randMinMax(node, 0.1, 'height', 0, 1000);
|
randMinMax(node, 0.1, 'height', 0, 1000);
|
||||||
randMinMax(node, 0.1, 'margin', 0, 20);
|
randSpacing(node, 0.1, 'margin', 0, 20);
|
||||||
randMinMax(node, 0.1, 'marginLeft', 0, 20);
|
randSpacing(node, 0.1, 'padding', 0, 20);
|
||||||
randMinMax(node, 0.1, 'marginTop', 0, 20);
|
|
||||||
randMinMax(node, 0.1, 'marginRight', 0, 20);
|
|
||||||
randMinMax(node, 0.1, 'marginBottom', 0, 20);
|
|
||||||
randEnum(node, 0.1, 'flexDirection', ['row', 'column']);
|
randEnum(node, 0.1, 'flexDirection', ['row', 'column']);
|
||||||
randEnum(node, 0.1, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']);
|
randEnum(node, 0.1, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']);
|
||||||
randEnum(node, 0.1, 'alignItems', ['flex-start', 'center', 'flex-end', 'stretch']);
|
randEnum(node, 0.1, 'alignItems', ['flex-start', 'center', 'flex-end', 'stretch']);
|
||||||
|
@@ -24,24 +24,32 @@ function computeLayout(node) {
|
|||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMargin(location, node) {
|
function getSpacing(type, location, node) {
|
||||||
var key = 'margin' + capitalizeFirst(location);
|
var key = type + capitalizeFirst(location);
|
||||||
if (key in node.style) {
|
if (key in node.style) {
|
||||||
return node.style[key];
|
return node.style[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
key = 'margin' + capitalizeFirst(axis[location]);
|
key = type + capitalizeFirst(axis[location]);
|
||||||
if (key in node.style) {
|
if (key in node.style) {
|
||||||
return node.style[key];
|
return node.style[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('margin' in node.style) {
|
if (type in node.style) {
|
||||||
return node.style.margin;
|
return node.style.margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMargin(location, node) {
|
||||||
|
return getSpacing('margin', location, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPadding(location, node) {
|
||||||
|
return getSpacing('padding', location, node);
|
||||||
|
}
|
||||||
|
|
||||||
function getJustifyContent(node) {
|
function getJustifyContent(node) {
|
||||||
if ('justifyContent' in node.style) {
|
if ('justifyContent' in node.style) {
|
||||||
return node.style.justifyContent;
|
return node.style.justifyContent;
|
||||||
|
Reference in New Issue
Block a user