Jdrewniak has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/267077

Change subject: Adding Integration test to verify event-logging on 
wikipedia.org portal.
......................................................................

Adding Integration test to verify event-logging on wikipedia.org portal.

Change-Id: I4154e65330ae092fc0f05742df5f381de90a495f
---
M package.json
A tests/casper.js
2 files changed, 137 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/portals 
refs/changes/77/267077/1

diff --git a/package.json b/package.json
index 5af6ca4..20816f3 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,8 @@
 {
   "private": true,
   "scripts": {
-    "test": "gulp lint"
+    "test": "gulp lint",
+    "casperjs": "casperjs test ./tests/casper.js"
   },
   "devDependencies": {
     "bluebird": "^3.0.5",
@@ -24,6 +25,8 @@
     "moment": "^2.10.6",
     "preq": "^0.4.6",
     "underscore": "^1.8.3",
-    "yargs": "^3.29.0"
+    "yargs": "^3.29.0",
+    "casperjs": "git+https://github.com/n1k0/casperjs.git";,
+    "phantomjs2": "^2.0.2"
   }
 }
diff --git a/tests/casper.js b/tests/casper.js
new file mode 100644
index 0000000..6b22fae
--- /dev/null
+++ b/tests/casper.js
@@ -0,0 +1,132 @@
+// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
+/* global casper, console */
+
+/**
+ * Integration Test for wikipedia.org portal event logging.
+ * Run from the main project directory with
+ * $ npm run casperjs
+ *
+ * Set to check the portal URL from IntelliJ IDEA server on port 63342.
+ * If using a different port for localhost, change the portalUrl variable 
accordingly.
+ *
+ * This baseline test:
+ * - opens the wikipedia portal
+ * - sets the event logging group to 'baseline'
+ * - reloads the page
+ * - checks for a landing EL request
+ * - checks for clickthrough events on all sections.
+ * - changes the search language, (to french)
+ * - submits the search form
+ * - checks if the search form directs to the correct search results page
+ **/
+
+casper.test.begin( 'Wikipedia Portal - baseline', function suite( test ) {
+
+       var existingEvents = {},
+               portalUrl = 
'http://localhost:63342/portals/prod/wikipedia.org/',
+               languagePickerLang = 'fr',
+               searchTerm = '~paris';
+
+       /**
+        * In development, eventLogging events are sent to a 
event.gif?{event..} URL endpoint
+        * This function parses the URL and returns a javascript object 
representing the EL data.
+        */
+       function parseElResource( resource ) {
+               var obj = decodeURIComponent( resource.url.replace( /.*\?/, '' 
) );
+               return JSON.parse( obj );
+       }
+
+       /**
+        * For eventlogging actions that are triggered by a click.
+        * Selects the first child link in the EL section.
+        * clicks the links and asserts if an EL request was sent.
+        */
+       function testLinkEvent( casper, test, section ) {
+               test.assertExists( '[data-el-section="' + section + '"]' );
+               casper.click( '[data-el-section="' + section + '"] * a' );
+               test.assertTruthy( existingEvents[ section ], 'event-logging ' 
+ section + ' sent.' );
+               casper.back();
+       }
+
+       /**
+        * Keeps a log of EL requests in an array.
+        */
+       function saveELRequest( request ) {
+               if ( request.url.match( 'event.gif' ) ) {
+
+                       var parsedRequest = parseElResource( request ),
+                               elSection = parsedRequest.event.section_used;
+
+                       if ( !existingEvents[ elSection ] ) {
+                               existingEvents[ elSection ] =  parsedRequest;
+                       }
+               }
+       }
+
+       /**
+        * Opens the portal URL, sets the localStorage to baseline EL group
+        * reloads the page.
+        */
+       casper.start( portalUrl, function () {
+
+               casper.evaluate( function () {
+                       console.log( 'setting EL group to baseline' );
+                       localStorage.setItem( 'portal_test_group', 'baseline' );
+               } );
+
+               casper.then( function () {
+                       casper.reload( function () {
+                               this.echo( 'reloaded page as baseline group' );
+                       } );
+               } );
+       } );
+
+       /**
+        * The resource.requested event is fired when a resource is requested.
+        * binding this event to the saveELRequest functions saves the EL 
requests
+        * to an array.
+        */
+       casper.on( 'resource.requested', saveELRequest );
+
+       /**
+        * Tests if the EL sections that should send an event on click, 
actually do.
+        */
+       casper.then( testLinkEvent.bind( this, casper, test, 'primary links' ) 
);
+       casper.then( testLinkEvent.bind( this, casper, test, 'secondary links' 
) );
+       casper.then( testLinkEvent.bind( this, casper, test, 'other languages' 
) );
+       casper.then( testLinkEvent.bind( this, casper, test, 'other projects' ) 
);
+
+       /**
+        * changes the language picker search language and submits the search 
form.
+        */
+       casper.then( function () {
+
+               this.click( 'select#searchLanguage' );
+
+               this.fillSelectors( 'form.search-form', {
+                       'select#searchLanguage': languagePickerLang,
+                       'input#searchInput': searchTerm
+               }, true );
+
+               test.assertTruthy( existingEvents.search, 'event-logging search 
sent.' );
+
+       } );
+
+       /**
+        * checks if the search form was correctly submitted.
+        */
+       casper.then( function () {
+               casper.wait( 600, function () {
+                       var searchTermRegex = new RegExp( '/search=' + 
searchTerm + '/' ),
+                               languageRegex = new RegExp( '/https\:\/\/' + 
languagePickerLang + '/' );
+                       test.assertTruthy( function () {
+                               return searchTermRegex.test( 
this.getCurrentUrl() ) && languageRegex.test( this.getCurrenUrl() );
+                       }, 'search for \'' + searchTerm + '\' in lang=\'' + 
languagePickerLang + '\' submitted. New URL is:' + this.getCurrentUrl() );
+               } );
+       } );
+
+       casper.run( function() {
+               test.done();
+       } );
+
+} );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4154e65330ae092fc0f05742df5f381de90a495f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/portals
Gerrit-Branch: master
Gerrit-Owner: Jdrewniak <[email protected]>

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

Reply via email to