jenkins-bot has submitted this change and it was merged.

Change subject: Add browser test for notifications in Echo
......................................................................


Add browser test for notifications in Echo

This browser test checks that mentions go to alerts and talk page
messages go to messages popup. This also upgrades the MW-Selenium
version in Echo tests to 1.6.1.

Depends on MW-Selenium version 1.6.1 (See T114061)

Bug: T113081
Change-Id: I40a17500cdfb838420c04dc0b9268ba56515cc2c
---
M Gemfile
M Gemfile.lock
M modules/ooui/mw.echo.ui.NotificationOptionWidget.js
M modules/viewmodel/mw.echo.dm.NotificationItem.js
M modules/viewmodel/mw.echo.dm.NotificationsModel.js
M tests/browser/environments.yml
A tests/browser/features/notifications.feature
M tests/browser/features/step_definition/badge_steps.rb
A tests/browser/features/step_definition/notifications_steps.rb
M tests/browser/features/step_definition/popup_steps.rb
A tests/browser/features/support/echo_api_helper.rb
A tests/browser/features/support/echo_pageobject_extension.rb
M tests/browser/features/support/env.rb
M tests/browser/features/support/hooks.rb
M tests/browser/features/support/pages/article_page.rb
15 files changed, 176 insertions(+), 12 deletions(-)

Approvals:
  Sbisson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Gemfile b/Gemfile
index 25c3dbe..7c53c8d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,5 +1,5 @@
 source 'https://rubygems.org'
 
 gem 'csscss', '~> 1.3.3'
-gem 'mediawiki_selenium', '~> 1.4.0'
+gem 'mediawiki_selenium', '~> 1.6.1'
 gem 'rubocop', '~> 0.34.2', require: false
diff --git a/Gemfile.lock b/Gemfile.lock
index 35a5a70..86c30e3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -34,7 +34,7 @@
     ffi (1.9.10)
     gherkin (2.12.2)
       multi_json (~> 1.3)
-    headless (1.0.2)
+    headless (2.2.0)
     http-cookie (1.0.2)
       domain_name (~> 0.5)
     i18n (0.7.0)
@@ -42,13 +42,14 @@
     mediawiki_api (0.5.0)
       faraday (~> 0.9, >= 0.9.0)
       faraday-cookie_jar (~> 0.0, >= 0.0.6)
-    mediawiki_selenium (1.4.0)
+    mediawiki_selenium (1.6.1)
       cucumber (~> 1.3, >= 1.3.20)
-      headless (~> 1.0, >= 1.0.1)
+      headless (~> 2.0, >= 2.1.0)
       json (~> 1.8, >= 1.8.1)
-      mediawiki_api (~> 0.4, >= 0.4.1)
+      mediawiki_api (~> 0.5, >= 0.5.0)
       page-object (~> 1.0)
       rest-client (~> 1.6, >= 1.6.7)
+      rspec-core (~> 2.14, >= 2.14.4)
       rspec-expectations (~> 2.14, >= 2.14.4)
       syntax (~> 1.2, >= 1.2.0)
       thor (~> 0.19, >= 0.19.1)
@@ -73,6 +74,7 @@
       http-cookie (>= 1.0.2, < 2.0)
       mime-types (>= 1.16, < 3.0)
       netrc (~> 0.7)
+    rspec-core (2.99.2)
     rspec-expectations (2.99.2)
       diff-lcs (>= 1.1.3, < 2.0)
     rubocop (0.34.2)
@@ -103,8 +105,8 @@
 
 DEPENDENCIES
   csscss (~> 1.3.3)
-  mediawiki_selenium (~> 1.4.0)
+  mediawiki_selenium (~> 1.6.1)
+  rubocop (~> 0.34.2)
 
 BUNDLED WITH
    1.10.5
-  rubocop (~> 0.34.2)
diff --git a/modules/ooui/mw.echo.ui.NotificationOptionWidget.js 
b/modules/ooui/mw.echo.ui.NotificationOptionWidget.js
index 0e9526a..63f0d59 100644
--- a/modules/ooui/mw.echo.ui.NotificationOptionWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationOptionWidget.js
@@ -38,7 +38,7 @@
                } );
 
                this.$element
