2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("UIComponent", test => {
|
2017-10-29 21:08:55 +00:00
|
|
|
let testgame = setupEmptyView(test);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("controls visibility", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let component = new UIComponent(testgame.view, 50, 50);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
let container = <UIContainer>(<any>component).container;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(container.visible, true);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
component.setVisible(false);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(container.visible, false);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
component.setVisible(true);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(container.visible, true);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
// with transition
|
|
|
|
component.setVisible(false, 500);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(container.visible, true);
|
2018-05-15 14:57:45 +00:00
|
|
|
check.equals(testgame.view.animations.simulate(container, 'alpha'), [1, 0.75, 0.5, 0.25, 0]);
|
2017-04-12 23:22:34 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("sets position inside parent", check => {
|
2017-10-09 21:13:56 +00:00
|
|
|
let comp1 = new UIComponent(testgame.view, 100, 100);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [0, 0]);
|
2017-04-12 23:22:34 +00:00
|
|
|
comp1.setPositionInsideParent(1, 1);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [1820, 980]);
|
2017-04-12 23:22:34 +00:00
|
|
|
comp1.setPositionInsideParent(0.5, 0.5);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [910, 490]);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
let comp2 = new UIComponent(comp1, 50, 50);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp2.getPosition(), [910, 490]);
|
|
|
|
check.equals(comp2.getPosition(true), [0, 0]);
|
2017-04-12 23:22:34 +00:00
|
|
|
comp2.setPositionInsideParent(1, 0);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp2.getPosition(), [960, 490]);
|
|
|
|
check.equals(comp2.getPosition(true), [50, 0]);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
comp1.setPositionInsideParent(0, 0);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [0, 0]);
|
|
|
|
check.equals(comp2.getPosition(), [50, 0]);
|
2017-04-12 23:22:34 +00:00
|
|
|
|
|
|
|
comp1.setPositionInsideParent(0.654, 0.321, false);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [1190.28, 314.58]);
|
2017-04-12 23:22:34 +00:00
|
|
|
comp1.setPositionInsideParent(0.654, 0.321);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(comp1.getPosition(), [1190, 315]);
|
2017-04-12 23:22:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|