Debian Codegraph @

tests/selenium/pageobjects/edit.page.js

raw
1 'use strict';
2
3 const Page = require( 'wdio-mediawiki/Page' );
4
5 // Copied from mediawiki-core edit.page.js
6 class EditPage extends Page {
7 async openForEditing( title, cm6enable = false ) {
8 const queryParams = {
9 action: 'edit',
10 vehidebetadialog: 1,
11 hidewelcomedialog: 1
12 };
13 if ( cm6enable ) {
14 queryParams.cm6enable = '1';
15 }
16 await super.openTitle( title, queryParams );
17 }
18
19 get wikiEditorToolbar() {
20 return $( '#wikiEditor-ui-toolbar' );
21 }
22
23 get legacyTextInput() {
24 return $( '#wpTextbox1' );
25 }
26
27 get legacyCodeMirrorButton() {
28 return $( '#mw-editbutton-codemirror' );
29 }
30
31 async clickText() {
32 if ( await this.visualEditorSave.isDisplayed() ) {
33 await this.visualEditorSurface.click();
34 } else if ( await this.legacyTextInput.isDisplayed() ) {
35 await this.legacyTextInput.click();
36 } else {
37 // Click the container, if using WikiEditor etc.
38 await this.legacyTextInput.parentElement().click();
39 }
40 }
41
42 get visualEditorSave() {
43 return $( '.ve-ui-toolbar-saveButton' );
44 }
45
46 get visualEditorSurface() {
47 return $( '.ve-ui-surface-source' );
48 }
49
50 get codeMirrorTemplateFoldingButton() {
51 return $( '.cm-tooltip-fold' );
52 }
53
54 get codeMirrorTemplateFoldingPlaceholder() {
55 return $( '.cm-foldPlaceholder' );
56 }
57
58 async cursorToPosition( index ) {
59 await this.clickText();
60
61 // Second "Control" deactivates the modifier.
62 const keys = [ 'Control', 'Home', 'Control' ];
63 for ( let i = 0; i < index; i++ ) {
64 keys.push( 'ArrowRight' );
65 }
66 await browser.keys( keys );
67 }
68
69 get highlightedBrackets() {
70 return $$( '.CodeMirror-line .cm-mw-matchingbracket' );
71 }
72
73 async getHighlightedMatchingBrackets() {
74 await this.highlightedBrackets[ 0 ].waitForDisplayed();
75 const matchingTexts = await this.highlightedBrackets.map( ( el ) => el.getText() );
76 return matchingTexts.join( '' );
77 }
78 }
79
80 module.exports = new EditPage();