-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy patheditor_options_test.js
86 lines (72 loc) · 2.51 KB
/
editor_options_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
if (typeof process !== "undefined") {
require("amd-loader");
require("./test/mockdom");
}
"use strict";
var assert = require("./test/assertions");
var sendKey = require("./test/user").type;
var ace = require("./ace");
var editor;
function mouse(type, pos, properties) {
var target = editor.renderer.getMouseEventTarget();
var event = new CustomEvent("mouse" + type, {bubbles: true});
if ("row" in pos) {
var pagePos = editor.renderer.textToScreenCoordinates(pos.row, pos.column);
event.clientX = pagePos.pageX;
event.clientY = pagePos.pageY;
}
else {
target = pos;
var rect = target.getBoundingClientRect();
event.clientX = rect.left + rect.width / 2;
event.clientY = rect.top + rect.height / 2;
}
Object.assign(event, properties);
target.dispatchEvent(event);
}
module.exports = {
setUp: function () {
editor = ace.edit(null, {
value: "999"
});
document.body.appendChild(editor.container);
editor.container.style.height = "200px";
editor.container.style.width = "300px";
editor.focus();
},
tearDown: function () {
editor.destroy();
editor = null;
},
"test readOnly Option": function (done) {
let readOnly = editor.getOption("readOnly");
assert.equal(editor.hoverTooltip, null);
assert.equal(readOnly, false);
editor.setOption("readOnly", true);
readOnly = editor.getOption("readOnly");
assert.equal(readOnly, true);
sendKey("a");
setTimeout(() => {
assert.equal(editor.getValue(), "999");
assert.ok(editor.hoverTooltip != null);
var nodes = document.querySelectorAll(".ace_tooltip");
assert.equal(nodes.length, 2);
assert.equal(editor.hoverTooltip.isOpen, true);
mouse("down", editor.container, {button: 0});
setTimeout(() => {
assert.equal(editor.hoverTooltip.isOpen, false);
editor.setOption("readOnly", false);
sendKey("a");
setTimeout(() => {
assert.equal(editor.getValue(), "a999");
var nodes = document.querySelectorAll(".ace_tooltip");
assert.equal(nodes.length, 1);
done();
}, 6);
}, 6);
}, 6);
}
};
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec();
}