Provide option for tests to disable body:overflow-hidden

This commit is contained in:
Jonathon Wilson 2012-11-23 10:37:27 -07:00
parent e0ee12d09a
commit a3748c941d
4 changed files with 33 additions and 14 deletions

View File

@ -9,6 +9,10 @@
var heartbeatInterval = null;
var subscribers = {}; // Keys are MessageType.MESSAGE values Values are lists of functions to call
var opts = {
layoutOpts: {}
};
/**
* Dynamically build routes from markup. Any layout="screen" will get a route corresponding to
* his layout-id attribute. If a layout-arg attribute is present, that will be named as a data
@ -143,11 +147,12 @@
/**
* Two-phase construction. Call after construction when in non-unit-test use.
*/
this.initialize = function() {
this.initialize = function(inOpts) {
var url, hash;
app = this;
this.opts = $.extend(opts, inOpts);
this.layout = new JK.Layout();
this.layout.initialize();
this.layout.initialize(this.opts.layoutOpts);
routing();
registerMessages();
registerLoginAck();

View File

@ -23,6 +23,7 @@
context.JK.Layout = function() {
// privates
var logger = context.JK.logger;
var me = null; // Reference to this instance for context sanity.
@ -37,7 +38,8 @@
screenMargin: 0, // Margin around screens (not headers/sidebar)
gridOuterMargin: 6, // Outer margin on Grids (added to screenMargin if screen)
gridPadding: 8, // Padding around grid cells. Added to outer margin.
animationDuration: 400
animationDuration: 400,
allowBodyOverflow: false // Allow tests to disable the body-no-scroll policy
};
var width = $(window).width();
@ -264,7 +266,11 @@
padding: '0px',
overflow: 'hidden'
};
if (opts.allowBodyOverflow) {
delete bodyStyle.overflow;
}
$('body').css(bodyStyle);
var layoutStyle = {
position: 'absolute',
margin: '0px',
@ -449,6 +455,8 @@
this.initialize = function(inOpts) {
me = this;
opts = $.extend(opts, inOpts);
logger.error("layout.initialize.opts:");
logger.error(opts);
setup();
events();
};

View File

@ -5,7 +5,12 @@
beforeEach(function() {
jasmine.getFixtures().fixturesPath = '/spec/javascripts/fixtures';
jamkazam = new context.JK.JamKazam();
var opts = {
layoutOpts: {
allowBodyOverflow: true
}
};
jamkazam = new context.JK.JamKazam(opts);
});
describe("Event Subscription", function() {

View File

@ -23,6 +23,7 @@
describe("override one default", function() {
it("headerHeight should be 300", function() {
testOpts = {
allowBodyOverflow: true,
headerHeight: 300
};
layout.initialize(testOpts);
@ -44,7 +45,7 @@
describe("CardLayout", function() {
describe("One cell, zero margins", function() {
it("should fill space", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow:true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 1, 1, 0, 0, 1, 1);
expect(cardLayout).toEqual({top:0,left:0,width:100,height:100});
@ -53,7 +54,7 @@
describe("Two columns, zero margins", function() {
it("should be half width each", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow:true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 1, 2, 0, 0, 1, 1);
expect(cardLayout).toEqual({top:0,left:0,width:50,height:100});
@ -65,7 +66,7 @@
describe("Two rows, zero margins", function() {
it("should be half height each", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow:true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 2, 1, 0, 0, 1, 1);
expect(cardLayout).toEqual({top:0,left:0,width:100,height:50});
@ -77,7 +78,7 @@
describe("two cols, colspan 2, zero margins", function() {
it("should fill width", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 1, 2, 0, 0, 1, 2);
expect(cardLayout).toEqual({top:0,left:0,width:100,height:100});
@ -86,7 +87,7 @@
describe("two rows, rowspan 2, zero margins", function() {
it("should fill height", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 2, 1, 0, 0, 2, 1);
expect(cardLayout).toEqual({top:0,left:0,width:100,height:100});
@ -95,7 +96,7 @@
describe("4x4, zero margins, row 1, col 1, rowspan 2, colspan 2", function() {
it("should fill middle 4 cells", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 0};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 0, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 4, 4, 1, 1, 2, 2);
expect(cardLayout).toEqual({top:25,left:25,width:50,height:50});
@ -105,7 +106,7 @@
// Outer margins
describe("1x1, 100x100, outermargin 10", function() {
it("should be inset 10 pixels, 80x80", function() {
testOpts = { gridOuterMargin: 10, gridPadding: 0};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 10, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 1, 1, 0, 0, 1, 1);
expect(cardLayout).toEqual({top:10,left:10,width:80,height:80});
@ -113,7 +114,7 @@
});
describe("2x2, 100x100, outermargin 10", function() {
it("should be inset 10 pixels, 40x40", function() {
testOpts = { gridOuterMargin: 10, gridPadding: 0};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 10, gridPadding: 0};
layout.initialize(testOpts);
cardLayout = layout.getCardLayout(100, 100, 2, 2, 0, 0, 1, 1);
expect(cardLayout).toEqual({top:10,left:10,width:40,height:40});
@ -123,7 +124,7 @@
// Inner margins
describe("2x2, 100x100, padding 10", function() {
it("10 pixels in and 10 pixel gutters", function() {
testOpts = { gridOuterMargin: 0, gridPadding: 10};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 0, gridPadding: 10};
layout.initialize(testOpts);
// upper left
cardLayout = layout.getCardLayout(100, 100, 2, 2, 0, 0, 1, 1);
@ -137,7 +138,7 @@
// 5 block test like starting home.
describe("home page test", function() {
it("5 blocks", function() {
testOpts = { gridOuterMargin: 10, gridPadding: 10};
testOpts = { allowBodyOverflow: true, gridOuterMargin: 10, gridPadding: 10};
layout.initialize(testOpts);
// Cell 1
cardLayout = layout.getCardLayout(1000, 1000, 2, 4, 0, 0, 1, 1);