2020-12-18 16:32:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Page = require( 'wdio-mediawiki/Page' );
|
|
|
|
|
|
|
|
// Copied from mediawiki-core edit.page.js
|
|
|
|
class EditPage extends Page {
|
2023-10-11 05:25:08 +00:00
|
|
|
async openForEditing( title, cm6enable = false ) {
|
|
|
|
const queryParams = {
|
|
|
|
action: 'edit',
|
|
|
|
vehidebetadialog: 1,
|
|
|
|
hidewelcomedialog: 1
|
|
|
|
};
|
|
|
|
if ( cm6enable ) {
|
|
|
|
queryParams.cm6enable = '1';
|
|
|
|
}
|
|
|
|
await super.openTitle( title, queryParams );
|
2020-12-18 16:32:22 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 11:14:55 +00:00
|
|
|
get wikiEditorToolbar() { return $( '#wikiEditor-ui-toolbar' ); }
|
2020-12-18 16:32:22 +00:00
|
|
|
get legacyTextInput() { return $( '#wpTextbox1' ); }
|
2023-10-18 00:34:33 +00:00
|
|
|
get legacyCodeMirrorButton() { return $( '#mw-editbutton-codemirror' ); }
|
2023-04-03 17:14:23 +00:00
|
|
|
async clickText() {
|
|
|
|
if ( await this.visualEditorSave.isDisplayed() ) {
|
|
|
|
await this.visualEditorSurface.click();
|
|
|
|
} else if ( await this.legacyTextInput.isDisplayed() ) {
|
|
|
|
await this.legacyTextInput.click();
|
2020-12-18 16:32:22 +00:00
|
|
|
} else {
|
|
|
|
// Click the container, if using WikiEditor etc.
|
2023-04-03 17:14:23 +00:00
|
|
|
await this.legacyTextInput.parentElement().click();
|
2020-12-18 16:32:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:14:55 +00:00
|
|
|
get visualEditorSave() { return $( '.ve-ui-toolbar-saveButton' ); }
|
|
|
|
get visualEditorSurface() { return $( '.ve-ui-surface-source' ); }
|
|
|
|
|
2023-04-03 17:14:23 +00:00
|
|
|
async cursorToPosition( index ) {
|
|
|
|
await this.clickText();
|
2020-12-18 16:32:22 +00:00
|
|
|
|
|
|
|
// Second "Control" deactivates the modifier.
|
|
|
|
const keys = [ 'Control', 'Home', 'Control' ];
|
|
|
|
for ( let i = 0; i < index; i++ ) {
|
|
|
|
keys.push( 'ArrowRight' );
|
|
|
|
}
|
2023-04-03 17:14:23 +00:00
|
|
|
await browser.keys( keys );
|
2020-12-18 16:32:22 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 12:27:57 +00:00
|
|
|
get highlightedBrackets() { return $$( '.CodeMirror-line .cm-mw-matchingbracket' ); }
|
|
|
|
|
|
|
|
async getHighlightedMatchingBrackets() {
|
|
|
|
await this.highlightedBrackets[ 0 ].waitForDisplayed();
|
|
|
|
const matchingTexts = await this.highlightedBrackets.map( function ( el ) {
|
2020-12-18 16:32:22 +00:00
|
|
|
return el.getText();
|
|
|
|
} );
|
|
|
|
return matchingTexts.join( '' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new EditPage();
|