Add browser test for basic watchlist functionality
authorJakob Warkotsch <j.warkotsch@gmail.com>
Mon, 18 Jun 2018 14:13:42 +0000 (16:13 +0200)
committerJakob Warkotsch <j.warkotsch@gmail.com>
Tue, 19 Jun 2018 14:24:48 +0000 (16:24 +0200)
Will be used to test more advanced title/link formatters downstream.

Bug: T191601
Change-Id: I0747c2d361e951f8b3765a3dca548e55edb72216

tests/selenium/pageobjects/watchable.page.js [new file with mode: 0644]
tests/selenium/pageobjects/watchlist.page.js [new file with mode: 0644]
tests/selenium/specs/specialwatchlist.js [new file with mode: 0644]

diff --git a/tests/selenium/pageobjects/watchable.page.js b/tests/selenium/pageobjects/watchable.page.js
new file mode 100644 (file)
index 0000000..896b2f4
--- /dev/null
@@ -0,0 +1,13 @@
+const Page = require( 'wdio-mediawiki/Page' );
+
+class WatchablePage extends Page {
+
+       get confirmWatch() { return browser.element( '#mw-content-text button[type="submit"]' ); }
+
+       watch( title ) {
+               super.openTitle( title, { action: 'watch' } );
+               this.confirmWatch.click();
+       }
+}
+
+module.exports = new WatchablePage();
diff --git a/tests/selenium/pageobjects/watchlist.page.js b/tests/selenium/pageobjects/watchlist.page.js
new file mode 100644 (file)
index 0000000..58a003f
--- /dev/null
@@ -0,0 +1,15 @@
+const Page = require( 'wdio-mediawiki/Page' );
+
+class WatchlistPage extends Page {
+       get titles() {
+               return browser.element( '.mw-changeslist' )
+                       .$$( '.mw-changeslist-line .mw-title' );
+       }
+
+       open() {
+               super.openTitle( 'Special:Watchlist' );
+       }
+
+}
+
+module.exports = new WatchlistPage();
diff --git a/tests/selenium/specs/specialwatchlist.js b/tests/selenium/specs/specialwatchlist.js
new file mode 100644 (file)
index 0000000..1e33b2b
--- /dev/null
@@ -0,0 +1,44 @@
+const assert = require( 'assert' ),
+       Api = require( 'wdio-mediawiki/Api' ),
+       WatchlistPage = require( '../pageobjects/watchlist.page' ),
+       WatchablePage = require( '../pageobjects/watchable.page' ),
+       LoginPage = require( 'wdio-mediawiki/LoginPage' );
+
+describe( 'Special:Watchlist', function () {
+       let username, password;
+
+       function getTestString( prefix = '' ) {
+               return prefix + Math.random().toString() + '-öäü-♠♣♥♦';
+       }
+
+       before( function () {
+               username = getTestString( 'user-' );
+               password = getTestString( 'password-' );
+
+               browser.call( function () {
+                       return Api.createAccount( username, password );
+               } );
+       } );
+
+       beforeEach( function () {
+               browser.deleteCookie();
+               LoginPage.login( username, password );
+       } );
+
+       it( 'should show page with new edit', function () {
+               const title = getTestString( 'Title-' );
+
+               browser.call( function () {
+                       return Api.edit( title, getTestString() ); // create
+               } );
+               WatchablePage.watch( title );
+               browser.call( function () {
+                       return Api.edit( title, getTestString() ); // edit
+               } );
+
+               WatchlistPage.open();
+
+               assert.strictEqual( WatchlistPage.titles[ 0 ].getText(), title );
+       } );
+
+} );