Skip to content

Commit

Permalink
HORIZONTAL_STACK and VERTICAL_STACK: Add tests for fillAvailableSpace…
Browse files Browse the repository at this point in the history
…Ratio
  • Loading branch information
mirion authored and publickeating committed May 7, 2014
1 parent 24e72e7 commit 7582fd3
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions frameworks/core_foundation/tests/views/view/childViewLayout_test.js
Expand Up @@ -89,3 +89,114 @@ test("basic HORIZONTAL_STACK", function () {
equals(view.layout.width, 310, "view width should be 310");

});

test("HORIZONTAL_STACK - with fillAvailableSpaceRatio", function () {
var view = null;
SC.run(function() {
view = SC.View.create({
layout: { height: 10, width: 200 },
childViewLayout: SC.View.HORIZONTAL_STACK,
childViewLayoutOptions: {
resizeToFit: NO,
paddingBefore: 10,
paddingAfter: 20,
spacing: 10
},
childViews: [ "c1", "c2", "c3", "c4", "c5" ],

c1: SC.View.create({
layout: { height: 10, width: 10 },
}),
c2: SC.View.create({
layout: { height: 10 },
fillAvailableSpaceRatio: 1
}),
c3: SC.View.create({
layout: { height: 10, width: 10 },
}),
c4: SC.View.create({
layout: { height: 10 },
fillAvailableSpaceRatio: 2
}),
c5: SC.View.create({
layout: { height: 10 },
border: 1,
isVisible: NO
}),
});
});

equals(view.c1.layout.left, 10, "c1 left should be 10");
equals(view.c2.layout.left, 30, "c2 left should be 10");
equals(view.c2.get( "borderFrame" ).width, 40, "c2 width should be 40");
equals(view.c3.layout.left, 80, "c3 left should be 10");
equals(view.c4.layout.left, 100, "c4 left should be 10");
equals(view.c4.get( "borderFrame" ).width, 80, "c4 width should be 80");

SC.run(function() {
view.c2.set( "isVisible", NO );
view.c4.set( "isVisible", NO );
view.c5.set( "isVisible", YES );
});

equals(view.c1.layout.left, 10, "c1 left should be 10");
equals(view.c3.layout.left, 30, "c3 left should be 30");
equals(view.c5.layout.left, 50, "c5 left should be 50");
equals(view.c5.get( "borderFrame" ).width, 130, "being the last child, c5 will extend to fill the available space, width should be 130");
});


test("VERTICAL_STACK - with fillAvailableSpaceRatio", function () {
var view = null;
SC.run(function() {
view = SC.View.create({
layout: { width: 10, height: 200 },
childViewLayout: SC.View.VERTICAL_STACK,
childViewLayoutOptions: {
resizeToFit: NO,
paddingBefore: 10,
paddingAfter: 20,
spacing: 10
},
childViews: [ "c1", "c2", "c3", "c4", "c5" ],

c1: SC.View.create({
layout: { width: 10, height: 10 },
}),
c2: SC.View.create({
layout: { width: 10 },
fillAvailableSpaceRatio: 1
}),
c3: SC.View.create({
layout: { width: 10, height: 10 },
}),
c4: SC.View.create({
layout: { width: 10 },
fillAvailableSpaceRatio: 2
}),
c5: SC.View.create({
layout: { width: 10 },
border: 1,
isVisible: NO
}),
});
});

equals(view.c1.layout.top, 10, "c1 top should be 10");
equals(view.c2.layout.top, 30, "c2 top should be 10");
equals(view.c2.get( "borderFrame" ).height, 40, "c2 height should be 40");
equals(view.c3.layout.top, 80, "c3 top should be 10");
equals(view.c4.layout.top, 100, "c4 top should be 10");
equals(view.c4.get( "borderFrame" ).height, 80, "c4 height should be 80");

SC.run(function() {
view.c2.set( "isVisible", NO );
view.c4.set( "isVisible", NO );
view.c5.set( "isVisible", YES );
});

equals(view.c1.layout.top, 10, "c1 top should be 10");
equals(view.c3.layout.top, 30, "c3 top should be 30");
equals(view.c5.layout.top, 50, "c5 top should be 50");
equals(view.c5.get( "borderFrame" ).height, 130, "being the last child, c5 will extend to fill the available space, height should be 130");
});

0 comments on commit 7582fd3

Please sign in to comment.