This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
/
decouplededitoruiview.js
142 lines (110 loc) · 4.13 KB
/
decouplededitoruiview.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/* globals document */
import DecoupledEditorUIView from '../src/decouplededitoruiview';
import EditingView from '@ckeditor/ckeditor5-engine/src/view/view';
import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
import Locale from '@ckeditor/ckeditor5-utils/src/locale';
import createRoot from '@ckeditor/ckeditor5-engine/tests/view/_utils/createroot.js';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'DecoupledEditorUIView', () => {
let locale, view, editingView, editingViewRoot;
testUtils.createSinonSandbox();
beforeEach( () => {
locale = new Locale();
editingView = new EditingView();
editingViewRoot = createRoot( editingView.document );
view = new DecoupledEditorUIView( locale, editingView );
view.editable.name = editingViewRoot.rootName;
} );
describe( 'constructor()', () => {
it( 'is virtual', () => {
expect( view.template ).to.be.undefined;
expect( view.element ).to.be.null;
} );
describe( '#toolbar', () => {
it( 'is created', () => {
expect( view.toolbar ).to.be.instanceof( ToolbarView );
} );
it( 'is given a locale object', () => {
expect( view.toolbar.locale ).to.equal( locale );
} );
it( 'is not rendered', () => {
expect( view.toolbar.isRendered ).to.be.false;
} );
it( 'has automatic items grouping enabled', () => {
expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;
} );
} );
describe( '#editable', () => {
it( 'is created', () => {
expect( view.editable ).to.be.instanceof( InlineEditableUIView );
} );
it( 'is given a locale object', () => {
expect( view.editable.locale ).to.equal( locale );
} );
it( 'is not rendered', () => {
expect( view.editable.isRendered ).to.be.false;
} );
it( 'can be created out of an existing DOM element', () => {
const editableElement = document.createElement( 'div' );
const testView = new DecoupledEditorUIView( locale, editingView, editableElement );
testView.editable.name = editingViewRoot.rootName;
testView.render();
expect( testView.editable.element ).to.equal( editableElement );
testView.destroy();
} );
} );
} );
describe( 'render()', () => {
beforeEach( () => {
view.render();
} );
afterEach( () => {
view.destroy();
} );
describe( '#toolbar', () => {
it( 'is rendered but gets no parent', () => {
expect( view.isRendered ).to.be.true;
expect( view.toolbar.element.parentElement ).to.be.null;
} );
it( 'gets the CSS classes', () => {
expect( view.toolbar.element.classList.contains( 'ck-reset_all' ) ).to.be.true;
expect( view.toolbar.element.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
} );
it( 'gets the "dir" attribute corresponding to Locale#uiLanguageDirection', () => {
expect( view.toolbar.element.getAttribute( 'dir' ) ).to.equal( 'ltr' );
} );
} );
describe( '#editable', () => {
it( 'is rendered but gets no parent', () => {
expect( view.isRendered ).to.be.true;
expect( view.editable.element.parentElement ).to.be.null;
} );
} );
} );
describe( 'destroy', () => {
beforeEach( () => {
view.render();
} );
it( 'destroys #toolbar and #editable', () => {
const toolbarSpy = sinon.spy( view.toolbar, 'destroy' );
const editableSpy = sinon.spy( view.editable, 'destroy' );
view.destroy();
sinon.assert.calledOnce( toolbarSpy );
sinon.assert.calledOnce( editableSpy );
} );
it( 'does not touch the toolbar#element and editable#element by default', () => {
document.body.appendChild( view.toolbar.element );
document.body.appendChild( view.editable.element );
view.destroy();
expect( view.toolbar.element.parentElement ).to.equal( document.body );
expect( view.editable.element.parentElement ).to.equal( document.body );
view.toolbar.element.remove();
view.editable.element.remove();
} );
} );
} );