2018-04-10 21:19:08 +00:00
|
|
|
/**
|
|
|
|
* Represents a page the can be presented in desktop
|
|
|
|
* or mobile mode (requires mobilefrontend), and has
|
|
|
|
* features like public 'beta' mode (requires mobilefrontend).
|
|
|
|
*
|
|
|
|
* @extends Page
|
|
|
|
* @example
|
|
|
|
* https://en.m.wikipedia.org/wiki/Barack_Obama
|
|
|
|
*/
|
|
|
|
|
2020-06-02 21:21:44 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-10 21:19:08 +00:00
|
|
|
const { Page } = require( './mw_core_pages' );
|
|
|
|
|
|
|
|
class MinervaPage extends Page {
|
|
|
|
|
|
|
|
get title() { return browser.getTitle(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a page if it isn't already open.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2018-04-10 21:19:08 +00:00
|
|
|
* @param {string} path
|
|
|
|
*/
|
|
|
|
open( path = 'Main_Page' ) {
|
|
|
|
const currentPage = browser.getUrl(),
|
|
|
|
newPage = browser.options.baseUrl + '/index.php?title=' + path;
|
|
|
|
if ( currentPage !== newPage ) {
|
|
|
|
browser.url( newPage );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure browser is opened on a MediaWiki page, and set a specified
|
|
|
|
* cookie for that domain.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2018-04-10 21:19:08 +00:00
|
|
|
* @param {string} name - name of the cookie
|
|
|
|
* @param {string} value - value of the cookie
|
|
|
|
*/
|
|
|
|
setCookie( name, value ) {
|
|
|
|
const currentPage = browser.getUrl();
|
|
|
|
if ( !currentPage.includes( browser.options.baseUrl ) ) {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:54:05 +00:00
|
|
|
const cookie = browser.getCookies( [ name ] );
|
2018-04-10 21:19:08 +00:00
|
|
|
|
|
|
|
if ( !cookie || cookie.value !== value ) {
|
2020-06-15 14:54:05 +00:00
|
|
|
browser.setCookies( {
|
2018-04-10 21:19:08 +00:00
|
|
|
name: name,
|
|
|
|
value: value } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the mobile cookie
|
|
|
|
*/
|
|
|
|
setMobileMode() {
|
|
|
|
this.setCookie( 'mf_useformat', 'true' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the beta cookie
|
|
|
|
*/
|
|
|
|
setBetaMode() {
|
|
|
|
this.setCookie( 'optin', 'beta' );
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:09:47 +00:00
|
|
|
waitUntilResourceLoaderModuleReady( moduleName ) {
|
|
|
|
browser.waitUntil( () => {
|
|
|
|
const state = browser.execute( ( m ) => {
|
|
|
|
return mw.loader.getState( m );
|
|
|
|
}, moduleName );
|
2020-06-15 14:54:05 +00:00
|
|
|
return state === 'ready';
|
2019-04-05 21:09:47 +00:00
|
|
|
} );
|
|
|
|
}
|
2018-04-10 21:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MinervaPage;
|