1
+ 'use strict' ;
2
+
1
3
var expect = chai . expect ;
2
4
_ . str = s ; // clearer exposition of underscore.string
3
5
4
6
describe ( 'CKEditor directive' , function ( ) {
5
- var $compile , $document , $rootScope , scope ;
7
+ var $compile , $document , $rootScope , scope , createElement , element ;
6
8
7
9
beforeEach ( module ( 'ckeditor' ) ) ;
8
10
@@ -11,6 +13,12 @@ describe('CKEditor directive', function () {
11
13
$rootScope = $injector . get ( '$rootScope' ) ;
12
14
$document = $injector . get ( '$document' ) ;
13
15
scope = $rootScope . $new ( ) ;
16
+
17
+ createElement = function ( ) {
18
+ element = $compile (
19
+ '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
20
+ ) ( scope ) ;
21
+ } ;
14
22
} ) ) ;
15
23
16
24
afterEach ( function cleanup ( done ) {
@@ -30,31 +38,23 @@ describe('CKEditor directive', function () {
30
38
done ( ) ;
31
39
} ;
32
40
33
- var element = $compile (
34
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
35
- ) ( scope ) ;
41
+ createElement ( ) ;
36
42
} ) ;
37
43
38
44
it ( 'should put editor out of readonly mode when ready' , function ( done ) {
39
45
scope . onReady = function ( ) {
40
46
expect ( _ . find ( CKEDITOR . instances ) . readOnly ) . to . be . false ;
41
47
done ( ) ;
42
48
} ;
43
-
44
- var element = $compile (
45
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
46
- ) ( scope ) ;
49
+ createElement ( ) ;
47
50
} ) ;
48
51
49
52
it ( 'should destroy instance on scope destroy' , function ( done ) {
50
53
scope . onReady = function ( ) {
51
54
done ( ) ;
52
55
} ;
53
56
54
- var element = $compile (
55
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
56
- ) ( scope ) ;
57
-
57
+ createElement ( ) ;
58
58
// this is tested in the afterEach "cleanup" above
59
59
} ) ;
60
60
} ) ;
@@ -63,9 +63,7 @@ describe('CKEditor directive', function () {
63
63
scope . content = 'Hello' ;
64
64
scope . onReady = done ;
65
65
66
- var element = $compile (
67
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
68
- ) ( scope ) ;
66
+ createElement ( ) ;
69
67
} ) ;
70
68
71
69
describe ( 'model sync' , function ( ) {
@@ -84,9 +82,7 @@ describe('CKEditor directive', function () {
84
82
} , 0 ) ;
85
83
} ;
86
84
87
- var element = $compile (
88
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
89
- ) ( scope ) ;
85
+ createElement ( ) ;
90
86
} ) ;
91
87
92
88
it ( 'should synchronize editor to the view' , function ( done ) {
@@ -101,9 +97,7 @@ describe('CKEditor directive', function () {
101
97
} , 5 ) ;
102
98
} ;
103
99
104
- var element = $compile (
105
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
106
- ) ( scope ) ;
100
+ createElement ( ) ;
107
101
} ) ;
108
102
109
103
it ( 'should synchronize editor to the view at start' , function ( done ) {
@@ -117,9 +111,19 @@ describe('CKEditor directive', function () {
117
111
} ;
118
112
119
113
scope . content = 'at start !' ;
120
- var element = $compile (
121
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
122
- ) ( scope ) ;
114
+ createElement ( ) ;
115
+ } ) ;
116
+
117
+ it ( 'should contain only one snapshot at start' , function ( done ) {
118
+ scope . onReady = function ( ) {
119
+ setTimeout ( function ( ) {
120
+ expect ( _ . find ( CKEDITOR . instances ) . undoManager . snapshots . length ) . to . equal ( 1 ) ;
121
+ done ( ) ;
122
+ } , 5 ) ;
123
+ } ;
124
+
125
+ scope . content = 'at start !' ;
126
+ createElement ( ) ;
123
127
} ) ;
124
128
125
129
it ( 'should update model in a watchable way' , function ( done ) {
@@ -134,10 +138,7 @@ describe('CKEditor directive', function () {
134
138
_ . find ( CKEDITOR . instances ) . setData ( '<p>Hey</p>' ) ;
135
139
} ;
136
140
137
- var element =
138
- $compile (
139
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
140
- ) ( scope ) ;
141
+ createElement ( ) ;
141
142
} ) ;
142
143
} ) ;
143
144
@@ -150,9 +151,7 @@ describe('CKEditor directive', function () {
150
151
done ( ) ;
151
152
} ;
152
153
153
- var element = $compile (
154
- '<div contenteditable="true" ckeditor ng-model="content" ready="onReady()"></div>'
155
- ) ( scope ) ;
154
+ createElement ( ) ;
156
155
} ) ;
157
156
} ) ;
158
157
0 commit comments