@qooxdoo/framework
Version:
The JS Framework for Coders
179 lines (146 loc) • 4.46 kB
JavaScript
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2010 1&1 Internet AG, Germany, http://www.1und1.de
License:
MIT: https://opensource.org/licenses/MIT
See the LICENSE file in the project's top-level directory for details.
Authors:
* Martin Wittemann (martinwittemann)
************************************************************************ */
qx.Class.define("qx.test.ui.core.Placement", {
extend: qx.test.ui.LayoutTestCase,
members: {
__nogo: null,
setUp() {
this.__nogo = new qx.ui.core.Widget().set({
backgroundColor: "red",
width: 100,
height: 300
});
this.getRoot().add(this.__nogo, { left: 150 });
// set the always visible element
qx.ui.core.MPlacement.setVisibleElement(this.__nogo);
},
tearDown() {
super.tearDown();
qx.ui.core.MPlacement.setVisibleElement(null);
this.__nogo.destroy();
},
__testAlwaysVisibleElement(w) {
// force an addition to the dom!
w.show();
w.hide();
// modify the placed widget
w.setWidth(100);
w.setVisibility("visible");
// render the widgets
this.flush();
// move and flush
w.moveTo(100, 0);
this.flush();
// the right position of the widget should be left of the nogo
var bounds = w.getBounds();
var right = bounds.left + bounds.width;
this.assertEquals(150, right);
this.assertEquals(50, bounds.left);
},
testVisibleWithPopoup() {
var w = new qx.ui.popup.Popup();
this.__testAlwaysVisibleElement(w);
w.destroy();
},
testVisibleWithMenu() {
var w = new qx.ui.menu.Menu();
this.__testAlwaysVisibleElement(w);
w.destroy();
},
__testAlwaysVisibleElementTooBig(w) {
// force an addition to the dom!
w.show();
w.hide();
// modify the placed widget
w.setWidth(200);
w.setVisibility("visible");
// render the widgets
this.flush();
// move and flush
w.moveTo(100, 0);
this.flush();
// The widget should be moved to the left border of the screen and still
// overlap the visible item
var bounds = w.getBounds();
var right = bounds.left + bounds.width;
this.assertEquals(200, right);
this.assertEquals(0, bounds.left);
},
testVisibleWithPopoupTooBig() {
var w = new qx.ui.popup.Popup();
this.__testAlwaysVisibleElementTooBig(w);
w.destroy();
},
testVisibleWithMenuTooBig() {
var w = new qx.ui.menu.Menu();
this.__testAlwaysVisibleElementTooBig(w);
w.destroy();
},
__testAlwaysVisibleElementAbove(w) {
// force an addition to the dom!
w.show();
w.hide();
this.__nogo.setLayoutProperties({ top: 100 });
// modify the placed widget
w.setWidth(100);
w.setVisibility("visible");
// render the widgets
this.flush();
// move and flush
w.moveTo(100, 0);
this.flush();
// Positions should be as set
var bounds = w.getBounds();
var right = bounds.left + bounds.width;
this.assertEquals(200, right);
this.assertEquals(100, bounds.left);
},
testVisibleWithPopoupAbove() {
var w = new qx.ui.popup.Popup();
this.__testAlwaysVisibleElementAbove(w);
w.destroy();
},
testVisibleWithMenuAbove() {
var w = new qx.ui.menu.Menu();
this.__testAlwaysVisibleElementAbove(w);
w.destroy();
},
__testAlwaysVisibleElementBelow(w) {
// force an addition to the dom!
w.show();
w.hide();
// modify the placed widget
w.setWidth(100);
w.setVisibility("visible");
// render the widgets
this.flush();
// move and flush
w.moveTo(100, 400);
this.flush();
// Positions should be as set
var bounds = w.getBounds();
var right = bounds.left + bounds.width;
this.assertEquals(200, right);
this.assertEquals(100, bounds.left);
},
testVisibleWithPopoupBelow() {
var w = new qx.ui.popup.Popup();
this.__testAlwaysVisibleElementBelow(w);
w.destroy();
},
testVisibleWithMenuBelow() {
var w = new qx.ui.menu.Menu();
this.__testAlwaysVisibleElementBelow(w);
w.destroy();
}
}
});