2014-03-30 17:12:38 -07:00
|
|
|
|
2014-04-18 16:35:37 -07:00
|
|
|
var testLayout = layoutTestUtils.testLayout;
|
|
|
|
var testRandomLayout = layoutTestUtils.testRandomLayout;
|
2014-04-22 09:32:49 -07:00
|
|
|
var computeLayout = layoutTestUtils.computeLayout;
|
|
|
|
var computeDOMLayout = layoutTestUtils.computeDOMLayout;
|
|
|
|
var reduceTest = layoutTestUtils.reduceTest;
|
2014-03-30 17:12:38 -07:00
|
|
|
|
|
|
|
describe('Layout', function() {
|
|
|
|
it('should layout a single node with width and height', function() {
|
|
|
|
testLayout({
|
|
|
|
style: {width: 100, height: 200}
|
|
|
|
}, {
|
2014-03-30 19:33:24 -07:00
|
|
|
width: 100, height: 200, top: 0, left: 0
|
2014-03-30 19:18:06 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with children', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000}, children: [
|
2014-03-30 19:18:06 -07:00
|
|
|
{style: {width: 500, height: 500}},
|
|
|
|
{style: {width: 250, height: 250}},
|
|
|
|
{style: {width: 125, height: 125}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-03-30 19:18:06 -07:00
|
|
|
{width: 500, height: 500, top: 0, left: 0},
|
|
|
|
{width: 250, height: 250, top: 500, left: 0},
|
|
|
|
{width: 125, height: 125, top: 750, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-03-30 17:12:38 -07:00
|
|
|
});
|
2014-03-30 19:33:24 -07:00
|
|
|
|
|
|
|
it('should layout node with nested children', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000}, children: [
|
|
|
|
{style: {width: 500, height: 500}},
|
|
|
|
{style: {width: 500, height: 500}, children: [
|
2014-03-30 19:33:24 -07:00
|
|
|
{style: {width: 250, height: 250}},
|
|
|
|
{style: {width: 250, height: 250}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
|
|
|
{width: 500, height: 500, top: 0, left: 0},
|
|
|
|
{width: 500, height: 500, top: 500, left: 0, children: [
|
2014-03-30 19:33:24 -07:00
|
|
|
{width: 250, height: 250, top: 0, left: 0},
|
|
|
|
{width: 250, height: 250, top: 250, left: 0},
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
]}
|
|
|
|
);
|
2014-03-30 19:33:24 -07:00
|
|
|
});
|
2014-03-30 19:51:14 -07:00
|
|
|
|
|
|
|
it('should layout node with margin', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 100, height: 200, margin: 10}},
|
|
|
|
{width: 100, height: 200, top: 10, left: 10}
|
|
|
|
);
|
2014-03-30 19:51:14 -07:00
|
|
|
});
|
2014-03-30 20:33:40 -07:00
|
|
|
|
|
|
|
it('should layout node with several children', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, margin: 10}, children: [
|
2014-03-30 20:33:40 -07:00
|
|
|
{style: {width: 100, height: 100, margin: 50}},
|
|
|
|
{style: {width: 100, height: 100, margin: 25}},
|
|
|
|
{style: {width: 100, height: 100, margin: 10}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 10, left: 10, children: [
|
2014-03-30 20:33:40 -07:00
|
|
|
{width: 100, height: 100, top: 50, left: 50},
|
|
|
|
{width: 100, height: 100, top: 225, left: 25},
|
|
|
|
{width: 100, height: 100, top: 360, left: 10}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-03-30 20:33:40 -07:00
|
|
|
});
|
2014-03-31 11:09:33 -07:00
|
|
|
|
|
|
|
it('should layout node with row flex direction', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, flexDirection: 'row'}, children: [
|
2014-03-31 11:09:33 -07:00
|
|
|
{style: {width: 100, height: 200}},
|
|
|
|
{style: {width: 300, height: 150}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-03-31 11:09:33 -07:00
|
|
|
{width: 100, height: 200, top: 0, left: 0},
|
|
|
|
{width: 300, height: 150, top: 0, left: 100}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-03-31 11:09:33 -07:00
|
|
|
});
|
2014-04-05 11:41:21 -07:00
|
|
|
|
|
|
|
it('should layout node based on children main dimensions', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 300}, children: [
|
2014-04-05 11:41:21 -07:00
|
|
|
{style: {width: 100, height: 200}},
|
|
|
|
{style: {width: 300, height: 150}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 300, height: 350, top: 0, left: 0, children: [
|
2014-04-05 11:41:21 -07:00
|
|
|
{width: 100, height: 200, top: 0, left: 0},
|
|
|
|
{width: 300, height: 150, top: 200, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-05 11:41:21 -07:00
|
|
|
});
|
2014-04-05 22:23:00 -07:00
|
|
|
|
|
|
|
it('should layout node with flex', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000}, children: [
|
2014-04-05 22:23:00 -07:00
|
|
|
{style: {width: 100, height: 200}},
|
|
|
|
{style: {width: 100, flex: 1}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-05 22:23:00 -07:00
|
|
|
{width: 100, height: 200, top: 0, left: 0},
|
|
|
|
{width: 100, height: 800, top: 200, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-05 22:23:00 -07:00
|
|
|
});
|
2014-04-06 09:43:16 -07:00
|
|
|
|
|
|
|
it('should layout node with flex recursively', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000}, children: [
|
|
|
|
{style: {width: 1000, flex: 1}, children: [
|
|
|
|
{style: {width: 1000, flex: 1}, children: [
|
|
|
|
{style: {width: 1000, flex: 1}}
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
);
|
2014-04-06 09:43:16 -07:00
|
|
|
});
|
2014-04-06 10:19:53 -07:00
|
|
|
|
2014-04-06 17:39:30 -07:00
|
|
|
it('should layout node with targeted margin', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, marginTop: 10, marginLeft: 5}, children: [
|
|
|
|
{style: {width: 100, height: 100, marginTop: 50, marginLeft: 15, marginBottom: 20}},
|
2014-04-06 10:19:53 -07:00
|
|
|
{style: {width: 100, height: 100, marginLeft: 30}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 10, left: 5, children: [
|
2014-04-06 10:19:53 -07:00
|
|
|
{width: 100, height: 100, top: 50, left: 15},
|
|
|
|
{width: 100, height: 100, top: 170, left: 30}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 10:19:53 -07:00
|
|
|
});
|
|
|
|
|
2014-04-06 17:39:30 -07:00
|
|
|
it('should layout node with justifyContent: flex-start', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, justifyContent: 'flex-start'}, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{style: {width: 100, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{width: 100, height: 100, top: 0, left: 0},
|
|
|
|
{width: 100, height: 100, top: 100, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 17:39:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with justifyContent: flex-end', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, justifyContent: 'flex-end'}, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{style: {width: 100, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{width: 100, height: 100, top: 800, left: 0},
|
|
|
|
{width: 100, height: 100, top: 900, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 17:39:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with justifyContent: space-between', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, justifyContent: 'space-between'}, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{style: {width: 100, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{width: 100, height: 100, top: 0, left: 0},
|
|
|
|
{width: 100, height: 100, top: 900, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 17:39:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with justifyContent: space-around', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, justifyContent: 'space-around'}, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{style: {width: 100, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{width: 100, height: 100, top: 200, left: 0},
|
|
|
|
{width: 100, height: 100, top: 700, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 17:39:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with justifyContent: center', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, justifyContent: 'center'}, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{style: {width: 100, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 17:39:30 -07:00
|
|
|
{width: 100, height: 100, top: 400, left: 0},
|
|
|
|
{width: 100, height: 100, top: 500, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 17:39:30 -07:00
|
|
|
});
|
|
|
|
|
2014-04-06 19:21:06 -07:00
|
|
|
it('should layout node with flex override height', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000}, children: [
|
2014-04-06 19:21:06 -07:00
|
|
|
{style: {width: 100, height: 100, flex: 1}},
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 19:21:06 -07:00
|
|
|
{width: 100, height: 1000, top: 0, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 19:21:06 -07:00
|
|
|
});
|
|
|
|
|
2014-04-06 21:34:41 -07:00
|
|
|
it('should layout node with alignItems: flex-start', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, alignItems: 'flex-start'}, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{style: {width: 200, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{width: 200, height: 100, top: 0, left: 0},
|
|
|
|
{width: 100, height: 100, top: 100, left: 0},
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 21:34:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with alignItems: center', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, alignItems: 'center'}, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{style: {width: 200, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{width: 200, height: 100, top: 0, left: 400},
|
|
|
|
{width: 100, height: 100, top: 100, left: 450},
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 21:34:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with alignItems: flex-end', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, alignItems: 'flex-end'}, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{style: {width: 200, height: 100}},
|
|
|
|
{style: {width: 100, height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{width: 200, height: 100, top: 0, left: 800},
|
|
|
|
{width: 100, height: 100, top: 100, left: 900},
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 21:34:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with alignSelf overrides alignItems', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, alignItems: 'flex-end'}, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{style: {width: 200, height: 100}},
|
|
|
|
{style: {width: 100, height: 100, alignSelf: 'center'}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-06 21:34:41 -07:00
|
|
|
{width: 200, height: 100, top: 0, left: 800},
|
|
|
|
{width: 100, height: 100, top: 100, left: 450},
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-06 21:34:41 -07:00
|
|
|
});
|
|
|
|
|
2014-04-09 19:15:46 -07:00
|
|
|
it('should layout node with alignItem: stretch', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 1000, height: 1000, alignItems: 'stretch'}, children: [
|
2014-04-09 19:15:46 -07:00
|
|
|
{style: {height: 100}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 1000, height: 1000, top: 0, left: 0, children: [
|
2014-04-09 19:15:46 -07:00
|
|
|
{width: 1000, height: 100, top: 0, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-09 19:15:46 -07:00
|
|
|
});
|
|
|
|
|
2014-04-09 19:40:17 -07:00
|
|
|
it('should layout empty node', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
2014-04-09 19:40:17 -07:00
|
|
|
{style: {}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
2014-04-09 19:40:17 -07:00
|
|
|
{width: 0, height: 0, top: 0, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-09 19:40:17 -07:00
|
|
|
});
|
|
|
|
|
2014-04-10 09:29:06 -07:00
|
|
|
it('should layout child with margin', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
2014-04-10 09:29:06 -07:00
|
|
|
{style: {margin: 5}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 10, height: 10, top: 0, left: 0, children: [
|
2014-04-10 09:29:06 -07:00
|
|
|
{width: 0, height: 0, top: 5, left: 5}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-10 09:29:06 -07:00
|
|
|
});
|
|
|
|
|
2014-04-14 10:29:04 -07:00
|
|
|
it('should not shrink children if not enough space', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {height: 100}, children: [
|
2014-04-14 10:29:04 -07:00
|
|
|
{style: {height: 100}},
|
|
|
|
{style: {height: 200}},
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 0, height: 100, top: 0, left: 0, children: [
|
2014-04-14 10:29:04 -07:00
|
|
|
{width: 0, height: 100, top: 0, left: 0},
|
|
|
|
{width: 0, height: 200, top: 100, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-14 10:29:04 -07:00
|
|
|
});
|
|
|
|
|
2014-04-14 10:57:16 -07:00
|
|
|
it('should layout for center', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {justifyContent: 'center'}},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0}
|
|
|
|
);
|
2014-04-14 10:57:16 -07:00
|
|
|
});
|
|
|
|
|
2014-04-14 12:00:16 -07:00
|
|
|
it('should layout flex-end taking into account margin', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {height: 100, justifyContent: 'flex-end'}, children: [
|
2014-04-14 12:00:16 -07:00
|
|
|
{style: {marginTop: 10}}
|
2014-04-14 18:38:46 -07:00
|
|
|
]},
|
|
|
|
{width: 0, height: 100, top: 0, left: 0, children: [
|
2014-04-14 12:00:16 -07:00
|
|
|
{width: 0, height: 0, top: 100, left: 0}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
);
|
2014-04-14 12:00:16 -07:00
|
|
|
});
|
|
|
|
|
2014-04-14 14:02:04 -07:00
|
|
|
it('should layout alignItems with margin', function() {
|
2014-04-14 18:38:46 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {alignItems: 'flex-end'}, children: [
|
|
|
|
{style: {margin: 10}},
|
|
|
|
{style: {height: 100}}
|
|
|
|
]}
|
|
|
|
]},
|
2014-04-15 16:39:42 -07:00
|
|
|
{width: 20, height: 120, top: 0, left: 0, children: [
|
|
|
|
{width: 20, height: 120, top: 0, left: 0, children: [
|
2014-04-14 14:02:04 -07:00
|
|
|
{width: 0, height: 0, top: 10, left: 10},
|
|
|
|
{width: 0, height: 100, top: 20, left: 20}
|
2014-04-14 18:38:46 -07:00
|
|
|
]}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
2014-04-14 14:02:04 -07:00
|
|
|
|
2014-04-15 16:39:42 -07:00
|
|
|
it('should layout flex inside of an empty element', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {flex: 1}},
|
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-15 17:53:38 -07:00
|
|
|
it('should layout alignItems stretch and margin', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {alignItems: 'stretch'}, children: [
|
|
|
|
{style: {marginLeft: 10}}
|
|
|
|
]},
|
|
|
|
{width: 10, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 0, left: 10}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-15 18:24:37 -07:00
|
|
|
it('should layout node with padding', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {padding: 5}},
|
|
|
|
{width: 10, height: 10, top: 0, left: 0}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 12:49:31 -07:00
|
|
|
it('should layout node with padding and a child', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {padding: 5}, children: [
|
|
|
|
{style: {}}
|
|
|
|
]},
|
|
|
|
{width: 10, height: 10, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 5, left: 5}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 13:15:00 -07:00
|
|
|
it('should layout node with padding and a child with margin', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {padding: 5}, children: [
|
|
|
|
{style: {margin: 5}}
|
|
|
|
]},
|
|
|
|
{width: 20, height: 20, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 10, left: 10}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 13:21:30 -07:00
|
|
|
it('should layout node with padding and stretch', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {padding: 10, alignSelf: 'stretch'}}
|
|
|
|
]},
|
|
|
|
{width: 20, height: 20, top: 0, left: 0, children: [
|
|
|
|
{width: 20, height: 20, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 13:32:05 -07:00
|
|
|
it('should layout node with inner & outer padding and stretch', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {padding: 50}, children: [
|
|
|
|
{style: {padding: 10, alignSelf: 'stretch'}}
|
|
|
|
]},
|
|
|
|
{width: 120, height: 120, top: 0, left: 0, children: [
|
|
|
|
{width: 20, height: 20, top: 50, left: 50}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 15:09:53 -07:00
|
|
|
it('should layout node with stretch and child with margin', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {alignSelf: 'stretch'}, children: [
|
|
|
|
{style: {margin: 16}}
|
|
|
|
]}
|
|
|
|
]},
|
|
|
|
{width: 32, height: 32, top: 0, left: 0, children: [
|
|
|
|
{width: 32, height: 32, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 16, left: 16}
|
|
|
|
]}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 16:12:24 -07:00
|
|
|
it('should layout node with top and left', function() {
|
2014-04-16 15:26:15 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {top: 5, left: 5}},
|
|
|
|
{width: 0, height: 0, top: 5, left: 5}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 16:12:24 -07:00
|
|
|
it('should layout node with height, padding and space-around', function() {
|
|
|
|
testLayout(
|
2014-04-22 09:48:33 -07:00
|
|
|
{style: {height: 10, paddingTop: 5, justifyContent: 'space-around'}, children: [
|
2014-04-16 16:12:24 -07:00
|
|
|
{style: {}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 10, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 7.5, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-16 16:31:38 -07:00
|
|
|
it('should layout node with bottom', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {bottom: 5}},
|
|
|
|
{width: 0, height: 0, top: -5, left: 0}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should layout node with both top and bottom', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {top: 10, bottom: 5}},
|
|
|
|
{width: 0, height: 0, top: 10, left: 0}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 14:29:17 -07:00
|
|
|
it('should layout node with position: absolute', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {width: 500, flexDirection: 'row'}, children: [
|
|
|
|
{style: {flex: 1}},
|
|
|
|
{style: {position: 'absolute', width: 50}},
|
|
|
|
{style: {flex: 1}},
|
|
|
|
]},
|
|
|
|
{width: 500, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 250, height: 0, top: 0, left: 0},
|
|
|
|
{width: 50, height: 0, top: 0, left: 250},
|
|
|
|
{width: 250, height: 0, top: 0, left: 250}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 14:53:02 -07:00
|
|
|
it('should layout node with child with position: absolute and margin', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {marginRight: 15, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 14:58:44 -07:00
|
|
|
it('should layout node with position: absolute, padding and alignSelf: center', function() {
|
|
|
|
testLayout(
|
2014-04-21 17:07:05 -07:00
|
|
|
{style: {}, children: [
|
2014-04-21 14:58:44 -07:00
|
|
|
{style: {paddingRight: 12, alignSelf: 'center', position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 12, height: 0, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
2014-04-21 16:52:53 -07:00
|
|
|
});
|
2014-04-21 14:58:44 -07:00
|
|
|
|
2014-04-21 17:07:05 -07:00
|
|
|
it('should work with height smaller than paddingBottom', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {height: 5, paddingBottom: 20}},
|
|
|
|
{width: 0, height: 20, top: 0, left: 0}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with width smaller than paddingLeft', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {width: 5, paddingLeft: 20}},
|
|
|
|
{width: 20, height: 0, top: 0, left: 0}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 17:16:32 -07:00
|
|
|
it('should layout node with specified width and stretch', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [{
|
|
|
|
style: {}, children: [
|
|
|
|
{style: {width: 400}}
|
|
|
|
]},
|
|
|
|
{style: {width: 200, alignSelf: 'stretch'}}
|
|
|
|
]},
|
|
|
|
{width: 400, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 400, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 400, height: 0, top: 0, left: 0}
|
|
|
|
]},
|
|
|
|
{width: 200, height: 0, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 18:34:28 -07:00
|
|
|
it('should layout node with padding and child with position absolute', function() {
|
2014-04-21 17:31:04 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {padding: 5}, children: [
|
|
|
|
{style: {position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 10, height: 10, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 5, left: 5}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 18:34:28 -07:00
|
|
|
it('should layout node with position absolute, top and left', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {height: 100}},
|
|
|
|
{style: {position: 'absolute', top: 10, left: 10}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 100, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 100, top: 0, left: 0},
|
|
|
|
{width: 0, height: 0, top: 10, left: 10}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 18:40:00 -07:00
|
|
|
it('should layout node with padding and child position absolute, left', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {padding: 20}, children: [
|
|
|
|
{style: {left: 5, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 40, height: 40, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 20, left: 5}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 18:45:01 -07:00
|
|
|
it('should layout node with position: absolute, top and marginTop', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {top: 5, marginTop: 5, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 10, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-21 18:45:57 -07:00
|
|
|
it('should layout node with position: absolute, left and marginLeft', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {}, children: [
|
|
|
|
{style: {left: 5, marginLeft: 5, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 0, left: 10}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-22 09:32:49 -07:00
|
|
|
it('should layout node with space-around and child position absolute', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {height: 200, justifyContent: 'space-around'}, children: [
|
|
|
|
{style: {position: 'absolute'}},
|
|
|
|
{style: {}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 200, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 100, left: 0},
|
|
|
|
{width: 0, height: 0, top: 100, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
2014-04-22 09:38:17 -07:00
|
|
|
});
|
|
|
|
|
2014-04-22 09:48:33 -07:00
|
|
|
it('should layout node with flex and main margin', function() {
|
2014-04-22 09:38:17 -07:00
|
|
|
testLayout(
|
|
|
|
{style: {width: 700, flexDirection: 'row'}, children: [
|
|
|
|
{style: {marginLeft: 5, flex: 1}}
|
|
|
|
]},
|
|
|
|
{width: 700, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 695, height: 0, top: 0, left: 5}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
2014-04-22 09:32:49 -07:00
|
|
|
|
2014-04-22 09:48:33 -07:00
|
|
|
it('should layout node with multiple flex and padding', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {width: 700, flexDirection: 'row'}, children: [
|
|
|
|
{style: {flex: 1}},
|
|
|
|
{style: {paddingRight: 5, flex: 1}}
|
|
|
|
]},
|
|
|
|
{width: 700, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 347.5, height: 0, top: 0, left: 0},
|
|
|
|
{width: 352.5, height: 0, top: 0, left: 347.5}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-22 09:53:54 -07:00
|
|
|
it('should layout node with multiple flex and margin', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {width: 700, flexDirection: 'row'}, children: [
|
|
|
|
{style: {flex: 1}},
|
|
|
|
{style: {marginLeft: 5, flex: 1}}
|
|
|
|
]},
|
|
|
|
{width: 700, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 347.5, height: 0, top: 0, left: 0},
|
|
|
|
{width: 347.5, height: 0, top: 0, left: 352.5}
|
|
|
|
]}
|
|
|
|
)
|
|
|
|
});
|
2014-04-22 09:48:33 -07:00
|
|
|
|
2014-04-22 09:56:48 -07:00
|
|
|
it('should layout node with flex and overflow', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {height: 300}, children: [
|
|
|
|
{style: {height: 600}},
|
|
|
|
{style: {flex: 1}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 300, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 600, top: 0, left: 0},
|
|
|
|
{width: 0, height: 0, top: 600, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-22 10:02:33 -07:00
|
|
|
it('should layout node with flex and position absolute', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {width: 600, flexDirection: 'row'}, children: [
|
|
|
|
{style: {flex: 1, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 600, height: 0, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 0, top: 0, left: 0}
|
|
|
|
]}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-04-22 10:21:17 -07:00
|
|
|
it('should layout node with double flex and position absolute', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {height: 500}, children: [
|
|
|
|
{style: {flex: 1}},
|
|
|
|
{style: {flex: 1, position: 'absolute'}}
|
|
|
|
]},
|
|
|
|
{width: 0, height: 500, top: 0, left: 0, children: [
|
|
|
|
{width: 0, height: 500, top: 0, left: 0},
|
|
|
|
{width: 0, height: 0, top: 500, left: 0},
|
|
|
|
]}
|
|
|
|
)
|
|
|
|
});
|
2014-04-22 09:56:48 -07:00
|
|
|
|
2014-04-22 11:31:42 -07:00
|
|
|
it('should layout node with borderWidth', function() {
|
|
|
|
testLayout(
|
|
|
|
{style: {borderWidth: 5}},
|
|
|
|
{width: 10, height: 10, top: 0, left: 0}
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-22 09:56:48 -07:00
|
|
|
|
2014-04-09 21:02:16 -07:00
|
|
|
it('should layout randomly', function() {
|
|
|
|
function RNG(seed) {
|
|
|
|
this.state = seed;
|
|
|
|
}
|
|
|
|
RNG.prototype.nextFloat = function() {
|
|
|
|
// LCG using GCC's constants
|
|
|
|
this.state = (1103515245 * this.state + 12345) % 0x80000000;
|
|
|
|
return this.state / (0x80000000 - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var rng = new RNG(0);
|
|
|
|
function randMinMax(node, chance, attribute, min, max) {
|
|
|
|
if (rng.nextFloat() < chance) {
|
2014-04-21 18:34:28 -07:00
|
|
|
if (attribute === 'right' || attribute === 'bottom') {
|
2014-04-21 17:07:05 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-04-09 21:02:16 -07:00
|
|
|
node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min;
|
|
|
|
}
|
|
|
|
}
|
2014-04-14 10:57:16 -07:00
|
|
|
function randEnum(node, chance, attribute, enumValues) {
|
|
|
|
if (rng.nextFloat() < chance) {
|
|
|
|
node.style[attribute] = enumValues[Math.floor(rng.nextFloat() * enumValues.length)];
|
|
|
|
}
|
|
|
|
}
|
2014-04-10 09:29:06 -07:00
|
|
|
function randChildren(node, chance) {
|
2014-04-10 09:40:57 -07:00
|
|
|
while (rng.nextFloat() < chance) {
|
2014-04-10 09:29:06 -07:00
|
|
|
if (!node.children) {
|
|
|
|
node.children = [];
|
|
|
|
}
|
|
|
|
node.children.push(generateRandomNode());
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 11:31:42 -07:00
|
|
|
function randSpacing(node, chance, type, suffix, min, max) {
|
|
|
|
randMinMax(node, chance, type + suffix, min, max);
|
|
|
|
randMinMax(node, chance, type + 'Left' + suffix, min, max);
|
|
|
|
randMinMax(node, chance, type + 'Top' + suffix, min, max);
|
|
|
|
randMinMax(node, chance, type + 'Right' + suffix, min, max);
|
|
|
|
randMinMax(node, chance, type + 'Bottom' + suffix, min, max);
|
2014-04-15 18:04:11 -07:00
|
|
|
}
|
2014-04-09 21:02:16 -07:00
|
|
|
function generateRandomNode() {
|
|
|
|
var node = {style: {}};
|
2014-04-21 18:50:34 -07:00
|
|
|
randMinMax(node, 0.5, 'width', 0, 1000);
|
|
|
|
randMinMax(node, 0.5, 'height', 0, 1000);
|
2014-04-21 18:40:00 -07:00
|
|
|
randMinMax(node, 0.5, 'top', -10, 10);
|
|
|
|
randMinMax(node, 0.5, 'left', -10, 10);
|
2014-04-21 18:50:34 -07:00
|
|
|
randMinMax(node, 0.5, 'right', -10, 10);
|
|
|
|
randMinMax(node, 0.5, 'bottom', -10, 10);
|
2014-04-22 11:31:42 -07:00
|
|
|
randSpacing(node, 0.5, 'margin', '', 0, 20);
|
|
|
|
randSpacing(node, 0.5, 'padding', '', 0, 20);
|
|
|
|
randSpacing(node, 0.5, 'border', 'Width', 0, 4);
|
2014-04-21 18:50:34 -07:00
|
|
|
randEnum(node, 0.5, 'flexDirection', ['column', 'row']);
|
|
|
|
randEnum(node, 0.5, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']);
|
|
|
|
randEnum(node, 0.5, 'alignItems', ['flex-start', 'center', 'flex-end', 'stretch']);
|
|
|
|
randEnum(node, 0.5, 'alignSelf', ['flex-start', 'center', 'flex-end', 'stretch']);
|
|
|
|
randEnum(node, 0.5, 'flex', ['none', 1]);
|
2014-04-21 18:40:00 -07:00
|
|
|
randEnum(node, 0.5, 'position', ['relative', 'absolute']);
|
2014-04-10 09:29:06 -07:00
|
|
|
randChildren(node, 0.2);
|
2014-04-09 21:02:16 -07:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2014-04-22 11:31:42 -07:00
|
|
|
for (var i = 0; i < 100; ++i) {
|
2014-04-09 21:02:16 -07:00
|
|
|
var node = generateRandomNode();
|
2014-04-14 17:50:55 -07:00
|
|
|
|
2014-04-22 09:32:49 -07:00
|
|
|
if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout)) {
|
|
|
|
node = reduceTest(node);
|
|
|
|
}
|
|
|
|
|
2014-04-14 17:50:55 -07:00
|
|
|
// The iframe's body has a natural width of 300 that it doesn't really make
|
|
|
|
// to replicate in the test suite. The easiest workaround is not to test
|
2014-04-16 16:34:07 -07:00
|
|
|
// alignSelf, position and flex properties on the root element.
|
2014-04-14 17:50:55 -07:00
|
|
|
delete node.style.alignSelf;
|
2014-04-14 18:38:46 -07:00
|
|
|
delete node.style.flex;
|
2014-04-16 16:34:07 -07:00
|
|
|
delete node.style.position;
|
2014-04-14 17:50:55 -07:00
|
|
|
|
2014-04-18 16:35:37 -07:00
|
|
|
testRandomLayout(node, i);
|
2014-04-09 21:02:16 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2014-03-30 17:12:38 -07:00
|
|
|
});
|
|
|
|
|