This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
/
integration.js
101 lines (79 loc) · 3.59 KB
/
integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import BalloonToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/balloon/balloontoolbar';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
import Table from '../src/table';
import TableToolbar from '../src/tabletoolbar';
import View from '@ckeditor/ckeditor5-ui/src/view';
describe( 'TableToolbar integration', () => {
describe( 'with the BalloonToolbar', () => {
let balloon, balloonToolbar, newEditor, editorElement;
beforeEach( () => {
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );
return ClassicTestEditor
.create( editorElement, {
plugins: [ Table, TableToolbar, BalloonToolbar, Paragraph ]
} )
.then( editor => {
newEditor = editor;
balloon = newEditor.plugins.get( 'ContextualBalloon' );
balloonToolbar = newEditor.plugins.get( 'BalloonToolbar' );
const button = new View();
button.element = global.document.createElement( 'div' );
// There must be at least one toolbar items which is not disabled to show it.
// https://github.com/ckeditor/ckeditor5-ui/issues/269
balloonToolbar.toolbarView.items.add( button );
newEditor.editing.view.isFocused = true;
newEditor.editing.view.getDomRoot().focus();
} );
} );
afterEach( () => {
editorElement.remove();
return newEditor.destroy();
} );
it( 'should allow the BalloonToolbar to be displayed when a table is selected with surrounding text', () => {
setModelData( newEditor.model, '<paragraph>fo[o</paragraph><table><tableRow><tableCell></tableCell></tableRow></table>]' );
balloonToolbar.show();
expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
} );
it( 'should allow the BalloonToolbar to be displayed when a table content is selected', () => {
setModelData(
newEditor.model,
'<paragraph>foo</paragraph><table><tableRow><tableCell><paragraph>x[y]z</paragraph></tableCell></tableRow></table>'
);
balloonToolbar.show();
expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
} );
it( 'should prevent the BalloonToolbar from being displayed when a table is selected as whole', () => {
setModelData(
newEditor.model,
'<paragraph>foo</paragraph>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]'
);
balloonToolbar.show();
expect( balloon.visibleView ).to.be.null;
} );
it( 'should listen to BalloonToolbar#show event with the high priority', () => {
const highestPrioritySpy = sinon.spy();
const highPrioritySpy = sinon.spy();
const normalPrioritySpy = sinon.spy();
// Select an table
setModelData(
newEditor.model,
'<paragraph>foo</paragraph>[<table><tableRow><tableCell><paragraph>x</paragraph></tableCell></tableRow></table>]'
);
newEditor.listenTo( balloonToolbar, 'show', highestPrioritySpy, { priority: 'highest' } );
newEditor.listenTo( balloonToolbar, 'show', highPrioritySpy, { priority: 'high' } );
newEditor.listenTo( balloonToolbar, 'show', normalPrioritySpy, { priority: 'normal' } );
balloonToolbar.show();
sinon.assert.calledOnce( highestPrioritySpy );
sinon.assert.notCalled( highPrioritySpy );
sinon.assert.notCalled( normalPrioritySpy );
} );
} );
} );