Skip to content

Commit edbadb2

Browse files
committed
feat: add unit tests for html emmet hints
1 parent 288f04d commit edbadb2

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/extensions/default/HTMLCodeHints/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@ define(function (require, exports, module) {
12191219
CodeHintManager.registerHintProvider(emmetMarkupHints, ["html", "php", "jsp"], 0);
12201220

12211221
// For unit testing
1222+
exports.emmetHintProvider = emmetMarkupHints;
12221223
exports.tagHintProvider = tagHints;
12231224
exports.attrHintProvider = attrHints;
12241225
});

src/extensions/default/HTMLCodeHints/unittests.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,74 @@ define(function (require, exports, module) {
9494
expect(hintList[0]).toBe(expectedFirstHint);
9595
}
9696

97+
// Helper function for testing cursor position
98+
function fixPos(pos) {
99+
if (!("sticky" in pos)) {
100+
pos.sticky = null;
101+
}
102+
return pos;
103+
}
104+
105+
106+
describe("Emmet hint provider", function () {
107+
108+
it("should display boiler plate code on ! press", function () {
109+
110+
let emmetBoilerPlate = "<!DOCTYPE html>\n" +
111+
"<html lang=\"en\">\n" +
112+
"<head>\n" +
113+
" <meta charset=\"UTF-8\">\n" +
114+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
115+
" <title>Document</title>\n" +
116+
"</head>\n" +
117+
"<body>\n" +
118+
"\n" +
119+
"</body>\n" +
120+
"</html>\n";
121+
122+
testDocument.setText("!");
123+
testEditor.setCursorPos({ line: 0, ch: 1 });
124+
let emmetHintList = expectHints(HTMLCodeHints.emmetHintProvider);
125+
verifyTagHints(emmetHintList, emmetBoilerPlate);
126+
});
127+
128+
it("should display doctype html initial line on !!! press", function () {
129+
130+
let emmetBoilerPlate = "<!DOCTYPE html>";
131+
132+
testDocument.setText("!!!");
133+
testEditor.setCursorPos({ line: 0, ch: 3 });
134+
let emmetHintList = expectHints(HTMLCodeHints.emmetHintProvider);
135+
verifyTagHints(emmetHintList, emmetBoilerPlate);
136+
});
137+
138+
it("should not display emmet hints on < key press", function () {
139+
testDocument.setText("<");
140+
testEditor.setCursorPos({ line: 0, ch: 1 });
141+
expectNoHints(HTMLCodeHints.emmetHintProvider);
142+
});
143+
144+
it("should add class name id name if abbr contains . and #", function () {
145+
146+
console.log('--------------------------');
147+
console.log("reached here");
148+
console.log('--------------------------');
149+
150+
testDocument.setText("div.hello#world");
151+
testEditor.setCursorPos({ line: 0, ch: 15 });
152+
let emmetHintList = expectHints(HTMLCodeHints.emmetHintProvider);
153+
verifyTagHints(emmetHintList, "<div class=\"hello\" id=\"world\"></div>");
154+
});
155+
156+
it(". should expand to a div with empty class name and set cursor in between quotes", function() {
157+
testDocument.setText(".");
158+
testEditor.setCursorPos({ line: 0, ch: 0 });
159+
var hints = expectHints(HTMLCodeHints.emmetHintProvider);
160+
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
161+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 0, ch: 12}));
162+
});
163+
});
164+
97165

98166
describe("Tag hint provider", function () {
99167

0 commit comments

Comments
 (0)