8
0
Просмотр исходного кода

Log warning instead of showing notification when feed callback throws an error.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
6384ef5688
2 измененных файлов с 21 добавлено и 31 удалено
  1. 10 10
      packages/ckeditor5-mention/src/mentionui.js
  2. 11 21
      packages/ckeditor5-mention/tests/mentionui.js

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

@@ -16,7 +16,7 @@ import featureDetection from './featuredetection';
 import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
 import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
-import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 import { debounce } from 'lodash-es';
 import { debounce } from 'lodash-es';
 
 
 import TextWatcher from './textwatcher';
 import TextWatcher from './textwatcher';
@@ -44,7 +44,7 @@ export default class MentionUI extends Plugin {
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	static get requires() {
 	static get requires() {
-		return [ ContextualBalloon, Notification ];
+		return [ ContextualBalloon ];
 	}
 	}
 
 
 	/**
 	/**
@@ -83,14 +83,14 @@ export default class MentionUI extends Plugin {
 					// So cleanup marker, remove the UI and...
 					// So cleanup marker, remove the UI and...
 					this._hideUIAndRemoveMarker();
 					this._hideUIAndRemoveMarker();
 
 
-					const notification = editor.plugins.get( Notification );
-					const t = editor.locale.t;
-
-					// ...show warning notification.
-					notification.showWarning( t( 'Could not obtain mention autocomplete feed.' ), {
-						title: t( 'Requesting feed failed' ),
-						namespace: 'mention'
-					} );
+					// ...log warning.
+					/**
+					 * The callback used for obtaining mention autocomplete feed thrown and error and the mention UI was hidden or
+					 * not displayed at all.
+					 *
+					 * @error mention-feed-callback-error
+					 */
+					log.warn( 'mention-feed-callback-error: Could not obtain mention autocomplete feed.' );
 				} )
 				} )
 				.then( feed => {
 				.then( feed => {
 					// Do nothing if :
 					// Do nothing if :

+ 11 - 21
packages/ckeditor5-mention/tests/mentionui.js

@@ -16,7 +16,7 @@ import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventd
 import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
 import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
-import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 import env from '@ckeditor/ckeditor5-utils/src/env';
 import env from '@ckeditor/ckeditor5-utils/src/env';
 
 
 import MentionUI, { createRegExp } from '../src/mentionui';
 import MentionUI, { createRegExp } from '../src/mentionui';
@@ -65,10 +65,6 @@ describe( 'MentionUI', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	it( 'should load Notification plugin', () => {
-		expect( editor.plugins.get( Notification ) ).to.instanceOf( Notification );
-	} );
-
 	describe( 'init()', () => {
 	describe( 'init()', () => {
 		it( 'should throw if marker was not provided for feed', () => {
 		it( 'should throw if marker was not provided for feed', () => {
 			return createClassicTestEditor( { feeds: [ { feed: [ 'a' ] } ] } ).catch( error => {
 			return createClassicTestEditor( { feeds: [ { feed: [ 'a' ] } ] } ).catch( error => {
@@ -1028,25 +1024,19 @@ describe( 'MentionUI', () => {
 
 
 				feedCallbackStub.throws( 'Request timeout' );
 				feedCallbackStub.throws( 'Request timeout' );
 
 
-				const notification = editor.plugins.get( Notification );
+				const spy = sinon.spy( log, 'warn' );
 
 
-				return new Promise( resolve => {
-					notification.on( 'show:warning', ( evt, data ) => {
-						// Stop the event to not block Karma tests.
-						evt.stop();
-						resolve( data );
-					}, { priority: 'high' } );
+				model.change( writer => {
+					writer.insertText( '#', doc.selection.getFirstPosition() );
+				} );
 
 
-					model.change( writer => {
-						writer.insertText( '#', doc.selection.getFirstPosition() );
-					} );
-				} ).then( data => {
-					expect( panelView.isVisible, 'panel is hidden' ).to.be.false;
-					expect( editor.model.markers.has( 'mention' ), 'there is no marker' ).to.be.false;
+				return waitForDebounce()
+					.then( () => {
+						expect( panelView.isVisible, 'panel is hidden' ).to.be.false;
+						expect( editor.model.markers.has( 'mention' ), 'there is no marker' ).to.be.false;
 
 
-					expect( data.message ).to.equal( 'Could not obtain mention autocomplete feed.' );
-					expect( data.title ).to.equal( 'Requesting feed failed' );
-				} );
+						sinon.assert.calledWithExactly( spy, 'mention-feed-callback-error: Could not obtain mention autocomplete feed.' );
+					} );
 			} );
 			} );
 
 
 			it( 'should not fail if marker was removed', () => {
 			it( 'should not fail if marker was removed', () => {