directiveSpec.js
4.25 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
124
125
126
127
128
129
130
131
describe('ng-ckeditor', function () {
CKEDITOR_BASEPATH = '/base/ckeditor/';
var elm, scope, controller, content, instance, i = 1;
beforeEach(module('ngCkeditor'));
beforeEach(inject(function ($rootScope, $compile, $document) {
elm = angular.element(
'<span>{{test}}<textarea ckeditor id="' + 'editor' + i + '" ng-model="test"></textarea></span>');
scope = $rootScope.$new(true);
scope.test = 'test';
$document.find('body').append(elm);
$compile(elm)(scope);
controller = elm.controller('ngModel');
instance = CKEDITOR.instances['editor' + i++];
instance.on('instanceReady', function() {
content = angular.element(instance.container.$.getElementsByClassName('cke_wysiwyg_div')[0]);
});
scope.$digest();
}));
afterEach( function() {
elm.remove();
} );
it('should create editor', inject(function ($timeout, $rootScope, $document) {
var flag;
runs(function() {
expect(CKEDITOR.instances['editor' + (i - 1)]).toBeDefined();
expect(scope.test).toBe('test');
setTimeout(function() {
flag = true;
}, 500)
});
waitsFor(function() {
return flag;
}, "instance should be ready", 1000);
}));
it('should change model value editor', inject(function ($timeout, $rootScope, $document) {
var flag;
runs(function() {
flag = false;
scope.test = 'new value';
$rootScope.$apply();
setTimeout(function() {
// instance not ready
expect(instance.getData()).toBe('');
expect(scope.test).toBe('new value');
}, 10);
instance.on('instanceReady', function() {
$timeout.flush();
expect(content.html()).toBe('<p>new value</p>');
expect(instance.getData()).toBe('<p>new value</p>\n');
expect(scope.test).toBe('<p>new value</p>\n');
flag = true;
});
});
waitsFor(function() {
return flag;
}, "instance should be ready", 1000);
}));
it('should async change model value editor', inject(function ($timeout, $rootScope, $document) {
var flag;
runs(function() {
flag = false;
scope.test = 'new value';
setTimeout(function() {
scope.test = 'test again';
scope.$apply();
expect(scope.test).toBe('test again');
}, 1000);
setTimeout(function() {
content[0].focus();
// emulate key press
$(content[0]).simulate("click")
.simulate("keydown", {keyCode : 13, charCode: 0})
.simulate("keypress", {keyCode : 13, charCode: 0})
.simulate("keyup", {keyCode : 13, charCode: 0});
$timeout.flush();
}, 1100);
setTimeout(function() {
scope.$apply();
flag = true;
expect(scope.test).toBe('<p> </p>\n\n<p>test again</p>\n');
}, 1200);
});
waitsFor(function() {
return flag;
}, "value should be changed", 2000);
}));
it('should change in source view', inject(function ($timeout, $rootScope, $document) {
var flag;
runs(function() {
flag = false;
setTimeout(function() {
$('.cke_button__source').simulate("click")
// emulate key press
$('.cke_source').simulate("click")
.simulate("keydown", {keyCode : 13, charCode: 0})
.simulate("keypress", {keyCode : 13, charCode: 0})
.simulate("keyup", {keyCode : 13, charCode: 0});
$timeout.flush();
}, 100);
setTimeout(function() {
scope.$apply();
flag = true;
expect(scope.test).toBe('<p>test</p>\n');
}, 200);
});
waitsFor(function() {
return flag;
}, "value should be changed", 1000);
}));
});