From 8f2b607cc887310adf414536d83576ec057f7df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 22 Mar 2013 05:23:34 -0300 Subject: [PATCH 1/6] New show line numbers tests and code refactor --- test/spec/EditorOptionHandlers-test.js | 346 ++++++++++++++----------- 1 file changed, 192 insertions(+), 154 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 4f5b837df27..6dfe15d7192 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -42,7 +42,11 @@ define(function (require, exports, module) { var testPath = SpecRunnerUtils.getTestPath("/spec/EditorOptionHandlers-test-files"), testWindow; - + + var CSS_FILE = testPath + "/test.css", + HTML_FILE = testPath + "/test.html"; + + beforeEach(function () { SpecRunnerUtils.createTestWindowAndRun(this, function (w) { testWindow = w; @@ -62,6 +66,7 @@ define(function (require, exports, module) { SpecRunnerUtils.closeTestWindow(); }); + function checkLineWrapping(firstPos, secondPos, shouldWrap, inlineEditor) { runs(function () { var firstLineBottom, @@ -82,190 +87,223 @@ define(function (require, exports, module) { } }); } - - var CSS_FILE = testPath + "/test.css", - HTML_FILE = testPath + "/test.html"; - - it("should wrap long lines in main editor by default", function () { - var promise, - editor; - + + + // Helper functions to open editors / toggle options + function openEditor(fullPath) { runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); + var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath}); waitsForDone(promise, "Open into working set"); - - // Use two cursor positions to detect line wrapping. First position at - // the beginning of a long line and the second position to be - // somewhere on the long line that will be part of an extra line - // created by word-wrap and get its bottom coordinate. - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); }); - }); - - it("should also wrap long lines in inline editor by default", function () { - var promise, - inlineEditor; - + } + function openAnotherEditor(fullpath) { runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); - waitsForDone(promise, "Open into working set"); + // Open another document and bring it to the front + waitsForDone(FileViewController.openAndSelectDocument(fullpath, FileViewController.PROJECT_MANAGER), + "FILE_OPEN on file timeout", 1000); }); + } + function openInlineEditor() { + openEditor(HTML_FILE); runs(function () { // Open inline editor onto test.css's ".testClass" rule - promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); + var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); waitsForDone(promise, "Open inline editor"); }); - + } + function toggleOption(commandID, text) { runs(function () { - inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - expect(inlineEditor).toBeTruthy(); - - checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, inlineEditor); + var promise = CommandManager.execute(commandID); + waitsForDone(promise, text); }); - }); + } + - it("should NOT wrap the long lines after turning off word-wrap", function () { - var promise, - editor; - - // Turn off word-wrap - runs(function () { - promise = CommandManager.execute(Commands.TOGGLE_WORD_WRAP); - waitsForDone(promise, "Toggle word-wrap"); + describe("Toggle Word Wrap", function () { + it("should wrap long lines in main editor by default", function () { + openEditor(HTML_FILE); + + runs(function () { + // Use two cursor positions to detect line wrapping. First position at + // the beginning of a long line and the second position to be + // somewhere on the long line that will be part of an extra line + // created by word-wrap and get its bottom coordinate. + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); + }); }); - - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); - waitsForDone(promise, "Open into working set"); - checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); + + it("should also wrap long lines in inline editor by default", function () { + var inlineEditor; + + openInlineEditor(); + + runs(function () { + inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + expect(inlineEditor).toBeTruthy(); + + checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, inlineEditor); + }); }); - }); - - it("should NOT wrap the long lines in another document when word-wrap off", function () { - var promise, - editor, - firstLineBottom, - nextLineBottom; - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); - waitsForDone(promise, "Open into working set"); - }); - - // Turn off word-wrap - runs(function () { - promise = CommandManager.execute(Commands.TOGGLE_WORD_WRAP); - waitsForDone(promise, "Toggle word-wrap"); + it("should NOT wrap the long lines after turning off word-wrap", function () { + // Turn off word-wrap + toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); + + openEditor(CSS_FILE); + + runs(function () { + checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); + }); }); - - runs(function () { - // Open another document and bring it to the front - waitsForDone(FileViewController.openAndSelectDocument(HTML_FILE, FileViewController.PROJECT_MANAGER), - "FILE_OPEN on file timeout", 1000); - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); + + it("should NOT wrap the long lines in another document when word-wrap off", function () { + openEditor(CSS_FILE); + + // Turn off word-wrap + toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); + + openAnotherEditor(HTML_FILE); + + runs(function () { + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); + }); }); }); - - it("should show active line in main editor by default", function () { - var promise, - editor, - lineInfo; - - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); - waitsForDone(promise, "Open into working set"); - }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 5, ch: 0}); - lineInfo = editor._codeMirror.lineInfo(5); - expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + + + describe("Toggle Active Line", function () { + it("should show active line in main editor by default", function () { + var editor, lineInfo; + + openEditor(HTML_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 5, ch: 0}); + lineInfo = editor._codeMirror.lineInfo(5); + expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + }); }); - }); - - it("should also show active line in inline editor by default", function () { - var promise, - inlineEditor, - lineInfo; - - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: HTML_FILE}); - waitsForDone(promise, "Open into working set"); + + it("should also show active line in inline editor by default", function () { + var inlineEditor, lineInfo; + + openInlineEditor(); + + runs(function () { + inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + expect(inlineEditor).toBeTruthy(); + + lineInfo = inlineEditor._codeMirror.lineInfo(0); + expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + }); }); - runs(function () { - // Open inline editor onto test.css's ".testClass" rule - promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); - waitsForDone(promise, "Open inline editor"); + it("should NOT style active line after turning it off", function () { + var editor, lineInfo; + + // Turn off show active line + toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); + + openEditor(CSS_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + lineInfo = editor._codeMirror.lineInfo(0); + expect(lineInfo.wrapClass).toBeUndefined(); + }); }); - - runs(function () { - inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - expect(inlineEditor).toBeTruthy(); - - lineInfo = inlineEditor._codeMirror.lineInfo(0); - expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + + it("should NOT style the active line when opening another document with show active line off", function () { + var editor, lineInfo; + + openEditor(CSS_FILE); + + // Turn off show active line + toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); + + openAnotherEditor(HTML_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + editor.setCursorPos({line: 3, ch: 5}); + lineInfo = editor._codeMirror.lineInfo(3); + expect(lineInfo.wrapClass).toBeUndefined(); + }); }); }); - it("should NOT style active line after turning it off", function () { - var promise, - editor, - lineInfo; - - // Turn off show active line - runs(function () { - promise = CommandManager.execute(Commands.TOGGLE_ACTIVE_LINE); - waitsForDone(promise, "Toggle active line"); - }); - - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); - waitsForDone(promise, "Open into working set"); - }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - lineInfo = editor._codeMirror.lineInfo(0); - expect(lineInfo.wrapClass).toBeUndefined(); + + describe("Toggle Line Numbers", function () { + it("should show line numbers in main editor by default", function () { + var editor, gutterElement; + + openEditor(HTML_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + gutterElement = editor._codeMirror.getGutterElement(); + expect(gutterElement.style.display).toBe(""); + }); }); - }); - - it("should NOT style the active line when opening another document with show active line off", function () { - var promise, - editor, - lineInfo; - runs(function () { - promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: CSS_FILE}); - waitsForDone(promise, "Open into working set"); - }); - - // Turn off show active line - runs(function () { - promise = CommandManager.execute(Commands.TOGGLE_ACTIVE_LINE); - waitsForDone(promise, "Toggle active line"); + it("should also show line numbers in inline editor by default", function () { + var inlineEditor, gutterElement; + + openInlineEditor(); + + runs(function () { + inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + expect(inlineEditor).toBeTruthy(); + + gutterElement = inlineEditor._codeMirror.getGutterElement(); + expect(gutterElement.style.display).toBe(""); + }); }); - - runs(function () { - // Open another document and bring it to the front - waitsForDone(FileViewController.openAndSelectDocument(HTML_FILE, FileViewController.PROJECT_MANAGER), - "FILE_OPEN on file timeout", 1000); + + it("should NOT show line numbers after turning it off", function () { + var editor, gutterElement; + + // Turn off show line numbers + toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); + + openEditor(CSS_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + gutterElement = editor._codeMirror.getGutterElement(); + expect(gutterElement.style.display).toBe("none"); + }); }); - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 3, ch: 5}); - lineInfo = editor._codeMirror.lineInfo(3); - expect(lineInfo.wrapClass).toBeUndefined(); + it("should NOT show line numbers when opening another document with show line numbers off", function () { + var editor, gutterElement; + + openEditor(CSS_FILE); + + // Turn off show line numbers + toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); + + openAnotherEditor(HTML_FILE); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + expect(editor).toBeTruthy(); + + gutterElement = editor._codeMirror.getGutterElement(); + expect(gutterElement.style.display).toBe("none"); + }); }); }); }); From c7ef1ea57e43596ba977ee9dd6850f43859889b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sat, 23 Mar 2013 07:16:34 -0300 Subject: [PATCH 2/6] Adding auto close brackets tests --- test/SpecRunner.html | 1 + .../EditorOptionHandlers-test-files/test.js | 1 + test/spec/EditorOptionHandlers-test.js | 270 +++++++++++------- test/spec/SpecRunnerUtils.js | 7 +- 4 files changed, 172 insertions(+), 107 deletions(-) create mode 100644 test/spec/EditorOptionHandlers-test-files/test.js diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 1b134ac7c3e..033dcfd424f 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -39,6 +39,7 @@ + diff --git a/test/spec/EditorOptionHandlers-test-files/test.js b/test/spec/EditorOptionHandlers-test-files/test.js new file mode 100644 index 00000000000..c648c40902f --- /dev/null +++ b/test/spec/EditorOptionHandlers-test-files/test.js @@ -0,0 +1 @@ +var myContent = "This is awesome!"; \ No newline at end of file diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 6dfe15d7192..d05da826e43 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -44,7 +44,12 @@ define(function (require, exports, module) { testWindow; var CSS_FILE = testPath + "/test.css", - HTML_FILE = testPath + "/test.html"; + HTML_FILE = testPath + "/test.html", + JS_FILE = testPath + "/test.js"; + + var OPEN_BRACKET = 91, + CLOSE_BRACKET = 93, + BACKSPACE = 8; beforeEach(function () { @@ -66,12 +71,20 @@ define(function (require, exports, module) { SpecRunnerUtils.closeTestWindow(); }); + function getEditor(isInlineEditor) { + if (isInlineEditor) { + return EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + } else { + return EditorManager.getCurrentFullEditor(); + } + } + - function checkLineWrapping(firstPos, secondPos, shouldWrap, inlineEditor) { + function checkLineWrapping(firstPos, secondPos, shouldWrap, isInlineEditor) { runs(function () { var firstLineBottom, nextLineBottom, - editor = inlineEditor || EditorManager.getCurrentFullEditor(); + editor = getEditor(isInlineEditor); expect(editor).toBeTruthy(); @@ -80,6 +93,7 @@ define(function (require, exports, module) { editor.setCursorPos(secondPos); nextLineBottom = editor._codeMirror.cursorCoords(null, "local").bottom; + if (shouldWrap) { expect(firstLineBottom).toBeLessThan(nextLineBottom); } else { @@ -88,6 +102,59 @@ define(function (require, exports, module) { }); } + function checkActiveLine(line, shouldShow, isInlineEditor) { + runs(function () { + var lineInfo, + editor = getEditor(isInlineEditor); + + expect(editor).toBeTruthy(); + editor.setCursorPos({line: line, ch: 0}); + lineInfo = editor._codeMirror.lineInfo(line); + + if (shouldShow) { + expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); + } else { + expect(lineInfo.wrapClass).toBeUndefined(); + } + }); + } + + function checkLineNumbers(shouldShow, isInlineEditor) { + runs(function () { + var gutterElement, + editor = getEditor(isInlineEditor); + + expect(editor).toBeTruthy(); + gutterElement = editor._codeMirror.getGutterElement(); + + if (shouldShow) { + expect(gutterElement.style.display).toBe(""); + } else { + expect(gutterElement.style.display).toBe("none"); + } + }); + } + + function checkCloseBrackets(startSel, endSel, keyCode, expectedText, isInlineEditor) { + runs(function () { + var line, + editor = getEditor(isInlineEditor), + input = editor._codeMirror.getInputField(); + + expect(editor).toBeTruthy(); + if (endSel) { + editor.setSelection(startSel, endSel); + } else { + editor.setCursorPos(startSel); + } + + SpecRunnerUtils.simulateKeyEvent(keyCode, keyCode === BACKSPACE ? "keydown" : "keypress", input); + + line = editor._codeMirror.getLine(0).substr(0, expectedText.length); + expect(line).toBe(expectedText); + }); + } + // Helper functions to open editors / toggle options function openEditor(fullPath) { @@ -124,26 +191,16 @@ define(function (require, exports, module) { it("should wrap long lines in main editor by default", function () { openEditor(HTML_FILE); - runs(function () { - // Use two cursor positions to detect line wrapping. First position at - // the beginning of a long line and the second position to be - // somewhere on the long line that will be part of an extra line - // created by word-wrap and get its bottom coordinate. - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); - }); + // Use two cursor positions to detect line wrapping. First position at + // the beginning of a long line and the second position to be + // somewhere on the long line that will be part of an extra line + // created by word-wrap and get its bottom coordinate. + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); }); it("should also wrap long lines in inline editor by default", function () { - var inlineEditor; - openInlineEditor(); - - runs(function () { - inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - expect(inlineEditor).toBeTruthy(); - - checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, inlineEditor); - }); + checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, true); }); it("should NOT wrap the long lines after turning off word-wrap", function () { @@ -151,10 +208,7 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); openEditor(CSS_FILE); - - runs(function () { - checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); - }); + checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false, false); }); it("should NOT wrap the long lines in another document when word-wrap off", function () { @@ -164,147 +218,151 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); openAnotherEditor(HTML_FILE); - - runs(function () { - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); - }); + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false, false); }); }); describe("Toggle Active Line", function () { it("should show active line in main editor by default", function () { - var editor, lineInfo; - openEditor(HTML_FILE); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 5, ch: 0}); - lineInfo = editor._codeMirror.lineInfo(5); - expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); - }); + checkActiveLine(5, true, false); }); it("should also show active line in inline editor by default", function () { - var inlineEditor, lineInfo; - openInlineEditor(); - - runs(function () { - inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - expect(inlineEditor).toBeTruthy(); - - lineInfo = inlineEditor._codeMirror.lineInfo(0); - expect(lineInfo.wrapClass).toBe("CodeMirror-activeline"); - }); + checkActiveLine(0, true, true); }); it("should NOT style active line after turning it off", function () { - var editor, lineInfo; - // Turn off show active line toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); openEditor(CSS_FILE); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - lineInfo = editor._codeMirror.lineInfo(0); - expect(lineInfo.wrapClass).toBeUndefined(); - }); + checkActiveLine(0, false, false); }); it("should NOT style the active line when opening another document with show active line off", function () { - var editor, lineInfo; - openEditor(CSS_FILE); // Turn off show active line toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); openAnotherEditor(HTML_FILE); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - editor.setCursorPos({line: 3, ch: 5}); - lineInfo = editor._codeMirror.lineInfo(3); - expect(lineInfo.wrapClass).toBeUndefined(); - }); + checkActiveLine(3, false, false); }); }); describe("Toggle Line Numbers", function () { it("should show line numbers in main editor by default", function () { - var editor, gutterElement; - openEditor(HTML_FILE); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - gutterElement = editor._codeMirror.getGutterElement(); - expect(gutterElement.style.display).toBe(""); - }); + checkLineNumbers(true, false); }); it("should also show line numbers in inline editor by default", function () { - var inlineEditor, gutterElement; - openInlineEditor(); - - runs(function () { - inlineEditor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - expect(inlineEditor).toBeTruthy(); - - gutterElement = inlineEditor._codeMirror.getGutterElement(); - expect(gutterElement.style.display).toBe(""); - }); + checkLineNumbers(true, true); }); it("should NOT show line numbers after turning it off", function () { - var editor, gutterElement; - // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); openEditor(CSS_FILE); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - gutterElement = editor._codeMirror.getGutterElement(); - expect(gutterElement.style.display).toBe("none"); - }); + checkLineNumbers(false, false); }); it("should NOT show line numbers when opening another document with show line numbers off", function () { - var editor, gutterElement; - openEditor(CSS_FILE); // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); openAnotherEditor(HTML_FILE); + checkLineNumbers(false, false); + }); + }); + + + describe("Toggle Auto Close Brackets", function () { + it("should NOT auto close brackets in main editor by default", function () { + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";", false); + }); + + it("should NOT auto close brackets in inline editor by default", function () { + openInlineEditor(); + checkCloseBrackets({line: 0, ch: 14}, null, OPEN_BRACKET, ".longLineClass ", true); + }); + + it("should auto close brackets after turning it off", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]", false); + }); + + it("should auto close brackets when opening another document with auto close brackets on", function () { + openEditor(CSS_FILE); + + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + + openAnotherEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]", false); + }); + + it("should only auto close brackets before spaces, a closing brackets or an end of line", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 0}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";", false); + checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); + checkCloseBrackets({line: 0, ch: 16}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";", false); + checkCloseBrackets({line: 0, ch: 39}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";[]", false); + }); + + it("should overwrite a closing bracket when cursor is before a closing bracket or selecting it", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); + + checkCloseBrackets({line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";", false); runs(function () { - editor = EditorManager.getCurrentFullEditor(); - expect(editor).toBeTruthy(); - - gutterElement = editor._codeMirror.getGutterElement(); - expect(gutterElement.style.display).toBe("none"); + expect(getEditor().getCursorPos()).toEqual({line: 0, ch: 17}); + }); + + checkCloseBrackets({line: 0, ch: 16}, {line: 0, ch: 17}, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";", false); + runs(function () { + expect(getEditor().getCursorPos()).toEqual({line: 0, ch: 17}); }); }); + + it("should wrap a selection between brackets", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];", false); + + runs(function () { + expect(getEditor().getSelection()).toEqual({start: {line: 0, ch: 16}, end: {line: 0, ch: 36}}); + }); + }); + + it("should delete both open and close brackets when both are together", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + + openEditor(JS_FILE); + checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); + checkCloseBrackets({line: 0, ch: 16}, null, BACKSPACE, "var myContent = \"This is awesome!\";", false); + }); }); }); }); diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index a031fd40acf..2c6f5884b7b 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -749,9 +749,14 @@ define(function (require, exports, module) { return this.keyCodeVal; } }); + Object.defineProperty(oEvent, 'charCode', { + get: function () { + return this.keyCodeVal; + } + }); if (oEvent.initKeyboardEvent) { - oEvent.initKeyboardEvent(event, true, true, doc.defaultView, false, false, false, false, key, key); + oEvent.initKeyboardEvent(event, true, true, doc.defaultView, key, 0, false, false, false, false); } else { oEvent.initKeyEvent(event, true, true, doc.defaultView, false, false, false, false, key, 0); } From 4ebca4aa58c6649118c5ef90b3e7d5b08dd8a337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 5 Apr 2013 00:30:03 -0300 Subject: [PATCH 3/6] Fixes after first review --- .../EditorOptionHandlers-test-files/test.css | 3 +- .../EditorOptionHandlers-test-files/test.html | 2 +- .../EditorOptionHandlers-test-files/test.js | 3 +- test/spec/EditorOptionHandlers-test.js | 183 ++++++++++-------- test/spec/ViewUtils-test.js | 4 +- 5 files changed, 114 insertions(+), 81 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test-files/test.css b/test/spec/EditorOptionHandlers-test-files/test.css index ef7b580936b..410ce93e930 100644 --- a/test/spec/EditorOptionHandlers-test-files/test.css +++ b/test/spec/EditorOptionHandlers-test-files/test.css @@ -1 +1,2 @@ -.longLineClass { margin: 0 auto; padding: 2em; max-width: 800px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5em; color: #333333; background-color: #ffffff; -webkit-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); -moz-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); } \ No newline at end of file +.longLineClass { margin: 0 auto; padding: 2em; max-width: 800px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5em; color: #333333; background-color: #ffffff; -webkit-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); -moz-box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); box-shadow: 0 0 12px rgba(0, 0, 0, 0.4); } +.shortLineClass { color: red; } diff --git a/test/spec/EditorOptionHandlers-test-files/test.html b/test/spec/EditorOptionHandlers-test-files/test.html index 0e8c832fc03..d3155237033 100644 --- a/test/spec/EditorOptionHandlers-test-files/test.html +++ b/test/spec/EditorOptionHandlers-test-files/test.html @@ -7,6 +7,6 @@

Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome!

-

Brackets is awesome!

+

Brackets is awesome!

\ No newline at end of file diff --git a/test/spec/EditorOptionHandlers-test-files/test.js b/test/spec/EditorOptionHandlers-test-files/test.js index c648c40902f..2e3d014445e 100644 --- a/test/spec/EditorOptionHandlers-test-files/test.js +++ b/test/spec/EditorOptionHandlers-test-files/test.js @@ -1 +1,2 @@ -var myContent = "This is awesome!"; \ No newline at end of file +var myContent = "This is awesome!"; +// Yes, it is! \ No newline at end of file diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index ffebc8679ad..51e9f1e32b7 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -26,7 +26,7 @@ /*global define, $, describe, beforeEach, afterEach, it, runs, waitsFor, expect, brackets, waitsForDone */ define(function (require, exports, module) { - 'use strict'; + "use strict"; // Load dependent modules var CommandManager, // loaded from brackets.test @@ -41,7 +41,8 @@ define(function (require, exports, module) { this.category = "integration"; var testPath = SpecRunnerUtils.getTestPath("/spec/EditorOptionHandlers-test-files"), - testWindow; + testWindow, + editor; var CSS_FILE = testPath + "/test.css", HTML_FILE = testPath + "/test.html", @@ -49,6 +50,7 @@ define(function (require, exports, module) { var OPEN_BRACKET = 91, CLOSE_BRACKET = 93, + SINGLE_QUOTE = 39, BACKSPACE = 8; @@ -65,26 +67,17 @@ define(function (require, exports, module) { SpecRunnerUtils.loadProjectInTestWindow(testPath); }); + editor = null; }); afterEach(function () { SpecRunnerUtils.closeTestWindow(); }); - function getEditor(isInlineEditor) { - if (isInlineEditor) { - return EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - } else { - return EditorManager.getCurrentFullEditor(); - } - } - - function checkLineWrapping(firstPos, secondPos, shouldWrap, isInlineEditor) { + function checkLineWrapping(firstPos, secondPos, shouldWrap) { runs(function () { - var editor = getEditor(isInlineEditor), - firstLineBottom, - nextLineBottom; + var firstLineBottom, nextLineBottom; expect(editor).toBeTruthy(); @@ -102,10 +95,9 @@ define(function (require, exports, module) { }); } - function checkActiveLine(line, shouldShow, isInlineEditor) { + function checkActiveLine(line, shouldShow) { runs(function () { - var editor = getEditor(isInlineEditor), - lineInfo; + var lineInfo; expect(editor).toBeTruthy(); editor.setCursorPos({line: line, ch: 0}); @@ -119,27 +111,25 @@ define(function (require, exports, module) { }); } - function checkLineNumbers(shouldShow, isInlineEditor) { + function checkLineNumbers(shouldShow) { runs(function () { - var editor = getEditor(isInlineEditor), - gutterElement; + var gutterElement, $gutter; expect(editor).toBeTruthy(); gutterElement = editor._codeMirror.getGutterElement(); + $gutter = testWindow.$(gutterElement).find(".CodeMirror-linenumbers"); if (shouldShow) { - expect(gutterElement.style.display).toBe(""); + expect($gutter.length).toNotBe(0); } else { - expect(gutterElement.style.display).toBe("none"); + expect($gutter.length).toBe(0); } }); } - function checkCloseBrackets(startSel, endSel, keyCode, expectedText, isInlineEditor) { + function checkCloseBraces(startSel, endSel, keyCode, expectedText) { runs(function () { - var editor = getEditor(isInlineEditor), - input, - line; + var input, line; expect(editor).toBeTruthy(); input = editor._codeMirror.getInputField(); @@ -152,7 +142,7 @@ define(function (require, exports, module) { SpecRunnerUtils.simulateKeyEvent(keyCode, keyCode === BACKSPACE ? "keydown" : "keypress", input); - line = editor._codeMirror.getLine(0).substr(0, expectedText.length); + line = editor._codeMirror.getLine(startSel.line); expect(line).toBe(expectedText); }); } @@ -164,23 +154,39 @@ define(function (require, exports, module) { var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath}); waitsForDone(promise, "Open into working set"); }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + }); } + function openAnotherEditor(fullpath) { runs(function () { // Open another document and bring it to the front waitsForDone(FileViewController.openAndSelectDocument(fullpath, FileViewController.PROJECT_MANAGER), "FILE_OPEN on file timeout", 1000); }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor(); + }); } - function openInlineEditor() { + + function openInlineEditor(toggleEditorAt) { + toggleEditorAt = toggleEditorAt || {line: 8, ch: 11}; openEditor(HTML_FILE); runs(function () { // Open inline editor onto test.css's ".testClass" rule - var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 8, ch: 11}); + var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), toggleEditorAt); waitsForDone(promise, "Open inline editor"); }); + + runs(function () { + editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + }); } + function toggleOption(commandID, text) { runs(function () { var promise = CommandManager.execute(commandID); @@ -202,7 +208,7 @@ define(function (require, exports, module) { it("should also wrap long lines in inline editor by default", function () { openInlineEditor(); - checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true, true); + checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true); }); it("should NOT wrap the long lines after turning off word-wrap", function () { @@ -210,7 +216,7 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); openEditor(CSS_FILE); - checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false, false); + checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); }); it("should NOT wrap the long lines in another document when word-wrap off", function () { @@ -220,7 +226,7 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); openAnotherEditor(HTML_FILE); - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false, false); + checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); }); }); @@ -228,12 +234,12 @@ define(function (require, exports, module) { describe("Toggle Active Line", function () { it("should NOT show active line in main editor by default", function () { openEditor(HTML_FILE); - checkActiveLine(5, false, false); + checkActiveLine(5, false); }); it("should NOT show active line in inline editor by default", function () { openInlineEditor(); - checkActiveLine(0, false, true); + checkActiveLine(0, false); }); it("should style active line after turning it on", function () { @@ -241,7 +247,7 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); openEditor(CSS_FILE); - checkActiveLine(0, true, false); + checkActiveLine(0, true); }); it("should style the active line when opening another document with show active line on", function () { @@ -251,7 +257,7 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); openAnotherEditor(HTML_FILE); - checkActiveLine(3, true, false); + checkActiveLine(3, true); }); }); @@ -259,20 +265,28 @@ define(function (require, exports, module) { describe("Toggle Line Numbers", function () { it("should show line numbers in main editor by default", function () { openEditor(HTML_FILE); - checkLineNumbers(true, false); + checkLineNumbers(true); }); it("should also show line numbers in inline editor by default", function () { openInlineEditor(); - checkLineNumbers(true, true); + checkLineNumbers(true); }); - it("should NOT show line numbers after turning it off", function () { + it("should NOT show line numbers after turning it off in the main editor", function () { // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); openEditor(CSS_FILE); - checkLineNumbers(false, false); + checkLineNumbers(false); + }); + + it("should NOT show line numbers after turning it off in inline editors", function () { + // Turn off show line numbers + toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); + + openInlineEditor(); + checkLineNumbers(false); }); it("should NOT show line numbers when opening another document with show line numbers off", function () { @@ -282,83 +296,100 @@ define(function (require, exports, module) { toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); openAnotherEditor(HTML_FILE); - checkLineNumbers(false, false); + checkLineNumbers(false); }); }); - describe("Toggle Auto Close Brackets", function () { - it("should NOT auto close brackets in main editor by default", function () { + describe("Toggle Auto Close Braces", function () { + it("should NOT auto close braces in main editor by default", function () { openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";", false); + checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); }); - it("should NOT auto close brackets in inline editor by default", function () { - openInlineEditor(); - checkCloseBrackets({line: 0, ch: 14}, null, OPEN_BRACKET, ".longLineClass ", true); + it("should NOT auto close braces in inline editor by default", function () { + openInlineEditor({line: 9, ch: 11}); + checkCloseBraces({line: 1, ch: 15}, null, OPEN_BRACKET, ".shortLineClass { color: red; }"); }); - it("should auto close brackets after turning it on", function () { - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + it("should auto close braces after turning it on in the main editor", function () { + // Turn on auto close braces + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]", false); + checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); + }); + + it("should auto close braces after turning it on in inline editors", function () { + // Turn on auto close braces + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); + + openInlineEditor({line: 9, ch: 11}); + checkCloseBraces({line: 1, ch: 32}, null, OPEN_BRACKET, ".shortLineClass { color: red; }[]"); }); - it("should auto close brackets when opening another document with auto close brackets on", function () { + it("should auto close braces when opening another document with auto close braces on", function () { openEditor(CSS_FILE); - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + // Turn on auto close braces + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); openAnotherEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]", false); + checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); }); - it("should only auto close brackets before spaces, closing brackets or end of lines", function () { - // Turn on auto close brackets + it("should only auto close braces before spaces, closing braces or end of lines", function () { + // Turn on auto close braces toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 0}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";", false); - checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); - checkCloseBrackets({line: 0, ch: 16}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";", false); - checkCloseBrackets({line: 0, ch: 39}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";[]", false); + checkCloseBraces({line: 0, ch: 0}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); + checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); + checkCloseBraces({line: 0, ch: 16}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";"); + checkCloseBraces({line: 0, ch: 39}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";[]"); }); - it("should overwrite a close bracket when writing a close bracket before the same close bracket", function () { - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + it("should overwrite a close brace when writing a close brace before the same close brace", function () { + // Turn on auto close braces + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); + checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); - checkCloseBrackets({line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";", false); + checkCloseBraces({line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";"); runs(function () { - expect(getEditor().getCursorPos()).toEqual({line: 0, ch: 17}); + expect(editor.getCursorPos()).toEqual({line: 0, ch: 17}); }); }); - it("should wrap a selection between brackets", function () { - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + it("should wrap a selection between braces", function () { + // Turn on auto close braces + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];", false); + checkCloseBraces({line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];"); runs(function () { - expect(getEditor().getSelection()).toEqual({start: {line: 0, ch: 16}, end: {line: 0, ch: 36}}); + expect(editor.getSelection()).toEqual({start: {line: 0, ch: 16}, end: {line: 0, ch: 36}}); }); }); - it("should delete both open and close brackets when both are together and backspacing", function () { + it("should delete both open and close braces when both are together and backspacing", function () { // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); + + openEditor(JS_FILE); + checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); + checkCloseBraces({line: 0, ch: 16}, null, BACKSPACE, "var myContent = \"This is awesome!\";"); + }); + + it("should NOT auto close single quotes inside comments", function () { + // Turn on auto close brackets + toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); openEditor(JS_FILE); - checkCloseBrackets({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";", false); - checkCloseBrackets({line: 0, ch: 16}, null, BACKSPACE, "var myContent = \"This is awesome!\";", false); + checkCloseBraces({line: 0, ch: 15}, null, SINGLE_QUOTE, "var myContent ='' \"This is awesome!\";"); + checkCloseBraces({line: 1, ch: 7}, null, SINGLE_QUOTE, "// Yes, it is!"); }); }); }); diff --git a/test/spec/ViewUtils-test.js b/test/spec/ViewUtils-test.js index 0cafcfedb5f..3c03b0c2d3c 100644 --- a/test/spec/ViewUtils-test.js +++ b/test/spec/ViewUtils-test.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. + * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -25,7 +25,7 @@ /*global define: false, describe: false, $: false, beforeEach: false, afterEach: false, it: false, expect: false, brackets: false */ define(function (require, exports, module) { - 'use strict'; + "use strict"; // Load dependent modules var ViewUtils = require("utils/ViewUtils"); From 21604ebdb758289a314da9abb3fa8fca48d3a873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 5 Apr 2013 00:34:29 -0300 Subject: [PATCH 4/6] Minor text fixes --- test/spec/EditorOptionHandlers-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 51e9f1e32b7..7fd1c93e117 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -273,7 +273,7 @@ define(function (require, exports, module) { checkLineNumbers(true); }); - it("should NOT show line numbers after turning it off in the main editor", function () { + it("should NOT show line numbers in main editor after turning it off", function () { // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); @@ -281,7 +281,7 @@ define(function (require, exports, module) { checkLineNumbers(false); }); - it("should NOT show line numbers after turning it off in inline editors", function () { + it("should NOT show line numbers in inline editor after turning it off", function () { // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); @@ -312,7 +312,7 @@ define(function (require, exports, module) { checkCloseBraces({line: 1, ch: 15}, null, OPEN_BRACKET, ".shortLineClass { color: red; }"); }); - it("should auto close braces after turning it on in the main editor", function () { + it("should auto close braces in the main editor after turning it on", function () { // Turn on auto close braces toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); @@ -320,7 +320,7 @@ define(function (require, exports, module) { checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); }); - it("should auto close braces after turning it on in inline editors", function () { + it("should auto close braces in inline editor after turning it on", function () { // Turn on auto close braces toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); From a9ab5c6b227fc59a845764e047f3b7c8adefd16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sat, 6 Apr 2013 18:31:31 -0300 Subject: [PATCH 5/6] Fixes after second review --- test/spec/EditorOptionHandlers-test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index 7fd1c93e117..e871a7d3b24 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -42,7 +42,7 @@ define(function (require, exports, module) { var testPath = SpecRunnerUtils.getTestPath("/spec/EditorOptionHandlers-test-files"), testWindow, - editor; + editor = null; var CSS_FILE = testPath + "/test.css", HTML_FILE = testPath + "/test.html", @@ -67,11 +67,11 @@ define(function (require, exports, module) { SpecRunnerUtils.loadProjectInTestWindow(testPath); }); - editor = null; }); afterEach(function () { SpecRunnerUtils.closeTestWindow(); + editor = null; }); @@ -113,16 +113,16 @@ define(function (require, exports, module) { function checkLineNumbers(shouldShow) { runs(function () { - var gutterElement, $gutter; + var gutterElement, $lineNumbers; expect(editor).toBeTruthy(); gutterElement = editor._codeMirror.getGutterElement(); - $gutter = testWindow.$(gutterElement).find(".CodeMirror-linenumbers"); + $lineNumbers = $(gutterElement).find(".CodeMirror-linenumbers"); if (shouldShow) { - expect($gutter.length).toNotBe(0); + expect($lineNumbers.length).toNotBe(0); } else { - expect($gutter.length).toBe(0); + expect($lineNumbers.length).toBe(0); } }); } @@ -221,7 +221,7 @@ define(function (require, exports, module) { it("should NOT wrap the long lines in another document when word-wrap off", function () { openEditor(CSS_FILE); - + // Turn off word-wrap toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); From 2346c02888db8b1dc800097fe0984e3223ff3831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sat, 6 Apr 2013 23:53:01 -0300 Subject: [PATCH 6/6] It now passes editor as a parameter using run and all the tests run in one window --- test/spec/EditorOptionHandlers-test.js | 271 +++++++++++++++---------- 1 file changed, 163 insertions(+), 108 deletions(-) diff --git a/test/spec/EditorOptionHandlers-test.js b/test/spec/EditorOptionHandlers-test.js index e871a7d3b24..be1b905f5a6 100644 --- a/test/spec/EditorOptionHandlers-test.js +++ b/test/spec/EditorOptionHandlers-test.js @@ -41,8 +41,7 @@ define(function (require, exports, module) { this.category = "integration"; var testPath = SpecRunnerUtils.getTestPath("/spec/EditorOptionHandlers-test-files"), - testWindow, - editor = null; + testWindow; var CSS_FILE = testPath + "/test.css", HTML_FILE = testPath + "/test.html", @@ -55,27 +54,37 @@ define(function (require, exports, module) { beforeEach(function () { - SpecRunnerUtils.createTestWindowAndRun(this, function (w) { - testWindow = w; - - // Load module instances from brackets.test - CommandManager = testWindow.brackets.test.CommandManager; - Commands = testWindow.brackets.test.Commands; - EditorManager = testWindow.brackets.test.EditorManager; - DocumentManager = testWindow.brackets.test.DocumentManager; - FileViewController = testWindow.brackets.test.FileViewController; - - SpecRunnerUtils.loadProjectInTestWindow(testPath); - }); + // Create a new window that will be shared by ALL tests in this spec. + if (!testWindow) { + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { + testWindow = w; + + // Load module instances from brackets.test + CommandManager = testWindow.brackets.test.CommandManager; + Commands = testWindow.brackets.test.Commands; + EditorManager = testWindow.brackets.test.EditorManager; + DocumentManager = testWindow.brackets.test.DocumentManager; + FileViewController = testWindow.brackets.test.FileViewController; + + SpecRunnerUtils.loadProjectInTestWindow(testPath); + }); + } }); afterEach(function () { - SpecRunnerUtils.closeTestWindow(); - editor = null; + runs(function () { + var promise = CommandManager.execute(Commands.FILE_CLOSE_ALL); + waitsForDone(promise, "Close all open files in working set"); + + var $dlg = testWindow.$(".modal.instance"); + if ($dlg.length) { + SpecRunnerUtils.clickDialogButton("dontsave"); + } + }); }); - function checkLineWrapping(firstPos, secondPos, shouldWrap) { + function checkLineWrapping(editor, firstPos, secondPos, shouldWrap) { runs(function () { var firstLineBottom, nextLineBottom; @@ -95,7 +104,7 @@ define(function (require, exports, module) { }); } - function checkActiveLine(line, shouldShow) { + function checkActiveLine(editor, line, shouldShow) { runs(function () { var lineInfo; @@ -111,7 +120,7 @@ define(function (require, exports, module) { }); } - function checkLineNumbers(shouldShow) { + function checkLineNumbers(editor, shouldShow) { runs(function () { var gutterElement, $lineNumbers; @@ -127,7 +136,7 @@ define(function (require, exports, module) { }); } - function checkCloseBraces(startSel, endSel, keyCode, expectedText) { + function checkCloseBraces(editor, startSel, endSel, keyCode, expectedText) { runs(function () { var input, line; @@ -154,10 +163,6 @@ define(function (require, exports, module) { var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath}); waitsForDone(promise, "Open into working set"); }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - }); } function openAnotherEditor(fullpath) { @@ -166,10 +171,6 @@ define(function (require, exports, module) { waitsForDone(FileViewController.openAndSelectDocument(fullpath, FileViewController.PROJECT_MANAGER), "FILE_OPEN on file timeout", 1000); }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor(); - }); } function openInlineEditor(toggleEditorAt) { @@ -181,10 +182,6 @@ define(function (require, exports, module) { var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), toggleEditorAt); waitsForDone(promise, "Open inline editor"); }); - - runs(function () { - editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; - }); } function toggleOption(commandID, text) { @@ -199,34 +196,45 @@ define(function (require, exports, module) { it("should wrap long lines in main editor by default", function () { openEditor(HTML_FILE); - // Use two cursor positions to detect line wrapping. First position at - // the beginning of a long line and the second position to be - // somewhere on the long line that will be part of an extra line - // created by word-wrap and get its bottom coordinate. - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, true); + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + + // Use two cursor positions to detect line wrapping. First position at + // the beginning of a long line and the second position to be + // somewhere on the long line that will be part of an extra line + // created by word-wrap and get its bottom coordinate. + checkLineWrapping(editor, {line: 8, ch: 0}, {line: 8, ch: 210}, true); + }); }); it("should also wrap long lines in inline editor by default", function () { openInlineEditor(); - checkLineWrapping({line: 0, ch: 0}, {line: 0, ch: 160}, true); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkLineWrapping(editor, {line: 0, ch: 0}, {line: 0, ch: 160}, true); + }); }); it("should NOT wrap the long lines after turning off word-wrap", function () { // Turn off word-wrap toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); - openEditor(CSS_FILE); - checkLineWrapping({line: 0, ch: 1}, {line: 0, ch: 180}, false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkLineWrapping(editor, {line: 0, ch: 1}, {line: 0, ch: 180}, false); + }); }); it("should NOT wrap the long lines in another document when word-wrap off", function () { openEditor(CSS_FILE); - - // Turn off word-wrap - toggleOption(Commands.TOGGLE_WORD_WRAP, "Toggle word-wrap"); - openAnotherEditor(HTML_FILE); - checkLineWrapping({line: 8, ch: 0}, {line: 8, ch: 210}, false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkLineWrapping(editor, {line: 8, ch: 0}, {line: 8, ch: 210}, false); + }); }); }); @@ -234,30 +242,41 @@ define(function (require, exports, module) { describe("Toggle Active Line", function () { it("should NOT show active line in main editor by default", function () { openEditor(HTML_FILE); - checkActiveLine(5, false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkActiveLine(editor, 5, false); + }); }); it("should NOT show active line in inline editor by default", function () { openInlineEditor(); - checkActiveLine(0, false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkActiveLine(editor, 0, false); + }); }); it("should style active line after turning it on", function () { // Turn on show active line toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); - openEditor(CSS_FILE); - checkActiveLine(0, true); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkActiveLine(editor, 0, true); + }); }); it("should style the active line when opening another document with show active line on", function () { openEditor(CSS_FILE); - - // Turn on show active line - toggleOption(Commands.TOGGLE_ACTIVE_LINE, "Toggle active line"); - openAnotherEditor(HTML_FILE); - checkActiveLine(3, true); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkActiveLine(editor, 3, true); + }); }); }); @@ -265,38 +284,50 @@ define(function (require, exports, module) { describe("Toggle Line Numbers", function () { it("should show line numbers in main editor by default", function () { openEditor(HTML_FILE); - checkLineNumbers(true); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkLineNumbers(editor, true); + }); }); it("should also show line numbers in inline editor by default", function () { openInlineEditor(); - checkLineNumbers(true); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkLineNumbers(editor, true); + }); }); it("should NOT show line numbers in main editor after turning it off", function () { // Turn off show line numbers toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); - openEditor(CSS_FILE); - checkLineNumbers(false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkLineNumbers(editor, false); + }); }); it("should NOT show line numbers in inline editor after turning it off", function () { - // Turn off show line numbers - toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); - openInlineEditor(); - checkLineNumbers(false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkLineNumbers(editor, false); + }); }); it("should NOT show line numbers when opening another document with show line numbers off", function () { openEditor(CSS_FILE); - - // Turn off show line numbers - toggleOption(Commands.TOGGLE_LINE_NUMBERS, "Toggle line numbers"); - openAnotherEditor(HTML_FILE); - checkLineNumbers(false); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkLineNumbers(editor, false); + }); }); }); @@ -304,92 +335,116 @@ define(function (require, exports, module) { describe("Toggle Auto Close Braces", function () { it("should NOT auto close braces in main editor by default", function () { openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); + }); }); it("should NOT auto close braces in inline editor by default", function () { openInlineEditor({line: 9, ch: 11}); - checkCloseBraces({line: 1, ch: 15}, null, OPEN_BRACKET, ".shortLineClass { color: red; }"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkCloseBraces(editor, {line: 1, ch: 15}, null, OPEN_BRACKET, ".shortLineClass { color: red; }"); + }); }); it("should auto close braces in the main editor after turning it on", function () { // Turn on auto close braces toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); + }); }); it("should auto close braces in inline editor after turning it on", function () { - // Turn on auto close braces - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openInlineEditor({line: 9, ch: 11}); - checkCloseBraces({line: 1, ch: 32}, null, OPEN_BRACKET, ".shortLineClass { color: red; }[]"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor().getInlineWidgets()[0].editors[0]; + checkCloseBraces(editor, {line: 1, ch: 32}, null, OPEN_BRACKET, ".shortLineClass { color: red; }[]"); + }); }); it("should auto close braces when opening another document with auto close braces on", function () { openEditor(CSS_FILE); - - // Turn on auto close braces - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openAnotherEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 35}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";[]"); + }); }); it("should only auto close braces before spaces, closing braces or end of lines", function () { - // Turn on auto close braces - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close brackets"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 0}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); - checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); - checkCloseBraces({line: 0, ch: 16}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";"); - checkCloseBraces({line: 0, ch: 39}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";[]"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 0}, null, OPEN_BRACKET, "var myContent = \"This is awesome!\";"); + checkCloseBraces(editor, {line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); + checkCloseBraces(editor, {line: 0, ch: 16}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";"); + checkCloseBraces(editor, {line: 0, ch: 39}, null, OPEN_BRACKET, "var myContent =[[]] \"This is awesome!\";[]"); + }); }); it("should overwrite a close brace when writing a close brace before the same close brace", function () { - // Turn on auto close braces - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); - checkCloseBraces({line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";"); runs(function () { - expect(editor.getCursorPos()).toEqual({line: 0, ch: 17}); + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); + checkCloseBraces(editor, {line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";"); + + runs(function () { + expect(editor.getCursorPos()).toEqual({line: 0, ch: 17}); + }); }); }); it("should wrap a selection between braces", function () { - // Turn on auto close braces - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];"); runs(function () { - expect(editor.getSelection()).toEqual({start: {line: 0, ch: 16}, end: {line: 0, ch: 36}}); + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];"); + + runs(function () { + expect(editor.getSelection()).toEqual({start: {line: 0, ch: 16}, end: {line: 0, ch: 36}}); + }); }); }); it("should delete both open and close braces when both are together and backspacing", function () { - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); - checkCloseBraces({line: 0, ch: 16}, null, BACKSPACE, "var myContent = \"This is awesome!\";"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 15}, null, OPEN_BRACKET, "var myContent =[] \"This is awesome!\";"); + checkCloseBraces(editor, {line: 0, ch: 16}, null, BACKSPACE, "var myContent = \"This is awesome!\";"); + }); }); it("should NOT auto close single quotes inside comments", function () { - // Turn on auto close brackets - toggleOption(Commands.TOGGLE_CLOSE_BRACKETS, "Toggle auto close braces"); - openEditor(JS_FILE); - checkCloseBraces({line: 0, ch: 15}, null, SINGLE_QUOTE, "var myContent ='' \"This is awesome!\";"); - checkCloseBraces({line: 1, ch: 7}, null, SINGLE_QUOTE, "// Yes, it is!"); + + runs(function () { + var editor = EditorManager.getCurrentFullEditor(); + checkCloseBraces(editor, {line: 0, ch: 15}, null, SINGLE_QUOTE, "var myContent ='' \"This is awesome!\";"); + checkCloseBraces(editor, {line: 1, ch: 7}, null, SINGLE_QUOTE, "// Yes, it is!"); + }); + + // This must be in the last spec in the suite. + runs(function () { + this.after(function () { + SpecRunnerUtils.closeTestWindow(); + }); + }); }); }); });