2023-10-11 05:25:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const assert = require( 'assert' ),
|
|
|
|
EditPage = require( '../pageobjects/edit.page' ),
|
|
|
|
FixtureContent = require( '../fixturecontent' ),
|
|
|
|
LoginPage = require( 'wdio-mediawiki/LoginPage' ),
|
|
|
|
UserPreferences = require( '../userpreferences' ),
|
|
|
|
Util = require( 'wdio-mediawiki/Util' );
|
|
|
|
|
|
|
|
describe( 'CodeMirror textSelection for the wikitext 2010 editor', () => {
|
|
|
|
let title;
|
|
|
|
|
|
|
|
before( async () => {
|
|
|
|
title = Util.getTestString( 'CodeMirror-fixture1-' );
|
|
|
|
await LoginPage.loginAdmin();
|
|
|
|
await FixtureContent.createFixturePage( title );
|
|
|
|
await UserPreferences.enableWikitext2010EditorWithCodeMirror();
|
|
|
|
await EditPage.openForEditing( title, true );
|
|
|
|
await EditPage.wikiEditorToolbar.waitForDisplayed();
|
|
|
|
await EditPage.clickText();
|
|
|
|
} );
|
|
|
|
|
2024-02-16 00:44:46 +00:00
|
|
|
// Content is "[]{{template}}"
|
2023-10-11 05:25:08 +00:00
|
|
|
it( 'sets and gets the correct text when using setContents and getContents', async () => {
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'setContents', 'foobar' ) );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getContents' ) ),
|
|
|
|
'foobar'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-02-16 00:44:46 +00:00
|
|
|
// Content is now "foobar"
|
2023-10-11 05:25:08 +00:00
|
|
|
it( 'sets and gets the correct selection when using setSelection and getSelection', async () => {
|
|
|
|
await browser.execute( () => {
|
|
|
|
$( '.cm-editor' ).textSelection( 'setSelection', { start: 3, end: 6 } );
|
|
|
|
} );
|
|
|
|
assert.strictEqual(
|
2024-06-14 11:51:53 +00:00
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getSelection' ) ),
|
2023-10-11 05:25:08 +00:00
|
|
|
'bar'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'correctly replaces the selected text when using replaceSelection', async () => {
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'replaceSelection', 'baz' ) );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getContents' ) ),
|
|
|
|
'foobaz'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-02-16 00:44:46 +00:00
|
|
|
// Content is now "foobaz"
|
2023-10-11 05:25:08 +00:00
|
|
|
it( 'returns the correct values for getCaretPosition', async () => {
|
|
|
|
await browser.execute( () => {
|
|
|
|
$( '.cm-editor' ).textSelection( 'setSelection', { start: 3, end: 6 } );
|
|
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getCaretPosition' ) ),
|
|
|
|
6
|
|
|
|
);
|
|
|
|
assert.deepStrictEqual(
|
2024-06-14 11:51:53 +00:00
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getCaretPosition', { startAndEnd: true } ) ),
|
2023-10-11 05:25:08 +00:00
|
|
|
[ 3, 6 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-06-14 11:51:53 +00:00
|
|
|
it( 'correctly wraps the selected text when using encapsulateSelection', async () => {
|
2024-02-16 00:44:46 +00:00
|
|
|
await browser.execute( () => {
|
|
|
|
$( '.cm-editor' ).textSelection( 'setContents', 'foobaz' )
|
|
|
|
.textSelection( 'encapsulateSelection', {
|
|
|
|
selectionStart: 0,
|
|
|
|
selectionEnd: 6,
|
|
|
|
pre: '<div>',
|
|
|
|
post: '</div>'
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getContents' ) ),
|
|
|
|
'<div>foobaz</div>'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2024-06-14 11:51:53 +00:00
|
|
|
it( "correctly inserts the 'peri' option when using encapsulateSelection", async () => {
|
2024-03-09 05:36:43 +00:00
|
|
|
await browser.execute( () => {
|
|
|
|
$( '.cm-editor' ).textSelection( 'setContents', 'foobaz' )
|
|
|
|
.textSelection( 'encapsulateSelection', {
|
|
|
|
selectionStart: 0,
|
|
|
|
selectionEnd: 6,
|
|
|
|
pre: '<div>',
|
|
|
|
post: '</div>',
|
|
|
|
peri: 'Soundgarden',
|
|
|
|
replace: true
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-editor' ).textSelection( 'getContents' ) ),
|
|
|
|
'<div>Soundgarden</div>'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2023-10-11 05:25:08 +00:00
|
|
|
it( 'scrolls to the correct place when using scrollToCaretPosition', async () => {
|
|
|
|
await browser.execute( () => {
|
|
|
|
const $cmEditor = $( '.cm-editor' );
|
|
|
|
$cmEditor.textSelection( 'setContents', 'foobar\n'.repeat( 50 ) );
|
|
|
|
// Ensure caret is at the top.
|
|
|
|
$cmEditor.textSelection( 'setSelection', { start: 0 } );
|
|
|
|
// Force scrolling to the bottom.
|
|
|
|
$( '.cm-scroller' )[ 0 ].scrollTop = 5000;
|
|
|
|
// Use textSelection to scroll back to caret.
|
|
|
|
$cmEditor.textSelection( 'scrollToCaretPosition' );
|
|
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
|
|
await browser.execute( () => $( '.cm-scroller' ).scrollTop() ),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
} );
|
2023-10-18 00:34:33 +00:00
|
|
|
|
2024-02-16 00:44:46 +00:00
|
|
|
// Content is now "foobar\n" repeated 50 times.
|
2023-10-18 00:34:33 +00:00
|
|
|
it( 'retains the contents after turning CodeMirror off', async () => {
|
|
|
|
await EditPage.legacyCodeMirrorButton.click();
|
|
|
|
await EditPage.legacyTextInput.waitForDisplayed();
|
|
|
|
assert.match( await EditPage.legacyTextInput.getValue(), /foobar/ );
|
|
|
|
} );
|
2023-10-11 05:25:08 +00:00
|
|
|
} );
|