mediawiki-extensions-Popups/tests/selenium/pageobjects/popups.page.js

127 lines
3.2 KiB
JavaScript
Raw Normal View History

'use strict';
/* global document */
const
fs = require( 'fs' ),
Api = require( 'wdio-mediawiki/Api' ),
Page = require( 'wdio-mediawiki/Page' ),
Util = require( 'wdio-mediawiki/Util' ),
TEST_PAGE_POPUPS_TITLE = 'Page popups test page',
TEST_REFERENCE_POPUPS_TITLE = 'Reference popups test page',
POPUPS_SELECTOR = '.mwe-popups',
PAGE_POPUPS_SELECTOR = '.mwe-popups-type-page',
PAGE_POPUPS_LINK_SELECTOR = '.mw-body-content ul a',
REFERENCE_POPUPS_SELECTOR = '.mwe-popups-type-reference',
REFERENCE_INCEPTION_LINK_SELECTOR = '.mwe-popups-type-reference .reference a',
POPUPS_MODULE_NAME = 'ext.popups.main';
async function makePage( title, path ) {
const content = fs.readFileSync( path, 'utf-8' );
const bot = await Api.bot();
await bot.edit( title, content );
}
class PopupsPage extends Page {
async setupPagePreviews() {
return browser.call( async () => {
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` );
} );
}
async setupReferencePreviews() {
return browser.call( async () => {
const path = `${__dirname}/../fixtures/`;
await makePage( TEST_REFERENCE_POPUPS_TITLE, `${path}test_page.wikitext` );
} );
}
async ready() {
await Util.waitForModuleState( POPUPS_MODULE_NAME );
}
async abandonLink() {
return $( '#content h1' ).moveTo();
}
async dwellLink( selector, doesNotTriggerPreview ) {
await $( selector ).moveTo();
if ( !doesNotTriggerPreview ) {
await $( POPUPS_SELECTOR ).waitForExist();
} else {
await browser.pause( 1000 );
}
}
async dwellPageLink() {
await this.dwellLink( PAGE_POPUPS_LINK_SELECTOR );
}
async dwellPageFragment() {
await this.dwellLink( '[href="#section"]', true );
}
async hoverPageLink() {
await $( PAGE_POPUPS_LINK_SELECTOR ).moveTo();
}
async dwellReferenceLink( id ) {
await this.dwellLink( `#${id} a` );
}
async dwellReferenceInceptionLink() {
await $( REFERENCE_INCEPTION_LINK_SELECTOR ).moveTo();
await browser.pause( 1000 );
}
async doNotSeePreview( selector ) {
return browser.waitUntil( async () => !( await $( selector ).isDisplayed() ) );
}
async doNotSeePagePreview() {
return this.doNotSeePreview( PAGE_POPUPS_SELECTOR );
}
async doNotSeeReferencePreview() {
return this.doNotSeePreview( REFERENCE_POPUPS_SELECTOR );
}
async seePreview( selector ) {
return await $( selector ).isDisplayed();
}
async seePagePreview() {
return await this.seePreview( PAGE_POPUPS_SELECTOR );
}
async seeReferencePreview() {
return await this.seePreview( REFERENCE_POPUPS_SELECTOR );
}
async seeReferenceInceptionPreview() {
return await this.seePreview( REFERENCE_INCEPTION_LINK_SELECTOR );
}
async seeScrollableReferencePreview() {
return browser.execute( () => {
const el = document.querySelector( '.mwe-popups-extract .mwe-popups-scroll' );
return el.scrollHeight > el.offsetHeight;
} );
}
async seeFadeoutOnReferenceText() {
return $( '.mwe-popups-fade-out' ).isExisting();
}
async openPagePopupsTest() {
return super.openTitle( TEST_PAGE_POPUPS_TITLE );
}
async openReferencePopupsTest() {
return super.openTitle( TEST_REFERENCE_POPUPS_TITLE );
}
}
module.exports = new PopupsPage();