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' ),
|
2020-11-18 13:09:36 +00:00
|
|
|
Util = require( 'wdio-mediawiki/Util' ),
|
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',
|
2022-06-15 17:09:21 +00:00
|
|
|
PAGE_POPUPS_LINK_SELECTOR = '.mw-body-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
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-03-15 19:24:34 +00:00
|
|
|
ready() {
|
2020-11-20 09:35:10 +00:00
|
|
|
Util.waitForModuleState( POPUPS_MODULE_NAME );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 13:09:36 +00:00
|
|
|
shouldUseReferencePopupsBetaFeature( shouldUse ) {
|
|
|
|
Util.waitForModuleState( 'mediawiki.base' );
|
|
|
|
return browser.execute( function ( use ) {
|
|
|
|
return mw.loader.using( 'mediawiki.api' ).then( function () {
|
2021-05-04 08:42:59 +00:00
|
|
|
return new mw.Api().saveOptions( {
|
|
|
|
// TODO: Remove the first option when all Beta code is gone
|
|
|
|
popupsreferencepreviews: use ? '1' : '0',
|
|
|
|
'popups-reference-previews': use ? '1' : '0'
|
|
|
|
} );
|
2020-11-18 13:09:36 +00:00
|
|
|
} );
|
|
|
|
}, shouldUse );
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:11:13 +00:00
|
|
|
hasReferencePopupsEnabled() {
|
2020-11-18 13:09:36 +00:00
|
|
|
// TODO Remove or adjust when not in Beta any more
|
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
|
|
|
}
|
|
|
|
|
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( () => {
|
2020-11-18 13:09:36 +00:00
|
|
|
const el = document.querySelector( '.mwe-popups-extract .mwe-popups-scroll' );
|
2019-03-21 10:59:22 +00:00
|
|
|
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();
|