-                       .addClass( 'mw-echo-ui-notificationOptionWidget' )
+                       .addClass( 'mw-echo-ui-notificationOptionWidget 
mw-echo-ui-notificationOptionWidget-' + this.model.getType() )
                        .append(
                                // HACK: Wrap the entire option with a link 
that takes
                                // the user to the primary url. This is not 
perfect,
diff --git a/modules/viewmodel/mw.echo.dm.NotificationItem.js 
b/modules/viewmodel/mw.echo.dm.NotificationItem.js
index ed254f4..ea50f41 100644
--- a/modules/viewmodel/mw.echo.dm.NotificationItem.js
+++ b/modules/viewmodel/mw.echo.dm.NotificationItem.js
@@ -11,6 +11,7 @@
         * @cfg {jQuery|string} [content] The html content of this notification
         * @cfg {string} [category] The category of this notification. The 
category identifies
         *  where the notification originates from.
+        * @cfg {string} [type] The notification type 'message' or 'alert'
         * @cfg {boolean} [read=false] State the read state of the option
         * @cfg {boolean} [seen=false] State the seen state of the option
         * @cfg {string} [timestamp] Notification timestamp in Mediawiki 
timestamp format
@@ -39,6 +40,7 @@
                this.content = config.content || $();
 
                this.category = config.category || '';
+               this.type = config.type || 'alert';
 
                this.toggleRead( !!config.read );
                this.toggleSeen( !!config.seen );
@@ -92,6 +94,13 @@
        mw.echo.dm.NotificationItem.prototype.getCategory = function () {
                return this.category;
        };
+       /**
+        * Get NotificationItem type
+        * @return {string} NotificationItem type
+        */
+       mw.echo.dm.NotificationItem.prototype.getType = function () {
+               return this.type;
+       };
 
        /**
         * Check whether this notification item is read
diff --git a/modules/viewmodel/mw.echo.dm.NotificationsModel.js 
b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
index 7ec9b2e..06bb4de 100644
--- a/modules/viewmodel/mw.echo.dm.NotificationsModel.js
+++ b/modules/viewmodel/mw.echo.dm.NotificationsModel.js
@@ -337,6 +337,7 @@
                                                                timestamp: 
notifData.timestamp.mw,
                                                                category: 
notifData.category,
                                                                content: 
$content,
+                                                               type: 
model.getType(),
                                                                // Hack: Get 
the primary link from the $content
                                                                primaryUrl: 
$content.find( '.mw-echo-notification-primary-link' ).attr( 'href' )
                                                        }
diff --git a/tests/browser/environments.yml b/tests/browser/environments.yml
index 98b76d3..597f956 100644
--- a/tests/browser/environments.yml
+++ b/tests/browser/environments.yml
@@ -25,18 +25,19 @@
 local:
   mediawiki_user: Admin
   mediawiki_password: vagrant
-  mediawiki_user_b: Selenium Flow user 2
+  mediawiki_user_b: Selenium Echo user 2
   mediawiki_url: http://127.0.0.1:8080/wiki/
 
 beta:
   mediawiki_url: http://en.wikipedia.beta.wmflabs.org/wiki/
   mediawiki_user: Selenium_user
-  mediawiki_user_b: Selenium Flow user 2
+  mediawiki_user_b: Selenium Echo user 2
   # mediawiki_password: SET THIS IN THE ENVIRONMENT!
 
 test2:
   mediawiki_url: http://test2.wikipedia.org/wiki/
   mediawiki_user: Selenium_user
+  mediawiki_user_b: Selenium Echo user 2
   # mediawiki_password: SET THIS IN THE ENVIRONMENT!
 
 integration:
diff --git a/tests/browser/features/notifications.feature 
b/tests/browser/features/notifications.feature
new file mode 100644
index 0000000..c689bd8
--- /dev/null
+++ b/tests/browser/features/notifications.feature
@@ -0,0 +1,22 @@
+@chrome @firefox @internet_explorer_10
[email protected]
+Feature: Testing notification types
+
+  Background:
+    Given I am logged in
+    And all my notifications are read
+
+  Scenario: Someone mentions me
+    Given another user mentions me
+    When I refresh the page
+    Then the alert badge is showing unseen notifications
+    And the alert badge value is "1"
+
+  Scenario: Someone writes on my talk page
+    Given another user writes on my talk page
+    When I refresh the page
+    Then the message badge is showing unseen notifications
+    And the message badge value is "1"
+    When I click the message badge
+    And I see the message popup
+    Then there are "1" unread notifications in the message popup
diff --git a/tests/browser/features/step_definition/badge_steps.rb 
b/tests/browser/features/step_definition/badge_steps.rb
index ec92931..8cb7cfe 100644
--- a/tests/browser/features/step_definition/badge_steps.rb
+++ b/tests/browser/features/step_definition/badge_steps.rb
@@ -4,3 +4,7 @@
 Given(/^I click the alert badge$/) do
   on(ArticlePage).notifications_badge_alert
 end
+
+Given(/^I click the message badge$/) do
+  on(ArticlePage).notifications_badge_message
+end
diff --git a/tests/browser/features/step_definition/notifications_steps.rb 
b/tests/browser/features/step_definition/notifications_steps.rb
new file mode 100644
index 0000000..4c5721c
--- /dev/null
+++ b/tests/browser/features/step_definition/notifications_steps.rb
@@ -0,0 +1,68 @@
+Given(/^all my notifications are read$/) do
+  clear_unread_notifications(@username)
+end
+
+Given(/^I refresh the page$/) do
+  on(ArticlePage) do |page|
+    page.refresh
+  end
+end
+
+Given(/^another user mentions me$/) do
+  message = '===Mention test===\nI am mentioning [[User:' + user(nil) +
+    ']] in this page to test Echo notifications. ~~~~'
+  as_user(:b) do
+    api.create_page(
+    @data_manager.get('Echo_test_page'),
+    message
+  )
+  end
+end
+
+Given(/^another user writes on my talk page$/) do
+  talk_page = "User_talk:#{user}"
+  message = '===Talk page test===\n' +
+    'I am writing a message in your user page to test Echo notifications. ~~~~'
+  as_user(:b) do
+    api.create_page(talk_page, message)
+  end
+end
+
+Given(/^the alert badge is showing unseen notifications$/) do
+  on(ArticlePage) do |page|
+    page.refresh_until do
+      page.notifications_badge_alert_unseen_element.visible?
+    end
+  end
+end
+
+Given(/^the message badge is showing unseen notifications$/) do
+  on(ArticlePage) do |page|
+    page.refresh_until do
+      page.notifications_badge_message_unseen_element.visible?
+    end
+  end
+end
+
+Given(/^the alert badge value is "(.+)"$/) do |num|
+  on(ArticlePage) do |page|
+    page.refresh_until do
+      page.notifications_badge_alert_element.text == num
+    end
+  end
+end
+
+Given(/^the message badge value is "(.+)"$/) do |num|
+  on(ArticlePage) do |page|
+    page.refresh_until do
+      page.notifications_badge_message_element.text == num
+    end
+  end
+end
+
+Given(/^there are "(.+)" unread notifications in the message popup$/) do |num|
+  on(ArticlePage) do |page|
+    page.popup_title(page.popup_message_element)
+    expect(page.num_unread_message_notifications).to eq(num.to_i)
+  end
+end
diff --git a/tests/browser/features/step_definition/popup_steps.rb 
b/tests/browser/features/step_definition/popup_steps.rb
index 78e62a9..720e323 100644
--- a/tests/browser/features/step_definition/popup_steps.rb
+++ b/tests/browser/features/step_definition/popup_steps.rb
@@ -3,3 +3,9 @@
     expect(page.popup_title(page.popup_alert_element).text).to match('Alerts')
   end
 end
+
+Given(/^I see the message popup$/) do
+  on(ArticlePage) do |page|
+    expect(page.popup_title(page.popup_message_element).text).to 
match('Messages')
+  end
+end
diff --git a/tests/browser/features/support/echo_api_helper.rb 
b/tests/browser/features/support/echo_api_helper.rb
new file mode 100644
index 0000000..77b7e5a
--- /dev/null
+++ b/tests/browser/features/support/echo_api_helper.rb
@@ -0,0 +1,25 @@
+module EchoAPIHelper
+  def create_page_with_user(title, text, username)
+    as_user(username) do
+      api.create_page title, text
+    end
+  end
+
+  def clear_unread_notifications(username)
+    as_user(username) do
+      api.action('echomarkread', token_type: 'csrf', all: '1')
+    end
+  end
+
+  def update_seentime(username, notificationType)
+    as_user(username) do
+      api.action('echomarkseen', token_type: 'csrf', type: notificationType)
+    end
+  end
+
+  def watch_page(username, pageTitle)
+    as_user(username) do
+      api.action('watch', token_type: 'watch', title: pageTitle)
+    end
+  end
+end
diff --git a/tests/browser/features/support/echo_pageobject_extension.rb 
b/tests/browser/features/support/echo_pageobject_extension.rb
new file mode 100644
index 0000000..8e18a6e
--- /dev/null
+++ b/tests/browser/features/support/echo_pageobject_extension.rb
@@ -0,0 +1,9 @@
+module PageObject
+  def refresh_until(timeout = PageObject.default_page_wait, message = nil)
+    platform.wait_until(timeout, message) do
+      yield.tap do |result|
+        refresh unless result
+      end
+    end
+  end
+end
diff --git a/tests/browser/features/support/env.rb 
b/tests/browser/features/support/env.rb
index 05c47ca..6d2bedf 100644
--- a/tests/browser/features/support/env.rb
+++ b/tests/browser/features/support/env.rb
@@ -1,6 +1,7 @@
 require 'mediawiki_selenium'
 
-require 'mediawiki_selenium/support'
+require 'mediawiki_selenium/cucumber'
+require 'mediawiki_selenium/pages'
 require 'mediawiki_selenium/step_definitions'
 
 def env_or_default(key, default)
diff --git a/tests/browser/features/support/hooks.rb 
b/tests/browser/features/support/hooks.rb
index 916949c..0d84341 100644
--- a/tests/browser/features/support/hooks.rb
+++ b/tests/browser/features/support/hooks.rb
@@ -1,6 +1,10 @@
 # Allow running of bundle exec cucumber --dry-run -f stepdefs
 require 'mediawiki_selenium'
 require 'page-object'
+require_relative 'echo_api_helper'
+require_relative 'echo_pageobject_extension'
 require_relative 'data_manager'
 
+World(EchoAPIHelper)
+
 Before { @data_manager = DataManager.new }
diff --git a/tests/browser/features/support/pages/article_page.rb 
b/tests/browser/features/support/pages/article_page.rb
index bb1902b..216cc62 100644
--- a/tests/browser/features/support/pages/article_page.rb
+++ b/tests/browser/features/support/pages/article_page.rb
@@ -13,15 +13,27 @@
   div(:popup_message,
       css: '#pt-notifications-message 
.mw-echo-ui-notificationBadgeButtonPopupWidget-popup')
 
+  link(:notifications_badge_alert_unseen,
+       css: '#pt-notifications-alert a.mw-echo-unseen-notifications')
+  link(:notifications_badge_message_unseen,
+       css: '#pt-notifications-message a.mw-echo-unseen-notifications')
+
   # Popup elements
   button(:mark_all_read_button, css: 
'.mw-echo-ui-notificationsWidget-markAllReadButton')
   def popup_title(popupElement)
     popupElement.when_present.span_element(
       css: '.oo-ui-popupWidget-head > .oo-ui-labelElement-label')
   end
-  # span(:popup_title, css: '.oo-ui-popupWidget-head > 
.oo-ui-labelElement-label')
 
   # Notification elements
   a(:notification_option, css: '.mw-echo-ui-notificationOptionWidget')
+  a(:notification_option_unread, css: 
'.mw-echo-ui-notificationOptionWidget-unread')
   a(:notification_option_markRead, css: 
'.mw-echo-ui-notificationOptionWidget-markAsReadButton')
+  def num_unread_message_notifications
+    # Count the number of elements that are unseen notification divs
+    # Taken from 
http://stackoverflow.com/questions/6433084/how-to-get-the-number-of-elements-having-same-attribute-in-html-in-watir
+    browser.elements(
+      css: 
'.mw-echo-ui-notificationOptionWidget-unread.mw-echo-ui-notificationOptionWidget-message'
+      ).size
+  end
 end

-- 
To view, visit https://gerrit.wikimedia.org/r/242016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I40a17500cdfb838420c04dc0b9268ba56515cc2c
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>
Gerrit-Reviewer: Mooeypoo <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to