2020-06-22 21:49:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* global document */
|
|
|
|
|
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 );
|
|
|
|
} );
|
2020-07-24 11:22:26 +00:00
|
|
|
} ).then( async ( content ) => {
|
|
|
|
const bot = await Api.bot();
|
|
|
|
await bot.edit( title, content );
|
2019-02-01 21:30:32 +00:00
|
|
|
} );
|
|
|
|
}
|
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 } );
|
2020-07-24 11:22:26 +00:00
|
|
|
return result;
|
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() {
|
2020-10-29 14:33:53 +00:00
|
|
|
return browser.execute( () => mw.config.get( 'wgPopupsReferencePreviews' ) );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 14:35:04 +00:00
|
|
|
abandonLink() {
|
2020-07-24 11:22:26 +00:00
|
|
|
$( '#content h1' ).moveTo();
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
dwellLink( selector ) {
|
2020-07-24 11:22:26 +00:00
|
|
|
$( selector ).moveTo();
|
|
|
|
$( POPUPS_SELECTOR ).waitForExist();
|
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() {
|
2020-07-24 11:22:26 +00:00
|
|
|
$( PAGE_POPUPS_LINK_SELECTOR ).moveTo();
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 13:49:39 +00:00
|
|
|
clickReferenceLink( num ) {
|
|
|
|
this.click( `.reference:nth-of-type(${num}) a` );
|
|
|
|
}
|
|
|
|
|
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() {
|
2020-07-24 11:22:26 +00:00
|
|
|
$( REFERENCE_INCEPTION_LINK_SELECTOR ).moveTo();
|
2019-03-22 17:36:34 +00:00
|
|
|
browser.pause( 1000 );
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
doNotSeePreview( selector ) {
|
2020-07-24 11:22:26 +00:00
|
|
|
return browser.waitUntil( () => !$( selector ).isDisplayed() );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doNotSeePagePreview() {
|
|
|
|
return this.doNotSeePreview( PAGE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
doNotSeeReferencePreview() {
|
|
|
|
return this.doNotSeePreview( REFERENCE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
seePreview( selector ) {
|
2020-07-24 11:22:26 +00:00
|
|
|
return $( selector ).isDisplayed();
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-07-24 11:22:26 +00:00
|
|
|
} );
|
2019-03-21 10:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
seeFadeoutOnReferenceText() {
|
2020-07-24 11:22:26 +00:00
|
|
|
return $( '.mwe-popups-fade-out' ).isExisting();
|
2019-03-21 10:59:22 +00:00
|
|
|
}
|
|
|
|
|
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();
|