|
|
@@ -3,7 +3,7 @@
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
|
*/
|
|
|
|
|
|
-/* global document, setTimeout, Event */
|
|
|
+/* global window, document, setTimeout, Event */
|
|
|
|
|
|
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
@@ -18,7 +18,7 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
|
|
|
import env from '@ckeditor/ckeditor5-utils/src/env';
|
|
|
|
|
|
-import MentionUI from '../src/mentionui';
|
|
|
+import MentionUI, { createRegExp } from '../src/mentionui';
|
|
|
import featureDetection from '../src/featuredetection';
|
|
|
import MentionEditing from '../src/mentionediting';
|
|
|
import MentionsView from '../src/ui/mentionsview';
|
|
|
@@ -444,38 +444,40 @@ describe( 'MentionUI', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'ES2018 RegExp Unicode property escapes fallback', () => {
|
|
|
- // Cache the original RegExp to restore it after the tests.
|
|
|
- const originalPunctationSupport = featureDetection.isPunctuationGroupSupported;
|
|
|
+ let regExpStub;
|
|
|
+
|
|
|
+ // Cache the original value to restore it after the tests.
|
|
|
+ const originalPunctuationSupport = featureDetection.isPunctuationGroupSupported;
|
|
|
|
|
|
before( () => {
|
|
|
featureDetection.isPunctuationGroupSupported = false;
|
|
|
} );
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- return createClassicTestEditor( staticConfig );
|
|
|
+ return createClassicTestEditor( staticConfig )
|
|
|
+ .then( editor => {
|
|
|
+ regExpStub = sinon.stub( window, 'RegExp' );
|
|
|
+
|
|
|
+ return editor;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
after( () => {
|
|
|
- // Restore the original RegExp.
|
|
|
- featureDetection.isPunctuationGroupSupported = originalPunctationSupport;
|
|
|
+ featureDetection.isPunctuationGroupSupported = originalPunctuationSupport;
|
|
|
} );
|
|
|
|
|
|
- it( 'should fallback to simpler RegExp if browser does not support unicode property escapes', () => {
|
|
|
- setData( model, '<paragraph>[] foo</paragraph>' );
|
|
|
-
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '〈', doc.selection.getFirstPosition() );
|
|
|
- } );
|
|
|
-
|
|
|
- model.change( writer => {
|
|
|
- writer.insertText( '@', doc.selection.getFirstPosition() );
|
|
|
- } );
|
|
|
+ it( 'returns a simplified RegExp for browsers not supporting Unicode punctuation groups', () => {
|
|
|
+ featureDetection.isPunctuationGroupSupported = false;
|
|
|
+ createRegExp( '@', 2 );
|
|
|
+ sinon.assert.calledOnce( regExpStub );
|
|
|
+ sinon.assert.calledWithExactly( regExpStub, '(^|[ \\(\\[{"\'])([@])([_a-zA-Z0-9À-ž]{2,}?)$', 'u' );
|
|
|
+ } );
|
|
|
|
|
|
- return waitForDebounce()
|
|
|
- .then( () => {
|
|
|
- expect( panelView.isVisible ).to.be.false;
|
|
|
- expect( editor.model.markers.has( 'mention' ) ).to.be.false;
|
|
|
- } );
|
|
|
+ it( 'returns a ES2018 RegExp for browsers supporting Unicode punctuation groups', () => {
|
|
|
+ featureDetection.isPunctuationGroupSupported = true;
|
|
|
+ createRegExp( '@', 2 );
|
|
|
+ sinon.assert.calledOnce( regExpStub );
|
|
|
+ sinon.assert.calledWithExactly( regExpStub, '(^|[ \\p{Ps}\\p{Pi}"\'])([@])([_a-zA-Z0-9À-ž]{2,}?)$', 'u' );
|
|
|
} );
|
|
|
} );
|
|
|
|