2018-03-15 16:30:11 +00:00
|
|
|
const
|
|
|
|
fs = require( 'fs' ),
|
2018-07-31 16:04:12 +00:00
|
|
|
Api = require( 'wdio-mediawiki/Api' ),
|
|
|
|
Page = require( 'wdio-mediawiki/Page' ),
|
2018-03-15 16:30:11 +00:00
|
|
|
TEST_PAGE_TITLE = 'Popups test page',
|
|
|
|
POPUPS_SELECTOR = '.mwe-popups',
|
2019-01-21 17:11:13 +00:00
|
|
|
PAGE_POPUPS_SELECTOR = '.mwe-popups-type-page',
|
2019-04-02 11:04:27 +00:00
|
|
|
PAGE_POPUPS_LINK_SELECTOR = '#content ul a',
|
2019-01-21 17:11:13 +00:00
|
|
|
REFERENCE_POPUPS_SELECTOR = '.mwe-popups-type-reference',
|
2019-03-22 17:36:34 +00:00
|
|
|
REFERENCE_INCEPTION_LINK_SELECTOR = '.mwe-popups-type-reference .reference a',
|
2018-03-15 16:30:11 +00:00
|
|
|
POPUPS_MODULE_NAME = 'ext.popups.main';
|
2017-09-01 14:35:04 +00:00
|
|
|
|
2019-02-01 21:30:32 +00:00
|
|
|
function makePage( title, path ) {
|
|
|
|
return new Promise( ( resolve ) => {
|
|
|
|
fs.readFile( path, 'utf-8', ( err, content ) => {
|
|
|
|
if ( err ) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
resolve( content );
|
|
|
|
} );
|
|
|
|
} ).then( ( content ) => {
|
|
|
|
return Api.edit( title, content );
|
|
|
|
} );
|
|
|
|
}
|
2017-09-01 14:35:04 +00:00
|
|
|
class PopupsPage extends Page {
|
|
|
|
setup() {
|
2018-03-14 23:50:09 +00:00
|
|
|
browser.call( () => {
|
2019-08-05 12:42:21 +00:00
|
|
|
const path = `${__dirname}/../fixtures/`;
|
2019-02-01 21:30:32 +00:00
|
|
|
// FIXME: Cannot use Promise.all as wdio-mediawiki/Api will trigger a bad
|
|
|
|
// token error.
|
|
|
|
return makePage( `${TEST_PAGE_TITLE} 2`, `${path}/test_page_2.wikitext` ).then( () => {
|
|
|
|
return makePage( TEST_PAGE_TITLE, `${path}test_page.wikitext` );
|
2017-09-01 14:35:04 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceLoaderModuleStatus( moduleName, moduleStatus, errMsg ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
// Word of caution: browser.waitUntil returns a Timer class NOT a Promise.
|
|
|
|
// Webdriver IO will run waitUntil synchronously so not returning it will
|
|
|
|
// block JavaScript execution while returning it will not.
|
|
|
|
// http://webdriver.io/api/utility/waitUntil.html
|
|
|
|
// https://github.com/webdriverio/webdriverio/blob/master/lib/utils/Timer.js
|
2018-03-14 23:50:09 +00:00
|
|
|
browser.waitUntil( () => {
|
2019-04-08 17:09:05 +00:00
|
|
|
const result = browser.execute( ( module ) => {
|
2019-04-08 17:20:02 +00:00
|
|
|
return typeof mw !== 'undefined' &&
|
|
|
|
mw.loader.getState( module.name ) === module.status;
|
2017-09-01 14:35:04 +00:00
|
|
|
}, { status: moduleStatus, name: moduleName } );
|
2019-04-08 17:09:05 +00:00
|
|
|
return result.value;
|
2017-09-01 14:35:04 +00:00
|
|
|
}, 10000, errMsg );
|
|
|
|
}
|
|
|
|
|
2018-03-15 19:24:34 +00:00
|
|
|
ready() {
|
2018-03-20 20:20:43 +00:00
|
|
|
this.resourceLoaderModuleStatus( POPUPS_MODULE_NAME, 'ready', 'Popups did not load' );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
hasReferencePopupsEnabled() {
|
|
|
|
return browser.execute( function () {
|
2019-10-17 08:51:49 +00:00
|
|
|
return mw.config.get( 'wgPopupsReferencePreviews' );
|
2019-01-21 17:11:13 +00:00
|
|
|
} ).value;
|
|
|
|
}
|
|
|
|
|
2017-09-01 14:35:04 +00:00
|
|
|
abandonLink() {
|
2018-03-15 19:24:34 +00:00
|
|
|
browser.moveToObject( '#content h1' );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
dwellLink( selector ) {
|
|
|
|
browser.moveToObject( selector );
|
2018-03-15 19:24:34 +00:00
|
|
|
browser.waitForExist( POPUPS_SELECTOR );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
dwellPageLink() {
|
2019-04-02 11:04:27 +00:00
|
|
|
this.dwellLink( PAGE_POPUPS_LINK_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
hoverPageLink() {
|
|
|
|
browser.moveToObject( PAGE_POPUPS_LINK_SELECTOR );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 10:59:22 +00:00
|
|
|
dwellReferenceLink( num ) {
|
2019-08-05 12:42:21 +00:00
|
|
|
this.dwellLink( `.reference:nth-of-type(${num}) a` );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 17:36:34 +00:00
|
|
|
dwellReferenceInceptionLink() {
|
|
|
|
browser.moveToObject( REFERENCE_INCEPTION_LINK_SELECTOR );
|
|
|
|
browser.pause( 1000 );
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
doNotSeePreview( selector ) {
|
|
|
|
return browser.waitUntil( () => !browser.isVisible( selector ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
doNotSeePagePreview() {
|
|
|
|
return this.doNotSeePreview( PAGE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
doNotSeeReferencePreview() {
|
|
|
|
return this.doNotSeePreview( REFERENCE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
seePreview( selector ) {
|
|
|
|
return browser.isVisible( selector );
|
|
|
|
}
|
|
|
|
|
|
|
|
seePagePreview() {
|
|
|
|
return this.seePreview( PAGE_POPUPS_SELECTOR );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
seeReferencePreview() {
|
|
|
|
return this.seePreview( REFERENCE_POPUPS_SELECTOR );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 17:36:34 +00:00
|
|
|
seeReferenceInceptionPreview() {
|
|
|
|
return this.seePreview( REFERENCE_INCEPTION_LINK_SELECTOR );
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:59:22 +00:00
|
|
|
seeScrollableReferencePreview() {
|
|
|
|
return browser.execute( () => {
|
|
|
|
const el = document.querySelector( '.mwe-popups-extract .mw-parser-output' );
|
|
|
|
return el.scrollHeight > el.offsetHeight;
|
|
|
|
} ).value;
|
|
|
|
}
|
|
|
|
|
|
|
|
seeFadeoutOnReferenceText() {
|
|
|
|
return browser.isExisting( '.mwe-popups-fade-out' );
|
|
|
|
}
|
|
|
|
|
2017-09-01 14:35:04 +00:00
|
|
|
open() {
|
2018-07-31 16:04:12 +00:00
|
|
|
super.openTitle( TEST_PAGE_TITLE );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
module.exports = new PopupsPage();
|