mediawiki-extensions-CodeMi.../tests/selenium/pageobjects/edit.page.js
MusikAnimal 361741ec86 CodeMirrorWikiEditor: sync with textarea when using CodeMirror toggle
This was working before somehow… but according to the CodeMirror docs,
it never syncs with the textarea automatically, so regardless this is
a necessary safeguard at least.

Repro steps:
1) Have CodeMirror turned on
2) Open a page for editing
3) Add content
4) Toggle CodeMirror off

With this patch, it should now always be synced.

Also add selenium test to ensure this doesn't break again.

Bug: T317243
Change-Id: Ie44e62fe5838bf32f40c6a3595ec3f541380cfe1
2023-10-21 00:42:22 +00:00

59 lines
1.7 KiB
JavaScript

'use strict';
const Page = require( 'wdio-mediawiki/Page' );
// Copied from mediawiki-core edit.page.js
class EditPage extends Page {
async openForEditing( title, cm6enable = false ) {
const queryParams = {
action: 'edit',
vehidebetadialog: 1,
hidewelcomedialog: 1
};
if ( cm6enable ) {
queryParams.cm6enable = '1';
}
await super.openTitle( title, queryParams );
}
get wikiEditorToolbar() { return $( '#wikiEditor-ui-toolbar' ); }
get legacyTextInput() { return $( '#wpTextbox1' ); }
get legacyCodeMirrorButton() { return $( '#mw-editbutton-codemirror' ); }
async clickText() {
if ( await this.visualEditorSave.isDisplayed() ) {
await this.visualEditorSurface.click();
} else if ( await this.legacyTextInput.isDisplayed() ) {
await this.legacyTextInput.click();
} else {
// Click the container, if using WikiEditor etc.
await this.legacyTextInput.parentElement().click();
}
}
get visualEditorSave() { return $( '.ve-ui-toolbar-saveButton' ); }
get visualEditorSurface() { return $( '.ve-ui-surface-source' ); }
async cursorToPosition( index ) {
await this.clickText();
// Second "Control" deactivates the modifier.
const keys = [ 'Control', 'Home', 'Control' ];
for ( let i = 0; i < index; i++ ) {
keys.push( 'ArrowRight' );
}
await browser.keys( keys );
}
get highlightedBrackets() { return $$( '.CodeMirror-line .cm-mw-matchingbracket' ); }
async getHighlightedMatchingBrackets() {
await this.highlightedBrackets[ 0 ].waitForDisplayed();
const matchingTexts = await this.highlightedBrackets.map( function ( el ) {
return el.getText();
} );
return matchingTexts.join( '' );
}
}
module.exports = new EditPage();