Ver código fonte

Update tests for env.isEdge check.

Maciej Gołaszewski 6 anos atrás
pai
commit
03eec2c244

+ 1 - 1
packages/ckeditor5-mention/src/mentionui.js

@@ -531,7 +531,7 @@ function createRegExp( marker, minimumCharacters ) {
 			// Uses the ES2018 syntax. See ckeditor5-mention#44.
 			// Uses the ES2018 syntax. See ckeditor5-mention#44.
 			return new RegExp( buildPattern( '\\p{Ps}"\'', marker, numberOfCharacters ), 'u' );
 			return new RegExp( buildPattern( '\\p{Ps}"\'', marker, numberOfCharacters ), 'u' );
 		} catch ( error ) {
 		} catch ( error ) {
-			// It's OK we're return later.
+			// It's OK we're fallback to non ES2018 RegExp later.
 		}
 		}
 	}
 	}
 
 

+ 49 - 1
packages/ckeditor5-mention/tests/mentionui.js

@@ -435,7 +435,7 @@ describe( 'MentionUI', () => {
 			} );
 			} );
 		} );
 		} );
 
 
-		describe( 'ES2018 RegExp Unicode property escapes fallback', function() {
+		describe( 'ES2018 RegExp Unicode property escapes fallback', () => {
 			// Cache the original RegExp to restore it after the tests.
 			// Cache the original RegExp to restore it after the tests.
 			const RegExp = window.RegExp;
 			const RegExp = window.RegExp;
 
 
@@ -477,6 +477,54 @@ describe( 'MentionUI', () => {
 						expect( editor.model.markers.has( 'mention' ) ).to.be.false;
 						expect( editor.model.markers.has( 'mention' ) ).to.be.false;
 					} );
 					} );
 			} );
 			} );
+
+			it( 'should fallback to old method if browser does not support unicode property escapes (on Edge)', () => {
+				// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
+				testUtils.sinon.stub( env, 'isEdge' ).get( () => true );
+
+				setData( model, '<paragraph>[] foo</paragraph>' );
+
+				model.change( writer => {
+					writer.insertText( '〈', doc.selection.getFirstPosition() );
+				} );
+
+				model.change( writer => {
+					writer.insertText( '@', doc.selection.getFirstPosition() );
+				} );
+
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible ).to.be.false;
+						expect( editor.model.markers.has( 'mention' ) ).to.be.false;
+					} );
+			} );
+		} );
+
+		describe( 'ES2018 RegExp Unicode property escapes fallback on Edge', () => {
+			beforeEach( () => {
+				// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
+				testUtils.sinon.stub( env, 'isEdge' ).get( () => true );
+
+				return createClassicTestEditor( staticConfig );
+			} );
+
+			it( 'should fallback to old method if browser does not support unicode property escapes (on Edge)', () => {
+				setData( model, '<paragraph>[] foo</paragraph>' );
+
+				model.change( writer => {
+					writer.insertText( '〈', doc.selection.getFirstPosition() );
+				} );
+
+				model.change( writer => {
+					writer.insertText( '@', doc.selection.getFirstPosition() );
+				} );
+
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible ).to.be.false;
+						expect( editor.model.markers.has( 'mention' ) ).to.be.false;
+					} );
+			} );
 		} );
 		} );
 
 
 		describe( 'static list with default trigger', () => {
 		describe( 'static list with default trigger', () => {