2024-03-11 21:34:36 +00:00
|
|
|
import CodeMirror from '../../src/codemirror.js';
|
2024-03-14 18:32:14 +00:00
|
|
|
import mediaWikiLang from '../../src/codemirror.mode.mediawiki.js';
|
2024-03-11 21:34:36 +00:00
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
title: 'wraps HTML tags with span.cm-bidi-isolate',
|
|
|
|
input: 'שלום<span class="foobar">שלום</span>שלום',
|
|
|
|
output: '<div class="cm-line">שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"><</span><span class="cm-mw-htmltag-name">span </span><span class="cm-mw-htmltag-attribute">class="foobar"</span><span class="cm-mw-htmltag-bracket">></span></span>שלום<span class="cm-bidi-isolate"><span class="cm-mw-htmltag-bracket"></</span><span class="cm-mw-htmltag-name">span</span><span class="cm-mw-htmltag-bracket">></span></span>שלום</div>'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Setup CodeMirror instance.
|
|
|
|
const textarea = document.createElement( 'textarea' );
|
|
|
|
textarea.dir = 'rtl';
|
|
|
|
document.body.appendChild( textarea );
|
|
|
|
const cm = new CodeMirror( textarea );
|
2024-03-14 18:32:14 +00:00
|
|
|
const mwLang = mediaWikiLang(
|
|
|
|
{ bidiIsolation: true },
|
|
|
|
{ tags: {} }
|
|
|
|
);
|
2024-03-11 21:34:36 +00:00
|
|
|
cm.initialize( [ ...cm.defaultExtensions, mwLang ] );
|
|
|
|
|
|
|
|
describe( 'CodeMirrorBidiIsolation', () => {
|
|
|
|
it.each( testCases )(
|
|
|
|
'bidi isolation ($title)',
|
|
|
|
( { input, output } ) => {
|
|
|
|
cm.view.dispatch( {
|
|
|
|
changes: {
|
|
|
|
from: 0,
|
|
|
|
to: cm.view.state.doc.length,
|
|
|
|
insert: input
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
cm.$textarea.textSelection = jest.fn().mockReturnValue( input );
|
|
|
|
expect( cm.view.dom.querySelector( '.cm-content' ).innerHTML ).toStrictEqual( output );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|