/**
 * Start the girder backbone app.
 */
$(function () {
    girder.events.trigger('g:appload.before');
    var app = new girder.App({
        el: 'body',
        parentView: null
    });
    girder.events.trigger('g:appload.after');
});

describe('Test empty and default layouts', function () {

    function expectEmptyLayout() {
        // ensure that all components we expect hidden are hidden
        expect($('#g-app-header-container').is(":visible") === false);
        expect($('#g-global-nav-container').is(":visible") === false);
        expect($('#g-app-footer-container').is(":visible") === false);
        // test that the css changes took effect for the empty layout
        expect($('#g-app-body-container').css('margin-left') === '0px');
        expect($('#g-app-body-container').css('padding-top') === '10px');
        // test that body elements remain visible
        expect($('.g-collection-create-button').is(':visible'));
    }

    function expectDefaultLayout () {
        // ensure that all components we expect revealed are visible
        expect($('#g-app-header-container').is(":visible"));
        expect($('#g-global-nav-container').is(":visible"));
        expect($('#g-app-footer-container').is(":visible"));
        // test that the css changes are reverted for the default layout
        expect($('#g-app-body-container').css('margin-left') !== '0px');
        expect($('#g-app-body-container').css('padding-top') !== '10px');
        // test that body elements remain visible
        expect($('.g-collection-create-button').is(':visible'));
    }

    girder.router.route('collections/emptylayout', 'collectionsEmptyLayout', function(params) {
        girder.events.trigger('g:navigateTo', girder.views.CollectionsView, params || {}, {layout: girder.Layout.EMPTY});
    });

    girder.router.route('collections/defaultlayout', 'collectionsDefaultLayout', function(params) {
        girder.events.trigger('g:navigateTo', girder.views.CollectionsView, params || {}, {layout: girder.Layout.DEFAULT});
    });

    it('register a user (first is admin)',
        girderTest.createUser('admin',
                              'admin@email.com',
                              'Admin',
                              'Admin',
                              'adminpassword!'));

    it('go to collections empty layout page', function () {

        waitsFor(function () {
            return $('#g-app-header-container').is(":visible");
        }, 'wait for app header container to appear so we can know it will disappear');

        girderTest.testRoute('collections/emptylayout', false, function () {
            // go to emptylayout, be sure that app header is gone
            return $('#g-app-header-container').is(":visible") === false;
        });

        runs(expectEmptyLayout);

    });

    it('go to standard collections page, test that not passing a layout will revert to default', function () {

        girderTest.testRoute('collections', false, function () {
            // route back to the standard collections view, this should
            // revert to the default layout
            // be sure that app header is back
            return $('#g-app-header-container').is(":visible") === true;
        });

        runs(expectDefaultLayout);
    });

    it('go to collections empty layout page, then specify a default layout', function () {
        // previously we tested setting a layout to empty, then letting app.js
        // revert to the default layout when none is specified
        //
        // this will test setting a layout to empty, and then specifying a default layout
        // to test the additional code path

        waitsFor(function () {
            return $('#g-app-header-container').is(":visible");
        }, 'wait for app header container to appear so we can know it will disappear');

        girderTest.testRoute('collections/emptylayout', false, function () {
            // go to emptylayout, be sure that app header is gone
            return $('#g-app-header-container').is(":visible") === false;
        });

        runs(expectEmptyLayout);

        girderTest.testRoute('collections/defaultlayout', false, function () {
            // this should revert to the default layout
            // be sure that app header is back
            return $('#g-app-header-container').is(":visible") === true;
        });

        runs(expectDefaultLayout);
    });

});

@@ -442,37 +442,39 @@
 ).is(%22:visible%22)
- === 
+).toBe(
 false);%0A        
@@ -515,37 +515,39 @@
 ).is(%22:visible%22)
- === 
+).toBe(
 false);%0A        
@@ -592,29 +592,31 @@
 (%22:visible%22)
- === 
+).toBe(
 false);%0A    
@@ -626,49 +626,14 @@
  // 
-test that the css changes took effect for
+ensure
  the
@@ -641,24 +641,35 @@
 empty layout
+ is present
 %0A        exp
@@ -703,38 +703,91 @@
 r').
-css('margin-left') === '0px');
+hasClass('g-empty-layout')).toBe(true);%0A        // and the default layout is absent
 %0A   
@@ -829,37 +829,48 @@
 r').
-css('padding-top') === '10px'
+hasClass('g-default-layout')).toBe(false
 );%0A 
@@ -973,32 +973,43 @@
 .is(':visible'))
+.toBe(true)
 ;%0A    %7D%0A%0A    fun
@@ -1159,32 +1159,43 @@
 .is(%22:visible%22))
+.toBe(true)
 ;%0A        expect
@@ -1231,32 +1231,43 @@
 .is(%22:visible%22))
+.toBe(true)
 ;%0A        expect
@@ -1311,16 +1311,27 @@
 sible%22))
+.toBe(true)
 ;%0A      
@@ -1339,50 +1339,14 @@
  // 
-test that the css changes are reverted for
+ensure
  the
@@ -1352,32 +1352,43 @@
 e default layout
+ is present
 %0A        expect(
@@ -1418,38 +1418,91 @@
 r').
-css('margin-left') !== '0px');
+hasClass('g-default-layout')).toBe(true);%0A        // and the empty layout is absent
 %0A   
@@ -1544,37 +1544,46 @@
 r').
-css('padding-top') !== '10px'
+hasClass('g-empty-layout')).toBe(false
 );%0A 
@@ -1694,16 +1694,27 @@
 sible'))
+.toBe(true)
 ;%0A    %7D%0A
@@ -2938,25 +2938,24 @@
 ptyLayout);%0A
-%0A
     %7D);%0A%0A   

Correct emptyLayoutSpec