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 {
|
|
|
|
openForEditing( title ) {
|
|
|
|
super.openTitle( title, { action: 'edit', vehidebetadialog: 1, hidewelcomedialog: 1 } );
|
|
|
|
}
|
|
|
|
|
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' ); }
|
|
|
|
clickText() {
|
2021-01-08 11:14:55 +00:00
|
|
|
if ( this.visualEditorSave.isDisplayed() ) {
|
|
|
|
this.visualEditorSurface.click();
|
|
|
|
} else if ( this.legacyTextInput.isDisplayed() ) {
|
2020-12-18 16:32:22 +00:00
|
|
|
this.legacyTextInput.click();
|
|
|
|
} else {
|
|
|
|
// Click the container, if using WikiEditor etc.
|
|
|
|
this.legacyTextInput.parentElement().click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 11:14:55 +00:00
|
|
|
get visualEditorSave() { return $( '.ve-ui-toolbar-saveButton' ); }
|
|
|
|
get visualEditorToggle() { return $( '.ve-init-mw-editSwitch' ); }
|
|
|
|
get visualEditorSurface() { return $( '.ve-ui-surface-source' ); }
|
|
|
|
|
2020-12-18 16:32:22 +00:00
|
|
|
cursorToPosition( index ) {
|
|
|
|
this.clickText();
|
|
|
|
|
|
|
|
// Second "Control" deactivates the modifier.
|
|
|
|
const keys = [ 'Control', 'Home', 'Control' ];
|
|
|
|
for ( let i = 0; i < index; i++ ) {
|
|
|
|
keys.push( 'ArrowRight' );
|
|
|
|
}
|
|
|
|
browser.keys( keys );
|
|
|
|
}
|
|
|
|
|
|
|
|
getHighlightedMatchingBrackets() {
|
2021-03-04 13:55:25 +00:00
|
|
|
const elements = $$( '.CodeMirror-line .cm-mw-matchingbracket' );
|
2020-12-18 16:32:22 +00:00
|
|
|
const matchingTexts = elements.map( function ( el ) {
|
|
|
|
return el.getText();
|
|
|
|
} );
|
|
|
|
return matchingTexts.join( '' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new EditPage();
|