Skip to content

Commit b5752bf

Browse files
committed
chore: write tests for lorem emmet
1 parent 00d87fd commit b5752bf

File tree

1 file changed

+63
-29
lines changed

1 file changed

+63
-29
lines changed

src/extensions/default/HTMLCodeHints/unittests.js

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ define(function (require, exports, module) {
2626

2727
// Modules from the SpecRunner window
2828
const SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
29-
Editor = brackets.getModule("editor/Editor").Editor,
30-
HTMLCodeHints = require("main");
29+
Editor = brackets.getModule("editor/Editor").Editor,
30+
HTMLCodeHints = require("main");
3131

3232
require("integ-tests");
3333

3434
describe("unit: HTML Code Hinting", function () {
3535

3636
var defaultContent = "<!doctype html>\n" +
37-
"<html>\n" +
38-
"<style type=\"text/css\">\n" +
39-
"</style>\n" +
40-
"<body>\n" +
41-
" <h1 id='foo'>Heading</h1>\n" + // tag without whitespace
42-
" <h3 id = 'bar' >Subheading</h3>\n" + // tag with whitespace
43-
" <p></p>\n" + // tag without attributes
44-
" <h5 id='aaa' class='bbb'></h5>\n" + // tag with two attributes
45-
" <div \n" + // incomplete tag
46-
"</body>\n" +
47-
"</html>\n";
37+
"<html>\n" +
38+
"<style type=\"text/css\">\n" +
39+
"</style>\n" +
40+
"<body>\n" +
41+
" <h1 id='foo'>Heading</h1>\n" + // tag without whitespace
42+
" <h3 id = 'bar' >Subheading</h3>\n" + // tag with whitespace
43+
" <p></p>\n" + // tag without attributes
44+
" <h5 id='aaa' class='bbb'></h5>\n" + // tag with two attributes
45+
" <div \n" + // incomplete tag
46+
"</body>\n" +
47+
"</html>\n";
4848

4949
var testDocument, testEditor;
5050

@@ -108,14 +108,14 @@ define(function (require, exports, module) {
108108
it("should not hint within <style> block", function () { // (bug #1277)
109109
// Replace default test content with code containing a <style> block
110110
testDocument.setText("<!doctype html>\n" +
111-
"<html>\n" +
112-
"<head>\n" +
113-
" <style>\n" +
114-
" </style>\n" +
115-
"</head>\n" +
116-
"<body>\n" +
117-
"</body>\n" +
118-
"</html>\n");
111+
"<html>\n" +
112+
"<head>\n" +
113+
" <style>\n" +
114+
" </style>\n" +
115+
"</head>\n" +
116+
"<body>\n" +
117+
"</body>\n" +
118+
"</html>\n");
119119

120120
testEditor.setCursorPos({ line: 3, ch: 9 }); // cursor after the > in "<style>"
121121
expectNoHints(HTMLCodeHints.tagHintProvider);
@@ -722,12 +722,12 @@ define(function (require, exports, module) {
722722
// also test after inserting the hint
723723
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
724724

725-
for(let i = 0; i <= 10; i++) {
725+
for (let i = 0; i <= 10; i++) {
726726
expect(testDocument.getLine(i)).toBe(emmetBoilerPlate[i]);
727727
}
728728

729729
// make sure the cursor is between the body tag
730-
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 8, ch: 1}));
730+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({ line: 8, ch: 1 }));
731731
});
732732

733733

@@ -745,7 +745,7 @@ define(function (require, exports, module) {
745745
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
746746
expect(testDocument.getLine(0)).toBe(emmetBoilerPlate);
747747

748-
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 0, ch: 15}));
748+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({ line: 0, ch: 15 }));
749749
});
750750

751751
it("should not display hints when two or more than three exclamation marks are present", function () {
@@ -776,26 +776,26 @@ define(function (require, exports, module) {
776776
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
777777
expect(testDocument.getLine(0)).toBe("<div class=\"hello\" id=\"world\"></div>");
778778

779-
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 0, ch: 30}));
779+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({ line: 0, ch: 30 }));
780780
});
781781

782-
it("./# should expand to a div with empty class/id name and set cursor in between quotes", function() {
782+
it("./# should expand to a div with empty class/id name and set cursor in between quotes", function () {
783783
testDocument.setText(".");
784784
testEditor.setCursorPos({ line: 0, ch: 1 });
785785
let hints = expectHints(HTMLCodeHints.emmetHintProvider);
786786

787787
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
788-
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 0, ch: 12}));
788+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({ line: 0, ch: 12 }));
789789

790790
testDocument.setText("#");
791791
testEditor.setCursorPos({ line: 0, ch: 1 });
792792
hints = expectHints(HTMLCodeHints.emmetHintProvider);
793793

794794
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
795-
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({line: 0, ch: 9}));
795+
expect(fixPos(testEditor.getCursorPos())).toEql(fixPos({ line: 0, ch: 9 }));
796796
});
797797

798-
it("should expand emmet snippet with * and {}", function() {
798+
it("should expand emmet snippet with * and {}", function () {
799799
const emmetSnippetResult = "<ul>\n" +
800800
" <li>hello world</li>\n" +
801801
" <li>hello world</li>\n" +
@@ -812,6 +812,40 @@ define(function (require, exports, module) {
812812
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
813813
expect(testDocument.getText()).toBe(emmetSnippetResult);
814814
});
815+
816+
it("should show emmet hint when lorem is typed and expand to lorem text", function () {
817+
testDocument.setText("lorem");
818+
testEditor.setCursorPos({ line: 0, ch: 5 });
819+
const hints = expectHints(HTMLCodeHints.emmetHintProvider);
820+
821+
const hintText = hints[0][0].textContent;
822+
expect(hintText).toBe("loremEmmet");
823+
824+
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
825+
826+
let text = testDocument.getText().toLowerCase();
827+
text = text.split(" ")[0];
828+
// add an extra space at the end to make sure that content after that is also present
829+
// we cannot check with exact text because it generates randomly
830+
text += ' ';
831+
expect(text).toBe("lorem ");
832+
});
833+
834+
it("should show emmet hint when lorem is typed along with some number and expand it", function () {
835+
testDocument.setText("lorem1");
836+
testEditor.setCursorPos({ line: 0, ch: 6 });
837+
const hints = expectHints(HTMLCodeHints.emmetHintProvider);
838+
839+
const hintText = hints[0][0].textContent;
840+
expect(hintText).toBe("lorem1Emmet");
841+
842+
HTMLCodeHints.emmetHintProvider.insertHint(hints[0]);
843+
844+
let text = testDocument.getText().toLowerCase();
845+
// lorem1 expands to lorem.
846+
// 1 here refers to the number of words
847+
expect(text).toBe("lorem.");
848+
});
815849
});
816850

817851

0 commit comments

Comments
 (0)