Przeglądaj źródła

Extract MentionsView.

Maciej Gołaszewski 6 lat temu
rodzic
commit
8998675954

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

@@ -10,13 +10,12 @@
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
-import View from '@ckeditor/ckeditor5-ui/src/view';
-import ListView from '@ckeditor/ckeditor5-ui/src/list/listview';
 import ListItemView from '@ckeditor/ckeditor5-ui/src/list/listitemview';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
 import Rect from '@ckeditor/ckeditor5-utils/src/dom/rect';
+import MentionsView from './ui/mentionsview';
 
 /**
  * The mention ui feature.
@@ -251,31 +250,6 @@ class TextWatcher {
 
 mix( TextWatcher, EmitterMixin );
 
-class MentionsView extends View {
-	constructor( locale ) {
-		super( locale );
-
-		this.listView = new ListView( locale );
-
-		this.setTemplate( {
-			tag: 'div',
-
-			attributes: {
-				class: [
-					'ck',
-					'ck-mention'
-				],
-
-				tabindex: '-1'
-			},
-
-			children: [
-				this.listView
-			]
-		} );
-	}
-}
-
 function getBalloonPositions() {
 	const defaultPositions = BalloonPanelView.defaultPositions;
 

+ 41 - 0
packages/ckeditor5-mention/src/ui/mentionsview.js

@@ -0,0 +1,41 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module mention/ui/mentionsview
+ */
+
+import View from '@ckeditor/ckeditor5-ui/src/view';
+import ListView from '@ckeditor/ckeditor5-ui/src/list/listview';
+
+/**
+ * The mention ui view.
+ *
+ * @extends module:ui/view~View
+ */
+export default class MentionsView extends View {
+	constructor( locale ) {
+		super( locale );
+
+		this.listView = new ListView( locale );
+
+		this.setTemplate( {
+			tag: 'div',
+
+			attributes: {
+				class: [
+					'ck',
+					'ck-mention'
+				],
+
+				tabindex: '-1'
+			},
+
+			children: [
+				this.listView
+			]
+		} );
+	}
+}

+ 14 - 0
packages/ckeditor5-mention/tests/mentionui.js

@@ -8,11 +8,13 @@
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpanelview';
 
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 import MentionUI from '../src/mentionui';
 import MentionEditing from '../src/mentionediting';
+import MentionsView from '../src/ui/mentionsview';
 
 describe( 'BalloonToolbar', () => {
 	let editor, editingView, mentionUI, editorElement;
@@ -63,9 +65,21 @@ describe( 'BalloonToolbar', () => {
 
 	describe( 'child views', () => {
 		describe( 'panelView', () => {
+			it( 'should create a view instance', () => {
+				expect( mentionUI.panelView ).to.instanceof( BalloonPanelView );
+			} );
+
 			it( 'should be added to the ui.view.body collection', () => {
 				expect( Array.from( editor.ui.view.body ) ).to.include( mentionUI.panelView );
 			} );
+
+			it( 'should have disabled arrow', () => {
+				expect( mentionUI.panelView.withArrow ).to.be.false;
+			} );
+
+			it( 'should have added MentionView as a child', () => {
+				expect( mentionUI.panelView.content.get( 0 ) ).to.be.instanceof( MentionsView );
+			} );
 		} );
 	} );
 } );