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' ),
|
2023-06-29 09:11:47 +00:00
|
|
|
TEST_PAGE_POPUPS_TITLE = 'Page popups test page',
|
|
|
|
TEST_REFERENCE_POPUPS_TITLE = 'Reference popups test page',
|
2018-03-15 16:30:11 +00:00
|
|
|
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
|
|
|
|
2023-06-29 09:11:47 +00:00
|
|
|
async function makePage( title, path ) {
|
|
|
|
const content = fs.readFileSync( path, 'utf-8' );
|
|
|
|
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 {
|
2023-07-18 07:34:47 +00:00
|
|
|
async setupPagePreviews() {
|
|
|
|
return browser.call( async () => {
|
2019-08-05 12:42:21 +00:00
|
|
|
const path = `${__dirname}/../fixtures/`;
|
2023-06-29 09:11:47 +00:00
|
|
|
await makePage( `${TEST_PAGE_POPUPS_TITLE} 2`, `${path}test_page_2.wikitext` );
|
|
|
|
await makePage( TEST_PAGE_POPUPS_TITLE, `${path}test_page.wikitext` );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async setupReferencePreviews() {
|
|
|
|
return browser.call( async () => {
|
2023-06-29 09:11:47 +00:00
|
|
|
const path = `${__dirname}/../fixtures/`;
|
|
|
|
await makePage( TEST_REFERENCE_POPUPS_TITLE, `${path}test_page.wikitext` );
|
2017-09-01 14:35:04 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async ready() {
|
|
|
|
await Util.waitForModuleState( POPUPS_MODULE_NAME );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async shouldUseReferencePopupsBetaFeature() {
|
|
|
|
await Util.waitForModuleState( 'mediawiki.base' );
|
|
|
|
await browser.execute( function () {
|
2020-11-18 13:09:36 +00:00
|
|
|
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
|
2023-07-18 07:34:47 +00:00
|
|
|
popupsreferencepreviews: '1',
|
|
|
|
'popups-reference-previews': '1'
|
2021-05-04 08:42:59 +00:00
|
|
|
} );
|
2020-11-18 13:09:36 +00:00
|
|
|
} );
|
2023-07-18 07:34:47 +00:00
|
|
|
} );
|
2020-11-18 13:09:36 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async 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
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async abandonLink() {
|
|
|
|
return $( '#content h1' ).moveTo();
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async dwellLink( selector, doesNotTriggerPreview ) {
|
|
|
|
await $( selector ).moveTo();
|
2023-01-11 16:51:42 +00:00
|
|
|
if ( !doesNotTriggerPreview ) {
|
2023-07-18 07:34:47 +00:00
|
|
|
await $( POPUPS_SELECTOR ).waitForExist();
|
2023-01-11 16:51:42 +00:00
|
|
|
} else {
|
2023-07-18 07:34:47 +00:00
|
|
|
await browser.pause( 1000 );
|
2023-01-11 16:51:42 +00:00
|
|
|
}
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async dwellPageLink() {
|
|
|
|
await this.dwellLink( PAGE_POPUPS_LINK_SELECTOR );
|
2019-04-02 11:04:27 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async dwellPageFragment() {
|
|
|
|
await this.dwellLink( '[href="#section"]', true );
|
2023-01-11 16:51:42 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async hoverPageLink() {
|
|
|
|
await $( PAGE_POPUPS_LINK_SELECTOR ).moveTo();
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 22:47:24 +00:00
|
|
|
async dwellReferenceLink( id ) {
|
|
|
|
await this.dwellLink( `#${id} a` );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async dwellReferenceInceptionLink() {
|
|
|
|
await $( REFERENCE_INCEPTION_LINK_SELECTOR ).moveTo();
|
|
|
|
await browser.pause( 1000 );
|
2019-03-22 17:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async doNotSeePreview( selector ) {
|
|
|
|
return browser.waitUntil( async () => !( await $( selector ).isDisplayed() ) );
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async doNotSeePagePreview() {
|
2019-01-21 17:11:13 +00:00
|
|
|
return this.doNotSeePreview( PAGE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async doNotSeeReferencePreview() {
|
2019-01-21 17:11:13 +00:00
|
|
|
return this.doNotSeePreview( REFERENCE_POPUPS_SELECTOR );
|
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seePreview( selector ) {
|
|
|
|
return await $( selector ).isDisplayed();
|
2019-01-21 17:11:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seePagePreview() {
|
|
|
|
return await this.seePreview( PAGE_POPUPS_SELECTOR );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seeReferencePreview() {
|
|
|
|
return await this.seePreview( REFERENCE_POPUPS_SELECTOR );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seeReferenceInceptionPreview() {
|
|
|
|
return await this.seePreview( REFERENCE_INCEPTION_LINK_SELECTOR );
|
2019-03-22 17:36:34 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seeScrollableReferencePreview() {
|
2019-03-21 10:59:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async seeFadeoutOnReferenceText() {
|
2020-07-24 11:22:26 +00:00
|
|
|
return $( '.mwe-popups-fade-out' ).isExisting();
|
2019-03-21 10:59:22 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async openPagePopupsTest() {
|
|
|
|
return super.openTitle( TEST_PAGE_POPUPS_TITLE );
|
2023-06-29 09:11:47 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 07:34:47 +00:00
|
|
|
async openReferencePopupsTest() {
|
|
|
|
return super.openTitle( TEST_REFERENCE_POPUPS_TITLE );
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
module.exports = new PopupsPage();
|