Repository: oppia/oppia

Issue:
Write an e2e test that does a "tour" of all the pages in Oppia.
The aim of this issue is to write one or more e2e tests that, collectively, load all the pages in Oppia and ensures that there are no errors (probably via general.checkForConsoleErrors() at the end). This will provide at least a sanity check that all pages are at least visitable without errors.

A suggested plan of action is as follows:
- Make a list of the different pages in Oppia
- Plan one or more "test paths" that, taken together, visit all these pages -- and add a comment to this issue explaining what these test paths are (so that others can give feedback on whether there's anything missing, for example).
- Implement the tests



Discussion:

Resolving patch:
diff --git a/core/controllers/library.py b/core/controllers/library.py
--- a/core/controllers/library.py
+++ b/core/controllers/library.py
@@ -128,6 +128,7 @@ def get(self):
                 'header_i18n_id': feconf.LIBRARY_CATEGORY_RECENTLY_PUBLISHED,
                 'has_full_results_page': True,
                 'full_results_url': feconf.LIBRARY_RECENTLY_PUBLISHED_URL,
+                'protractor_id': 'recently-published',
             })
         if top_rated_activity_summary_dicts:
             summary_dicts_by_category.insert(0, {
@@ -137,6 +138,7 @@ def get(self):
                     feconf.LIBRARY_CATEGORY_TOP_RATED_EXPLORATIONS),
                 'has_full_results_page': True,
                 'full_results_url': feconf.LIBRARY_TOP_RATED_URL,
+                'protractor_id': 'top-rated',
             })
         if featured_activity_summary_dicts:
             summary_dicts_by_category.insert(0, {


Test patch:
diff --git a/core/tests/protractor.conf.js b/core/tests/protractor.conf.js
--- a/core/tests/protractor.conf.js
+++ b/core/tests/protractor.conf.js
@@ -88,7 +88,8 @@ exports.config = {
       'protractor/preferences.js',
       'protractor/cacheSlugs.js',
       'protractor/staticPagesTour.js',
-      'protractor/loginFlow.js'
+      'protractor/loginFlow.js',
+      'protractor/libraryPagesTour.js'
     ],
 
     i18n: [
diff --git a/core/tests/protractor/libraryPagesTour.js b/core/tests/protractor/libraryPagesTour.js
new file mode 100644
--- /dev/null
+++ b/core/tests/protractor/libraryPagesTour.js
@@ -0,0 +1,83 @@
+// Copyright 2014 The Oppia Authors. All Rights Reserved.
+//
+// Licensed under the Apache 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://www.apache.org/licenses/LICENSE-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.
+
+/**
+ * @fileoverview End-to-end tests to check for console errors in
+ * library related pages.
+ */
+
+var general = require('../protractor_utils/general.js');
+var library = require('../protractor_utils/library.js');
+var player = require('../protractor_utils/player.js');
+var users = require('../protractor_utils/users.js');
+var workflow = require('../protractor_utils/workflow.js');
+
+describe('Library pages tour', function() {
+  var EXPLORATION_TITLE = 'Test Exploration';
+  var EXPLORATION_OBJECTIVE = 'To learn testing';
+  var EXPLORATION_CATEGORY = 'Random';
+  var EXPLORATION_LANGUAGE = 'English';
+  var EXPLORATION_RATING = 4;
+  var SEARCH_TERM = 'python';
+  var visitLibraryPage = function() {
+    browser.get(general.LIBRARY_URL_SUFFIX);
+  };
+
+  it('visits the library index page', function() {
+    visitLibraryPage();
+  });
+
+  it('visits the top rated page', function() {
+    // To visit the top rated page, at least one
+    // exploration has to be rated by the user
+    users.createAndLoginAdminUser('random@gmail.com', 'random');
+    workflow.createAndPublishExploration(
+      EXPLORATION_TITLE,
+      EXPLORATION_CATEGORY,
+      EXPLORATION_OBJECTIVE,
+      EXPLORATION_LANGUAGE
+    );
+    visitLibraryPage();
+    library.playExploration(EXPLORATION_TITLE);
+
+    player.submitAnswer('Continue');
+    player.rateExploration(EXPLORATION_RATING);
+
+    visitLibraryPage();
+    element(by.css('.protractor-test-library-top-rated')).click();
+    expect(browser.getCurrentUrl()).toContain('library/top_rated');
+    users.logout();
+  });
+
+  it('visits the recent explorations page', function() {
+    visitLibraryPage();
+    element(by.css('.protractor-test-library-recently-published')).click();
+    expect(browser.getCurrentUrl()).toContain('library/recently_published');
+  });
+
+  it('visits the search page', function() {
+    visitLibraryPage();
+    element(by.css('.protractor-test-search-input')).sendKeys(SEARCH_TERM);
+    browser.driver.wait(function() {
+      return browser.getCurrentUrl().then(function(url) {
+        return /search/.test(url);
+      });
+    });
+    expect(browser.getCurrentUrl()).toContain('search/find?q=python');
+  });
+
+  afterEach(function() {
+    general.checkForConsoleErrors([]);
+  });
+});
diff --git a/core/tests/protractor_utils/users.js b/core/tests/protractor_utils/users.js
--- a/core/tests/protractor_utils/users.js
+++ b/core/tests/protractor_utils/users.js
@@ -73,13 +73,17 @@ var createModerator = function(email, username) {
 };
 
 var createAdmin = function(email, username) {
+  createAndLoginAdminUser(email, username);
+  logout();
+};
+
+var createAndLoginAdminUser = function(email, username) {
   login(email, true);
   _completeSignup(username);
   admin.editConfigProperty(
       'Usernames of admins', 'List', function(listEditor) {
     listEditor.addItem('Unicode').setValue(username);
   });
-  logout();
 };
 
 exports.login = login;
@@ -88,4 +92,5 @@ exports.createUser = createUser;
 exports.createAndLoginUser = createAndLoginUser;
 exports.createModerator = createModerator;
 exports.createAdmin = createAdmin;
+exports.createAndLoginAdminUser = createAndLoginAdminUser;