text: /*!
   * Copyright 2014 Apereo Foundation (AF) Licensed under the
   * Educational Community License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License. You may
   * obtain a copy of the License at
   *
   *     http://opensource.org/licenses/ECL-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an "AS IS"
   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
   * or implied. See the License for the specific language governing
   * permissions and limitations under the License.
   */
  
  casper.test.begin('Widget - Left hand navigation', function(test) {
  
      /**
       * Verify that all personal dashboard navigation is present
       */
      var verifyMeNavigation = function() {
          casper.waitForSelector('.oae-lhnavigation ul.nav-list li', function() {
              // Verify the left hand navigation container exists
              test.assertExists('.oae-lhnavigation', 'The left hand navigation container is present');
              // Verify the left hand navigation list exists
              test.assertExists('.oae-lhnavigation ul.nav-list', 'The left hand navigation list is present');
              // Verify the left hand navigation has activity, library, discussions and groups
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="dashboard"]', 'The left hand navigation list item for \'Recent activity\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="dashboard"] a[href="/dashboard"]', 'The left hand navigation list item for \'Recent activity\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="dashboard"] a[href="/dashboard"] div', 'Recent activity', 'The left hand navigation list item for \'Recent activity\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"]', 'The left hand navigation list item for \'My library\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="/library"]', 'The left hand navigation list item for \'My library\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="/library"] div', 'My library', 'The left hand navigation list item for \'My library\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"]', 'The left hand navigation list item for \'My discussions\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="/discussions"]', 'The left hand navigation list item for \'My discussions\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="/discussions"] div', 'My discussions', 'The left hand navigation list item for \'My discussions\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="groups"]', 'The left hand navigation list item for \'My groups\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="groups"] a[href="/groups"]', 'The left hand navigation list item for \'My groups\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="groups"] a[href="/groups"] div', 'My groups', 'The left hand navigation list item for \'My groups\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="network"]', 'The left hand navigation list item for my \'My network\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="network"] a[href="/network"]', 'The left hand navigation list item for my \'My network\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="network"] a[href="/network"] div', 'My network', 'The left hand navigation list item for my \'My network\' has the correct text');
          });
      };
  
      /**
       * Verify that all personal dashboard navigation for another user is present
       *
       * @param  {String}    profilePath    The path to the user's profile
       */
      var verifyOtherUserNavigation = function(profilePath) {
          casper.waitForSelector('.oae-lhnavigation ul.nav-list li', function() {
              // Verify the left hand navigation container exists
              test.assertExists('.oae-lhnavigation', 'The left hand navigation container is present');
              // Verify the left hand navigation list exists
              test.assertExists('.oae-lhnavigation ul.nav-list', 'The left hand navigation list is present');
              // Verify the left hand navigation has library, discussions and groups and the recent activity is hidden
              test.assertDoesntExist('.oae-lhnavigation ul.nav-list li[data-id="' + profilePath + '/dashboard"]', 'Recent activity is not shown when viewing other user\'s profile');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"]', 'The left hand navigation list item for \'Library\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="' + profilePath + '/library"]', 'The left hand navigation list item for \'Library\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="' + profilePath + '/library"] div', 'Library', 'The left hand navigation list item for \'Library\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"]', 'The left hand navigation list item for \'Discussions\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="' + profilePath + '/discussions"]', 'The left hand navigation list item for \'Discussions\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="' + profilePath + '/discussions"] div', 'Discussions', 'The left hand navigation list item for \'Discussions\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="groups"]', 'The left hand navigation list item for \'Groups\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="groups"] a[href="' + profilePath + '/groups"]', 'The left hand navigation list item for \'Groups\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="groups"] a[href="' + profilePath + '/groups"] div', 'Groups', 'The left hand navigation list item for \'Groups\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="network"]', 'The left hand navigation list item for \'Network\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="network"] a[href="' + profilePath + '/network"]', 'The left hand navigation list item for \'Network\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="network"] a[href="' + profilePath + '/network"] div', 'Network', 'The left hand navigation list item for \'Network\' has the correct text');
          });
      };
  
      /**
       * Verify that all group navigation is present
       *
       * @param  {String}   profilePath   The path to the group's profile
       */
      var verifyGroupNavigation = function(profilePath) {
          casper.waitForSelector('.oae-lhnavigation ul.nav-list li', function() {
              // Verify the left hand navigation container exists
              test.assertExists('.oae-lhnavigation', 'The left hand navigation container is present');
              // Verify the left hand navigation list exists
              test.assertExists('.oae-lhnavigation ul.nav-list', 'The left hand navigation list is present');
              // Verify the left hand navigation has activity, library, discussions and members
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="activity"]', 'The left hand navigation list item for \'Recent activity\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="activity"] a[href="' + profilePath + '/activity"]', 'The left hand navigation list item for \'Recent activity\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="activity"] a[href="' + profilePath + '/activity"] div', 'Recent activity', 'The left hand navigation list item for \'Recent activity\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"]', 'The left hand navigation list item for \'Library\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="' + profilePath + '/library"]', 'The left hand navigation list item for \'Library\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="library"] a[href="' + profilePath + '/library"] div', 'Library', 'The left hand navigation list item for \'Library\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"]', 'The left hand navigation list item for \'Discussions\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="' + profilePath + '/discussions"]', 'The left hand navigation list item for \'Discussions\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="discussions"] a[href="' + profilePath + '/discussions"] div', 'Discussions', 'The left hand navigation list item for \'Discussions\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="members"]', 'The left hand navigation list item for \'Members\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="members"] a[href="' + profilePath + '/members"]', 'The left hand navigation list item for \'Members\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="members"] a[href="' + profilePath + '/members"] div', 'Members', 'The left hand navigation list item for \'Members\' has the correct text');
          });
      };
  
      /**
       * Verify that all global administration navigation is present
       */
      var verifyGlobalAdminNavigation = function() {
          casper.waitForSelector('.oae-lhnavigation ul.nav-list li', function() {
              // Verify the left hand navigation container exists
              test.assertExists('.oae-lhnavigation', 'The left hand navigation container is present');
              // Verify the left hand navigation list exists
              test.assertExists('.oae-lhnavigation ul.nav-list', 'The left hand navigation list is present');
              // Verify the left hand navigation has tenants, modules, user management and maintenance
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="tenants"]', 'The left hand navigation list item for \'Tenants\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="tenants"] a[href="/tenants"]', 'The left hand navigation list item for \'Tenants\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="tenants"] a[href="/tenants"] div', 'Tenants', 'The left hand navigation list item for \'Tenants\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="configuration"]', 'The left hand navigation list item for \'Configuration\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="configuration"] a[href="/configuration"]', 'The left hand navigation list item for \'Configuration\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="configuration"] a[href="/configuration"] div', 'Configuration', 'The left hand navigation list item for \'Configuration\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"]', 'The left hand navigation list item for \'User management\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"] a[href="/usermanagement"]', 'The left hand navigation list item for \'User management\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"] a[href="/usermanagement"] div', 'User management', 'The left hand navigation list item for \'User management\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="maintenance"]', 'The left hand navigation list item for \'Maintenance\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="maintenance"] a[href="/maintenance"]', 'The left hand navigation list item for \'Maintenance\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="maintenance"] a[href="/maintenance"] div', 'Maintenance', 'The left hand navigation list item for \'Maintenance\' has the correct text');
          });
      };
  
      /**
       * Verify that all tenant administration navigation is present
       */
      var verifyTenantAdminNavigation = function() {
          casper.waitForSelector('.oae-lhnavigation ul.nav-list li', function() {
              // Verify the left hand navigation container exists
              test.assertExists('.oae-lhnavigation', 'The left hand navigation container is present');
              // Verify the left hand navigation list exists
              test.assertExists('.oae-lhnavigation ul.nav-list', 'The left hand navigation list is present');
              // Verify the left hand navigation has tenants, modules, user management and skinning
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="tenants"]', 'The left hand navigation list item for \'Tenant\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="tenants"] a[href="/tenant/' + configUtil.tenantAlias + '/tenants"]', 'The left hand navigation list item for \'Tenant\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="tenants"] a[href="/tenant/' + configUtil.tenantAlias + '/tenants"] div', 'Tenant', 'The left hand navigation list item for \'Tenant\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="configuration"]', 'The left hand navigation list item for \'Configuration\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="configuration"] a[href="/tenant/' + configUtil.tenantAlias + '/configuration"]', 'The left hand navigation list item for \'Configuration\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="configuration"] a[href="/tenant/' + configUtil.tenantAlias + '/configuration"] div', 'Configuration', 'The left hand navigation list item for \'Configuration\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"]', 'The left hand navigation list item for \'User management\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"] a[href="/tenant/' + configUtil.tenantAlias + '/usermanagement"]', 'The left hand navigation list item for \'User management\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="usermanagement"] a[href="/tenant/' + configUtil.tenantAlias + '/usermanagement"] div', 'User management', 'The left hand navigation list item for \'User management\' has the correct text');
  
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="skinning"]', 'The left hand navigation list item for \'Skinning\' is present');
              test.assertExists('.oae-lhnavigation ul.nav-list li[data-id="skinning"] a[href="/tenant/' + configUtil.tenantAlias + '/skinning"]', 'The left hand navigation list item for \'Skinning\' has a link');
              test.assertSelectorHasText('.oae-lhnavigation ul.nav-list li[data-id="skinning"] a[href="/tenant/' + configUtil.tenantAlias + '/skinning"] div', 'Skinning', 'The left hand navigation list item for \'Skinning\' has the correct text');
          });
      };
  
      casper.start(configUtil.tenantUI, function() {
          // Create a couple of users to test with
          var user1 = null;
          var user2 = null;
          userUtil.createUsers(2, function(user1, user2) {
              // Login with that user
              userUtil.doLogIn(user1.username, user1.password);
  
              groupUtil.createGroup(null, null, null, null, null, null, function(err, groupProfile) {
                  // Verify that all personal dashboard navigation is present
                  uiUtil.openMe();
                  casper.then(function() {
                      casper.echo('# Verify home page navigation', 'INFO');
                      verifyMeNavigation();
                  });
  
                  // Verify that all personal dashboard navigation is present when viewing another user's profile
                  uiUtil.openUserProfile(user2);
                  casper.then(function() {
                      casper.echo('# Verify /user/:tenantID/:userID navigation', 'INFO');
                      verifyOtherUserNavigation(user2.profilePath);
                  });
  
                  // Verify that all group navigation is present
                  uiUtil.openGroupProfile(groupProfile);
                  casper.then(function() {
                      casper.echo('# Verify /group/:tenantID/:groupID navigation', 'INFO');
                      verifyGroupNavigation(groupProfile.profilePath);
                      userUtil.doLogOut();
                  });
  
                  // Verify that all global admin navigation is present
                  uiUtil.openAdmin();
                  userUtil.doLogIn(configUtil.adminUsername, configUtil.adminPassword);
                  uiUtil.openAdmin();
                  casper.then(function() {
                      casper.echo('# Verify global administration navigation', 'INFO');
                      verifyGlobalAdminNavigation();
                  });
  
                  // Verify that all tenant admin navigation is present
                  uiUtil.openTenantAdmin(configUtil.tenantAlias);
                  casper.then(function() {
                      casper.echo('# Verify tenant administration navigation', 'INFO');
                      verifyTenantAdminNavigation();
                      // Log out at the end of the test
                      userUtil.doLogOut();
                  });
              });
          });
      });
  
      casper.run(function() {
          test.done();
      });
  });
  