forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunittests.js
More file actions
1 lines (1 loc) · 4.57 KB
/
Copy pathunittests.js
File metadata and controls
1 lines (1 loc) · 4.57 KB
1
define(function(require,exports,module){var SpecRunnerUtils=brackets.getModule("spec/SpecRunnerUtils"),CSSAtRuleCodeHints=require("main");describe("CSS '@' rules Code Hinting",function(){var defaultContent="@ { \n} \n \n@m ",testDocument,testEditor;function setupTest(content,languageId){var mock=SpecRunnerUtils.createMockEditor(content,languageId);testDocument=mock.doc,testEditor=mock.editor}function tearDownTest(){SpecRunnerUtils.destroyMockEditor(testDocument),testEditor=null,testDocument=null}function expectHints(provider,implicitChar,returnWholeObj){expect(provider.hasHints(testEditor,implicitChar)).toBe(!0);var hintsObj=provider.getHints();return expect(hintsObj).toBeTruthy(),returnWholeObj?hintsObj:hintsObj.hints}function expectNoHints(provider,implicitChar){expect(provider.hasHints(testEditor,implicitChar)).toBe(!1)}function verifyListsAreIdentical(hintList,values){var i;for(expect(hintList.length).toBe(values.length),i=0;i<values.length;i++)expect(hintList[i]).toBe(values[i])}function selectHint(provider,expectedHint,implicitChar){var hintList=expectHints(provider,implicitChar);return expect(hintList.indexOf(expectedHint)).not.toBe(-1),provider.insertHint(expectedHint)}function fixPos(pos){return"sticky"in pos||(pos.sticky=null),pos}function expectCursorAt(pos){var selection=testEditor.getSelection();expect(fixPos(selection.start)).toEql(fixPos(selection.end)),expect(fixPos(selection.start)).toEql(fixPos(pos))}function verifyFirstEntry(hintList,expectedFirstHint){expect(hintList[0]).toBe(expectedFirstHint)}function verifyAllValues(hintList,values){expect(hintList.length).toBe(values.length),expect(hintList.sort().toString()).toBe(values.sort().toString())}var modesToTest=["css","scss","less"],modeCounter,selectMode=function(){return modesToTest[modeCounter]};describe("'@' rules in styles mode (selection of correct restricted block based on input)",function(){beforeEach(function(){var mock=SpecRunnerUtils.createMockEditor(defaultContent,selectMode());testEditor=mock.editor,testDocument=mock.doc}),afterEach(function(){SpecRunnerUtils.destroyMockEditor(testDocument),testEditor=null,testDocument=null});var testAllHints=function(){testEditor.setCursorPos({line:0,ch:1});var hintList=expectHints(CSSAtRuleCodeHints.restrictedBlockHints);verifyFirstEntry(hintList,"@charset"),verifyListsAreIdentical(hintList,["@charset","@counter-style","@font-face","@font-feature-values","@import","@keyframes","@media","@namespace","@page","@supports"])},testFilteredHints=function(){testEditor.setCursorPos({line:3,ch:2});var hintList=expectHints(CSSAtRuleCodeHints.restrictedBlockHints);verifyFirstEntry(hintList,"@media"),verifyListsAreIdentical(hintList,["@media"])},testNoHintsOnSpace=function(){testEditor.setCursorPos({line:3,ch:3}),expect(CSSAtRuleCodeHints.restrictedBlockHints.hasHints(testEditor,"")).toBe(!1)},testNoHints=function(){testEditor.setCursorPos({line:0,ch:0}),expect(CSSAtRuleCodeHints.restrictedBlockHints.hasHints(testEditor,"c")).toBe(!1)};for(modeCounter in modesToTest)it("should list all rule hints right after @",testAllHints),it("should list filtered rule hints right after @m",testFilteredHints),it("should not list rule hints on space",testNoHintsOnSpace),it("should not list rule hints if the cursor is before @",testNoHints)}),describe("'@' rules in LESS mode (selection of correct restricted block based on input)",function(){defaultContent="@ { \n} \n \n@m \n@green: green;\n.div { \ncolor: @} \n",beforeEach(function(){var mock=SpecRunnerUtils.createMockEditor(defaultContent,"less");testEditor=mock.editor,testDocument=mock.doc}),afterEach(function(){SpecRunnerUtils.destroyMockEditor(testDocument),testEditor=null,testDocument=null}),it("should not list rule hints in less variable evaluation scope",function(){testEditor.setCursorPos({line:3,ch:3}),expect(CSSAtRuleCodeHints.restrictedBlockHints.hasHints(testEditor,"")).toBe(!1)})}),describe("'@' rule hint insertion",function(){beforeEach(function(){var mock=SpecRunnerUtils.createMockEditor(defaultContent,"css");testEditor=mock.editor,testDocument=mock.doc}),afterEach(function(){SpecRunnerUtils.destroyMockEditor(testDocument),testEditor=null,testDocument=null}),it("should insert @rule selected",function(){testEditor.setCursorPos({line:0,ch:1}),selectHint(CSSAtRuleCodeHints.restrictedBlockHints,"@charset"),expect(testDocument.getLine(0)).toBe("@charset { "),expectCursorAt({line:0,ch:8})}),it("should insert filtered selection by replacing the existing rule",function(){testEditor.setCursorPos({line:3,ch:2}),selectHint(CSSAtRuleCodeHints.restrictedBlockHints,"@media"),expect(testDocument.getLine(3)).toBe("@media "),expectCursorAt({line:3,ch:6})})})})});