diff --git a/core/tests/protractor/learnerDashboard.js b/core/tests/protractor/learnerDashboard.js index 1d280fb6076f..7e961fe86a21 100644 --- a/core/tests/protractor/learnerDashboard.js +++ b/core/tests/protractor/learnerDashboard.js @@ -25,12 +25,15 @@ var general = require('../protractor_utils/general.js'); var LibraryPage = require('../protractor_utils/LibraryPage.js'); var player = require('../protractor_utils/player.js'); var users = require('../protractor_utils/users.js'); +var LearnerDashboardPage = + require('../protractor_utils/LearnerDashboardPage.js'); describe('Learner dashboard functionality', function() { var creatorDashboardPage = null; var adminPage = null; var libraryPage = null; - + var learnerDashboardPage = null; + beforeEach(function() { creatorDashboardPage = new CreatorDashboardPage.CreatorDashboardPage(); libraryPage = new LibraryPage.LibraryPage(); @@ -38,6 +41,7 @@ describe('Learner dashboard functionality', function() { beforeAll(function() { adminPage = new AdminPage.AdminPage(); + learnerDashboardPage = new LearnerDashboardPage.LearnerDashboardPage(); // Create a new learner. users.createUser('learner@learnerDashboard.com', 'learnerlearnerDashboard'); users.createUser( @@ -78,7 +82,7 @@ describe('Learner dashboard functionality', function() { general.openPlayer('3'); player.submitAnswer('Continue', null); browser.ignoreSynchronization = true; - browser.get(general.LEARNER_DASHBOARD_URL); + learnerDashboardPage.get(); general.acceptAlert(); browser.ignoreSynchronization = false; browser.waitForAngular(); @@ -91,10 +95,9 @@ describe('Learner dashboard functionality', function() { player.submitAnswer( 'MultipleChoiceInput', 'Those were all the questions I had!'); player.submitAnswer('Continue', null); - browser.get(general.LEARNER_DASHBOARD_URL); - browser.waitForAngular(); - element(by.css('.protractor-test-completed-section')).click(); + learnerDashboardPage.get(); browser.waitForAngular(); + learnerDashboardPage.navigateToCompletedSection(); libraryPage.expectExplorationToBeVisible('About Oppia'); users.logout(); @@ -108,7 +111,7 @@ describe('Learner dashboard functionality', function() { users.logout(); users.login('learner@learnerDashboard.com'); - browser.get(general.LEARNER_DASHBOARD_URL); + learnerDashboardPage.get(); browser.waitForAngular(); libraryPage.expectExplorationToBeHidden('Root Linear Coefficient Theorem'); users.logout(); @@ -129,17 +132,13 @@ describe('Learner dashboard functionality', function() { // 'In Progress' section. player.submitAnswer('Continue', null); browser.ignoreSynchronization = true; - browser.get(general.LEARNER_DASHBOARD_URL); + learnerDashboardPage.get(); general.acceptAlert(); browser.waitForAngular(); general.waitForSystem(); browser.ignoreSynchronization = false; - element(by.css('.protractor-test-incomplete-collection-section')).click(); - browser.waitForAngular(); - general.waitForSystem(); - expect(element.all(by.css( - '.protractor-test-collection-summary-tile-title')).first( - ).getText()).toMatch('Test Collection'); + learnerDashboardPage.navigateToIncompleteCollectionsSection(); + learnerDashboardPage.expectTitleOfSummaryTileToMatch('Test Collection'); // Go to the test collection. browser.get('/search/find?q='); @@ -157,18 +156,13 @@ describe('Learner dashboard functionality', function() { player.submitAnswer( 'MultipleChoiceInput', 'Those were all the questions I had!'); player.submitAnswer('Continue', null); - browser.get(general.LEARNER_DASHBOARD_URL); - browser.waitForAngular(); - general.waitForSystem(); - element(by.css('.protractor-test-completed-section')).click(); + learnerDashboardPage.get(); browser.waitForAngular(); general.waitForSystem(); - element(by.css('.protractor-test-completed-collection-section')).click(); - browser.waitForAngular(); + learnerDashboardPage.navigateToCompletedSection(); general.waitForSystem(); - expect(element.all(by.css( - '.protractor-test-collection-summary-tile-title')).first( - ).getText()).toMatch('Test Collection'); + learnerDashboardPage.navigateToCompletedCollectionsSection(); + learnerDashboardPage.expectTitleOfSummaryTileToMatch('Test Collection'); users.logout(); users.login('creator1@learnerDashboard.com'); @@ -192,15 +186,11 @@ describe('Learner dashboard functionality', function() { users.logout(); users.login('learner@learnerDashboard.com'); - browser.get(general.LEARNER_DASHBOARD_URL); - browser.waitForAngular(); - general.waitForSystem(); - element(by.css('.protractor-test-incomplete-collection-section')).click(); + learnerDashboardPage.get(); browser.waitForAngular(); general.waitForSystem(); - expect(element.all(by.css( - '.protractor-test-collection-summary-tile-title')).first( - ).getText()).toMatch('Test Collection'); + learnerDashboardPage.navigateToIncompleteCollectionsSection(); + learnerDashboardPage.expectTitleOfSummaryTileToMatch('Test Collection'); users.logout(); }); @@ -217,17 +207,12 @@ describe('Learner dashboard functionality', function() { // Both creators should be present in the subscriptions section of the // dashboard. - browser.get(general.LEARNER_DASHBOARD_URL); + learnerDashboardPage.get(); browser.waitForAngular(); general.waitForSystem(); - element(by.css('.protractor-test-subscriptions-section')).click(); - browser.waitForAngular(); - expect(element.all(by.css( - '.protractor-test-subscription-name')).first().getText()).toMatch( - 'creator...'); - expect(element.all(by.css( - '.protractor-test-subscription-name')).last().getText()).toMatch( - 'creator...'); + learnerDashboardPage.navigateToSubscriptionsSection(); + learnerDashboardPage.expectSubscriptionFirstNameToMatch('creator...'); + learnerDashboardPage.expectSubscriptionLastNameToMatch('creator...'); users.logout(); }); @@ -242,18 +227,12 @@ describe('Learner dashboard functionality', function() { 'MultipleChoiceInput', 'Those were all the questions I had!'); player.submitAnswer('Continue', null); player.submitFeedback(feedback); - browser.get(general.LEARNER_DASHBOARD_URL); - browser.waitForAngular(); - element(by.css('.protractor-test-feedback-section')).click(); - browser.waitForAngular(); - expect(element.all(by.css( - '.protractor-test-feedback-exploration')).first().getText()).toMatch( - 'About Oppia'); - element(by.css('.protractor-test-feedback-thread')).click(); + learnerDashboardPage.get(); browser.waitForAngular(); - expect(element.all(by.css( - '.protractor-test-feedback-message')).first().getText()).toMatch( - feedback); + learnerDashboardPage.navigateToFeedbackSection(); + learnerDashboardPage.expectFeedbackExplorationTitleToMatch('About Oppia'); + learnerDashboardPage.navigateToFeedbackThread(); + learnerDashboardPage.expectFeedbackMessageToMatch(feedback); users.logout(); }); diff --git a/core/tests/protractor_utils/LearnerDashboardPage.js b/core/tests/protractor_utils/LearnerDashboardPage.js new file mode 100644 index 000000000000..4473da52205a --- /dev/null +++ b/core/tests/protractor_utils/LearnerDashboardPage.js @@ -0,0 +1,112 @@ +// Copyright 2017 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 Page object for the learner dashboard, for use in Protractor + * tests. + */ + +var general = require('./general.js'); + +var LearnerDashboardPage = function() { + var LEARNER_DASHBOARD_URL = '/learner_dashboard'; + var completedSection = + element(by.css('.protractor-test-completed-section')); + var feedbackSection = + element(by.css('.protractor-test-feedback-section')); + var feedbackThread = + element(by.css('.protractor-test-feedback-thread')); + var completedCollectionsSection = + element(by.css('.protractor-test-completed-collection-section')); + var incompleteCollectionsSection = + element(by.css('.protractor-test-incomplete-collection-section')); + var subscriptionsSection = + element(by.css('.protractor-test-subscriptions-section')); + var subscriptionName = + element.all(by.css('.protractor-test-subscription-name')); + var titleOfSummaryTile = + element.all(by.css('.protractor-test-collection-summary-tile-title')); + var feedbackExplorationTitle = + element.all(by.css('.protractor-test-feedback-exploration')); + var feedbackMessage = + element.all(by.css('.protractor-test-feedback-message')); + + this.get = function() { + return browser.get(LEARNER_DASHBOARD_URL); + }; + + this.navigateToCompletedSection = function() { + completedSection.click(); + browser.waitForAngular(); + }; + + this.navigateToIncompleteCollectionsSection = function() { + incompleteCollectionsSection.click(); + browser.waitForAngular(); + general.waitForSystem(); + }; + + this.navigateToCompletedCollectionsSection = function() { + completedCollectionsSection.click(); + browser.waitForAngular(); + general.waitForSystem(); + }; + + this.navigateToFeedbackSection = function() { + feedbackSection.click(); + browser.waitForAngular(); + }; + + this.navigateToFeedbackThread = function() { + feedbackThread.click(); + browser.waitForAngular(); + }; + + this.navigateToSubscriptionsSection = function() { + subscriptionsSection.click(); + browser.waitForAngular(); + }; + + this.expectTitleOfSummaryTileToMatch = function(title) { + expect( + titleOfSummaryTile.first().getText() + ).toMatch(title); + }; + + this.expectSubscriptionFirstNameToMatch = function(name) { + expect( + subscriptionName.first().getText() + ).toMatch(name); + }; + + this.expectSubscriptionLastNameToMatch = function(name) { + expect( + subscriptionName.last().getText() + ).toMatch(name); + }; + + this.expectFeedbackExplorationTitleToMatch = function(title) { + expect( + feedbackExplorationTitle.first().getText() + ).toMatch(title); + }; + + this.expectFeedbackMessageToMatch = function(message) { + expect( + feedbackMessage.first().getText() + ).toMatch(message); + }; +}; + +exports.LearnerDashboardPage = LearnerDashboardPage; diff --git a/core/tests/protractor_utils/general.js b/core/tests/protractor_utils/general.js index c6b8cbe8a59e..dea4289e5ba3 100644 --- a/core/tests/protractor_utils/general.js +++ b/core/tests/protractor_utils/general.js @@ -65,7 +65,6 @@ var checkForConsoleErrors = function(errorsToIgnore) { var SERVER_URL_PREFIX = 'http://localhost:9001'; var EDITOR_URL_SLICE = '/create/'; var PLAYER_URL_SLICE = '/explore/'; -var LEARNER_DASHBOARD_URL = '/learner_dashboard'; var USER_PREFERENCES_URL = '/preferences'; var LOGIN_URL_SUFFIX = '/_ah/login'; var MODERATOR_URL_SUFFIX = '/moderator'; @@ -165,7 +164,6 @@ exports.scrollToTop = scrollToTop; exports.checkForConsoleErrors = checkForConsoleErrors; exports.SERVER_URL_PREFIX = SERVER_URL_PREFIX; -exports.LEARNER_DASHBOARD_URL = LEARNER_DASHBOARD_URL; exports.USER_PREFERENCES_URL = USER_PREFERENCES_URL; exports.EDITOR_URL_SLICE = EDITOR_URL_SLICE; exports.LOGIN_URL_SUFFIX = LOGIN_URL_SUFFIX;