2020-06-22 21:49:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
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',
|
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',
|
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 ) {
|
2024-01-11 09:43:59 +00:00
|
|
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
2023-06-29 09:11:47 +00:00
|
|
|
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 () => {
|
2024-01-11 09:43:59 +00:00
|
|
|
const path = `${ __dirname }/../fixtures/`;
|
|
|
|
await makePage( `${ TEST_PAGE_POPUPS_TITLE } 2`, `${ path }test_page_2.wikitext` );
|
|
|
|
await makePage( TEST_PAGE_POPUPS_TITLE, `${ path }test_page.wikitext` );
|
2023-06-29 09:11:47 +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 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-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 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 openPagePopupsTest() {
|
|
|
|
return super.openTitle( TEST_PAGE_POPUPS_TITLE );
|
2023-06-29 09:11:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 14:35:04 +00:00
|
|
|
}
|
|
|
|
module.exports = new PopupsPage();
|