-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathfullscreencommand.js
More file actions
123 lines (92 loc) · 3.8 KB
/
fullscreencommand.js
File metadata and controls
123 lines (92 loc) · 3.8 KB
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
/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
import { Essentials } from '@ckeditor/ckeditor5-essentials/src/essentials.js';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import { global } from '@ckeditor/ckeditor5-utils/src/dom/global.js';
import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { DecoupledEditor } from '@ckeditor/ckeditor5-editor-decoupled';
import { InlineEditor } from '@ckeditor/ckeditor5-editor-inline';
import { BalloonEditor } from '@ckeditor/ckeditor5-editor-balloon';
import { MultiRootEditor } from '@ckeditor/ckeditor5-editor-multi-root';
import { removeEditorBodyOrphans } from '@ckeditor/ckeditor5-core/tests/_utils/cleanup.js';
import { FullscreenCommand } from '../src/fullscreencommand.js';
import { FullscreenClassicEditorHandler } from '../src/handlers/classiceditorhandler.js';
import { FullscreenDecoupledEditorHandler } from '../src/handlers/decouplededitorhandler.js';
import { FullscreenAbstractEditorHandler } from '../src/handlers/abstracteditorhandler.js';
const basicConfig = {
plugins: [
Paragraph,
Essentials
]
};
describe( 'FullscreenCommand', () => {
let domElement, editor, command;
beforeEach( async () => {
domElement = global.document.createElement( 'div' );
global.document.body.appendChild( domElement );
editor = await ClassicEditor.create( domElement, basicConfig );
command = new FullscreenCommand( editor );
} );
afterEach( () => {
domElement.remove();
return editor.destroy();
} );
it( '#value should be initially set to `false`', () => {
expect( command.value ).to.equal( false );
} );
it( 'should not affect data', () => {
expect( command.affectsData ).to.equal( false );
} );
it( 'should be enabled by default', () => {
expect( command.isEnabled ).to.equal( true );
} );
describe( 'should set proper #fullscreenHandler for each editor type', () => {
let tempElement;
beforeEach( async () => {
tempElement = global.document.createElement( 'div' );
global.document.body.appendChild( tempElement );
} );
afterEach( () => {
tempElement.remove();
removeEditorBodyOrphans();
} );
it( 'for Classic editor', async () => {
testEditorTypeHandler( tempElement, ClassicEditor, FullscreenClassicEditorHandler );
} );
it( 'for Decoupled editor', async () => {
testEditorTypeHandler( tempElement, DecoupledEditor, FullscreenDecoupledEditorHandler );
} );
it( 'for Inline editor', async () => {
testEditorTypeHandler( tempElement, InlineEditor, FullscreenAbstractEditorHandler );
} );
it( 'for Balloon editor', async () => {
testEditorTypeHandler( tempElement, BalloonEditor, FullscreenAbstractEditorHandler );
} );
it( 'for Multiroot editor', async () => {
testEditorTypeHandler( tempElement, MultiRootEditor, FullscreenAbstractEditorHandler );
} );
async function testEditorTypeHandler( element, editorConstructor, editorHandler ) {
const tempEditor = await editorConstructor.create( element, basicConfig );
const tempCommand = new FullscreenCommand( tempEditor );
expect( tempCommand.fullscreenHandler ).to.be.instanceOf( editorHandler );
return tempEditor.destroy();
}
} );
describe( '#execute()', () => {
it( 'should call #_disableFullscreenMode() if #value is `true`', () => {
const spy = sinon.spy( command, '_disableFullscreenMode' );
command.value = true;
command.execute();
expect( spy.calledOnce ).to.equal( true );
} );
it( 'should call #_enableFullscreenMode() if #value is `false`', () => {
const spy = sinon.spy( command, '_enableFullscreenMode' );
command.value = false;
command.execute();
expect( spy.calledOnce ).to.equal( true );
command.execute();
} );
} );
} );