Margin should affect parent dimensions

This commit is contained in:
Christopher Chedeau
2014-04-10 09:29:06 -07:00
parent 1452aa7e7b
commit 1b79c9c215
2 changed files with 33 additions and 3 deletions

View File

@@ -460,6 +460,21 @@ describe('Layout', function() {
});
});
it('should layout child with margin', function() {
testLayout({
style: {},
children: [
{style: {margin: 5}}
]
}, {
width: 10, height: 10, top: 0, left: 0,
children: [
{width: 0, height: 0, top: 5, left: 5}
]
});
});
it('should layout randomly', function() {
function RNG(seed) {
this.state = seed;
@@ -476,6 +491,14 @@ describe('Layout', function() {
node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min;
}
}
function randChildren(node, chance) {
while (Math.random() < chance) {
if (!node.children) {
node.children = [];
}
node.children.push(generateRandomNode());
}
}
function generateRandomNode() {
var node = {style: {}};
randMinMax(node, 0.1, 'width', 0, 1000);
@@ -485,6 +508,7 @@ describe('Layout', function() {
randMinMax(node, 0.1, 'marginTop', -5, 20);
randMinMax(node, 0.1, 'marginRight', -5, 20);
randMinMax(node, 0.1, 'marginBottom', -5, 20);
randChildren(node, 0.2);
return node;
}