forked from hockic/bootstrap-wysihtml5
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathbootstrap_editor_link_test.js
104 lines (81 loc) · 2.85 KB
/
bootstrap_editor_link_test.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
if (wysihtml5.browser.supported()) {
module('bootstrap3-wysihtml5-bower.toolbar.link', {
setup: function() {
this.container = testhelper.prepareFixtureWithTextarea();
this.editableArea = testhelper.getEditableArea();
},
teardown: function() {
QUnit.reset();
}
});
asyncTest('open link modal with mouse', function(){
expect(6);
var that = this;
var onLoad = function() {
//find link modal
var createLinkButton = that.container.find('[data-wysihtml5-command="createLink"]');
ok(createLinkButton.hasClass('btn'), 'Found button link.');
var createLinkModal = that.container.find('[data-wysihtml5-dialog="createLink"]');
ok(!createLinkModal.hasClass('in'), 'CreateLink modal is hidden');
createLinkButton.happen('click');
ok(createLinkButton.hasClass('wysihtml5-command-dialog-opened'), 'CreateLink modal is visible (class on button)');
};
var onShow = function(event) {
ok(true, 'show:dialog event was fired');
// 150 is the length of the fade transition
setTimeout(function() {
var modal = $(event.dialogContainer);
ok(modal.hasClass('in'), 'CreateLink modal is visible (class on modal)');
var cancelBtn = modal.find('[data-wysihtml5-dialog-action="cancel"]');
cancelBtn.happen('click');
}, 200);
};
var onHide = function(event) {
ok(true, 'cancel:dialog event was fired');
start();
};
var editor = this.editableArea.wysihtml5({
events: {
'load': onLoad,
'show:dialog': onShow,
'cancel:dialog': onHide
}
});
});
asyncTest('open link modal with keyboard', function(){
expect(6);
var that = this;
var onLoad = function() {
//find link modal
var createLinkButton = that.container.find('[data-wysihtml5-command="createLink"]');
ok(createLinkButton.hasClass('btn'), 'Found button link.');
var createLinkModal = that.container.find('[data-wysihtml5-dialog="createLink"]');
ok(!createLinkModal.hasClass('in'), 'CreateLink modal is hidden');
//trigger key Ctrl+k
$(this.composer.editableArea.contentDocument.body).happen({ type: 'keydown', keyCode: 75, ctrlKey: true });
ok(createLinkButton.hasClass('wysihtml5-command-dialog-opened'), 'CreateLink modal is visible (class on button)');
};
var onShow = function(event) {
ok(true, 'show:dialog event was fired');
setTimeout(function() {
var modal = $(event.dialogContainer);
ok(modal.hasClass('in'), 'CreateLink modal is visible (class on modal)');
modal.happen({ type: 'keydown', keyCode: 27, ctrlKey: false });
}, 200);
};
var onHide = function(event) {
ok(true, 'cancel:dialog event was fired');
start();
};
var editor = this.editableArea.wysihtml5({
events: {
'load': onLoad,
'show:dialog': onShow,
'cancel:dialog': onHide
},
shortcuts: {
'75': 'createLink' //k
}
});
});
}