Debian Codegraph @

tests/selenium/specs/templateFolding-wikitext2010.js

raw
1 'use strict';
2
3 const assert = require( 'assert' ),
4 EditPage = require( '../pageobjects/edit.page' ),
5 FixtureContent = require( '../fixturecontent' ),
6 LoginPage = require( 'wdio-mediawiki/LoginPage' ),
7 UserPreferences = require( '../userpreferences' ),
8 Util = require( 'wdio-mediawiki/Util' );
9
10 describe( 'CodeMirror template folding for the wikitext 2010 editor', () => {
11 let title, parserFunctionNode;
12
13 before( async () => {
14 title = Util.getTestString( 'CodeMirror-fixture1-' );
15 await LoginPage.loginAdmin();
16 await FixtureContent.createFixturePage( title );
17 await UserPreferences.enableWikitext2010EditorWithCodeMirror();
18 await EditPage.openForEditing( title, true );
19 await EditPage.wikiEditorToolbar.waitForDisplayed();
20 await browser.execute( () => {
21 $( '.cm-editor' ).textSelection( 'setContents', '{{foo|1={{bar|{{baz|{{PAGENAME}}}}}}}}' );
22 } );
23 parserFunctionNode = $( '.cm-mw-parserfunction-name' );
24 } );
25
26 it( 'folds the template parameters via the button', async () => {
27 // First make sure the parser function node is visible.
28 assert( await parserFunctionNode.waitForDisplayed() );
29 // Insert the cursor.
30 await browser.execute( () => {
31 // Just after the '{{' in '{{PAGENAME}}'
32 $( '.cm-editor' ).textSelection( 'setSelection', { start: 22, end: 22 } );
33 } );
34 await EditPage.codeMirrorTemplateFoldingButton.waitForDisplayed();
35 // Fold the template, which should hide the parser function node.
36 await EditPage.codeMirrorTemplateFoldingButton.click();
37 // The parser function node should be hidden, while the placeholder should be visible.
38 assert( await parserFunctionNode.waitForDisplayed( { reverse: true } ) );
39 assert( await EditPage.codeMirrorTemplateFoldingPlaceholder.isDisplayedInViewport() );
40 } );
41
42 it( 'expands the template parameters via the button', async () => {
43 // Parser function node should be hidden.
44 assert( await parserFunctionNode.waitForDisplayed( { reverse: true } ) );
45 // Expand the template.
46 await EditPage.codeMirrorTemplateFoldingPlaceholder.click();
47 // Parser function node should be visible, while the placeholder should be hidden.
48 assert( await parserFunctionNode.waitForDisplayed() );
49 assert(
50 await EditPage.codeMirrorTemplateFoldingPlaceholder
51 .waitForDisplayed( { reverse: true } )
52 );
53 } );
54 } );