Specs cleanup buffers

This commit is contained in:
Corey Johnson
2012-06-29 15:08:16 -07:00
parent 98393a653e
commit 801a91ec9b
21 changed files with 107 additions and 232 deletions

View File

@@ -14,6 +14,9 @@ describe "Autocomplete", ->
autocomplete = new Autocomplete(editor)
miniEditor = autocomplete.miniEditor
afterEach ->
editor.remove()
describe "@activate(rootView)", ->
it "activates autocomplete on all existing and future editors (but not on autocomplete's own mini editor)", ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
@@ -35,6 +38,9 @@ describe "Autocomplete", ->
expect(Autocomplete.prototype.initialize).not.toHaveBeenCalled()
leftEditor.remove()
rightEditor.remove()
describe 'autocomplete:attach event', ->
it "shows autocomplete view and focuses its mini-editor", ->
expect(editor.find('.autocomplete')).not.toExist()

View File

@@ -12,6 +12,9 @@ describe "CommandInterpreter", ->
editor = new Editor(editSession: editSession)
interpreter = new CommandInterpreter()
afterEach ->
editor.remove()
describe "addresses", ->
beforeEach ->
editor.addSelectionForBufferRange([[7,0], [7,11]])

View File

@@ -11,6 +11,9 @@ describe "CommandPanel", ->
editor = rootView.activeEditor()
commandPanel = rootView.activateExtension(CommandPanel)
afterEach ->
rootView.remove()
describe "serialization", ->
it "preserves the command panel's mini editor text and visibility across reloads", ->
rootView.trigger 'command-panel:toggle'
@@ -21,6 +24,8 @@ describe "CommandPanel", ->
expect(newRootView.find('.command-panel')).toExist()
expect(commandPanel.miniEditor.getText()).toBe 'abc'
newRootView.remove()
describe "when toggle-command-panel is triggered on the root view", ->
it "toggles the command panel", ->
rootView.attachToDom()

View File

@@ -1,177 +0,0 @@
RootView = require 'root-view'
FileFinder = require 'file-finder'
$ = require 'jquery'
{$$} = require 'space-pen'
describe 'FileFinder', ->
[rootView, finder] = []
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.enableKeymap()
rootView.activateExtension(FileFinder)
finder = FileFinder.instance
describe "when the file-finder:toggle event is triggered on the root view", ->
describe "when there is a project", ->
it "shows or hides the FileFinder, returning focus to the active editor when hiding it", ->
rootView.attachToDom()
expect(rootView.find('.file-finder')).not.toExist()
rootView.find('.editor').trigger 'split-right'
[editor1, editor2] = rootView.find('.editor').map -> $(this).view()
rootView.trigger 'file-finder:toggle'
expect(rootView.find('.file-finder')).toExist()
expect(rootView.find('.file-finder input:focus')).toExist()
finder.miniEditor.insertText('this should not show up next time we toggle')
rootView.trigger 'file-finder:toggle'
expect(editor1.isFocused).toBeFalsy()
expect(editor2.isFocused).toBeTruthy()
expect(rootView.find('.file-finder')).not.toExist()
rootView.trigger 'file-finder:toggle'
expect(finder.miniEditor.getText()).toBe ''
it "shows all relative file paths for the current project and selects the first", ->
finder.maxResults = 1000
rootView.trigger 'file-finder:toggle'
rootView.project.getFilePaths().done (paths) ->
expect(finder.pathList.children('li').length).toBe paths.length, finder.maxResults
for path in paths
expect(finder.pathList.find("li:contains(#{path})")).toExist()
expect(finder.pathList.children().first()).toHaveClass 'selected'
describe "when root view's project has no path", ->
beforeEach ->
rootView.project.setPath(null)
it "does not open the FileFinder", ->
expect(rootView.find('.file-finder')).not.toExist()
rootView.trigger 'file-finder:toggle'
expect(rootView.find('.file-finder')).not.toExist()
describe "file-finder:cancel event", ->
it "hides the finder", ->
rootView.trigger 'file-finder:toggle'
expect(finder.hasParent()).toBeTruthy()
finder.trigger 'file-finder:cancel'
expect(finder.hasParent()).toBeFalsy()
it "focuses previously focused element", ->
rootView.attachToDom()
activeEditor = rootView.activeEditor()
activeEditor.focus()
rootView.trigger 'file-finder:toggle'
expect(activeEditor.isFocused).toBeFalsy()
expect(finder.miniEditor.isFocused).toBeTruthy()
finder.trigger 'file-finder:cancel'
expect(activeEditor.isFocused).toBeTruthy()
expect(finder.miniEditor.isFocused).toBeFalsy()
describe "when the file finder loses focus", ->
it "detaches itself", ->
rootView.attachToDom()
rootView.trigger 'file-finder:toggle'
expect(finder.hasParent()).toBeTruthy()
rootView.focus()
expect(finder.hasParent()).toBeFalsy()
describe "when characters are typed into the input element", ->
it "displays matching paths in the ol element and selects the first", ->
rootView.trigger 'file-finder:toggle'
listLengthBefore = finder.pathList.children().length
finder.miniEditor.insertText('samp')
expect(finder.pathList.children().length).toBeLessThan(listLengthBefore)
expect(finder.pathList.find('li:first')).toHaveClass 'selected'
expect(finder.pathList.find('li.selected').length).toBe 1
# we should clear the list before re-populating it
finder.miniEditor.insertText('txt')
expect(finder.pathList.children().length).toBe 1
expect(finder.pathList.find('li:first')).toHaveClass 'selected'
expect(finder.pathList.find('li:first')).toHaveText 'sample.txt'
describe "move-down / move-up events", ->
beforeEach ->
rootView.trigger 'file-finder:toggle'
it "selects the next / previous path in the list", ->
expect(finder.find('li:eq(0)')).toHaveClass "selected"
expect(finder.find('li:eq(2)')).not.toHaveClass "selected"
finder.miniEditor.trigger keydownEvent('down')
finder.miniEditor.trigger keydownEvent('down')
expect(finder.find('li:eq(0)')).not.toHaveClass "selected"
expect(finder.find('li:eq(2)')).toHaveClass "selected"
finder.miniEditor.trigger keydownEvent('up')
expect(finder.find('li:eq(0)')).not.toHaveClass "selected"
expect(finder.find('li:eq(1)')).toHaveClass "selected"
expect(finder.find('li:eq(2)')).not.toHaveClass "selected"
it "does not fall off the end or begining of the list", ->
expect(finder.find('li:first')).toHaveClass "selected"
finder.miniEditor.trigger keydownEvent('up')
expect(finder.find('li:first')).toHaveClass "selected"
for i in [1..finder.pathList.children().length+2]
finder.miniEditor.trigger keydownEvent('down')
expect(finder.find('li:last')).toHaveClass "selected"
describe "select-file events", ->
[editor1, editor2] = []
beforeEach ->
rootView.attachToDom()
editor1 = rootView.activeEditor()
editor2 = editor1.splitRight()
expect(rootView.activeEditor()).toBe editor2
rootView.trigger 'file-finder:toggle'
describe "when there is a path selected", ->
it "opens the file associated with that path in the editor", ->
finder.trigger 'move-down'
selectedLi = finder.find('li:eq(1)')
expectedPath = rootView.project.resolve(selectedLi.text())
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).not.toBe expectedPath
finder.trigger 'file-finder:select-file'
expect(finder.hasParent()).toBeFalsy()
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).toBe expectedPath
expect(editor2.isFocused).toBeTruthy()
describe "when there is no path selected", ->
it "does nothing", ->
finder.miniEditor.insertText('this should match nothing, because no one wants to drink battery acid')
finder.trigger 'file-finder:select-file'
expect(finder.hasParent()).toBeTruthy()
describe ".findMatches(queryString)", ->
beforeEach ->
rootView.trigger 'file-finder:toggle'
it "returns up to finder.maxResults paths if queryString is empty", ->
expect(finder.findMatches('').length).toBeLessThan finder.maxResults + 1
finder.maxResults = 5
expect(finder.findMatches('').length).toBeLessThan finder.maxResults + 1
it "returns paths sorted by score of match against the given query", ->
finder.paths = ["app.coffee", "atom/app.coffee"]
expect(finder.findMatches('app.co')).toEqual ["app.coffee", "atom/app.coffee"]
expect(finder.findMatches('atom/app.co')).toEqual ["atom/app.coffee"]

View File

@@ -12,6 +12,9 @@ describe 'FuzzyFinder', ->
rootView.activateExtension(FuzzyFinder)
finder = FuzzyFinder.instance
afterEach ->
rootView.remove()
describe "file-finder behavior", ->
describe "toggling", ->
describe "when the root view's project has a path", ->
@@ -68,14 +71,14 @@ describe 'FuzzyFinder', ->
selectedLi = finder.find('li:eq(1)')
expectedPath = rootView.project.resolve(selectedLi.text())
expect(editor1.buffer.path).not.toBe expectedPath
expect(editor2.buffer.path).not.toBe expectedPath
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).not.toBe expectedPath
finder.trigger 'fuzzy-finder:select-path'
expect(finder.hasParent()).toBeFalsy()
expect(editor1.buffer.path).not.toBe expectedPath
expect(editor2.buffer.path).toBe expectedPath
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).toBe expectedPath
expect(editor2.isFocused).toBeTruthy()
describe "when no paths are highlighted", ->
@@ -156,8 +159,8 @@ describe 'FuzzyFinder', ->
finder.trigger 'fuzzy-finder:select-path'
expect(finder.hasParent()).toBeFalsy()
expect(editor1.buffer.path).not.toBe expectedPath
expect(editor2.buffer.path).toBe expectedPath
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).toBe expectedPath
expect(editor2.isFocused).toBeTruthy()
describe "when the highlighted path is not open in the active editor, but instead is open on another editor", ->
@@ -176,8 +179,8 @@ describe 'FuzzyFinder', ->
finder.trigger 'fuzzy-finder:select-path'
expect(finder.hasParent()).toBeFalsy()
expect(editor1.buffer.path).not.toBe expectedPath
expect(editor2.buffer.path).toBe expectedPath
expect(editor1.buffer.getPath()).not.toBe expectedPath
expect(editor2.buffer.getPath()).toBe expectedPath
expect(editor2.isFocused).toBeTruthy()
describe "common behavior between file and buffer finder", ->
@@ -268,12 +271,12 @@ describe 'FuzzyFinder', ->
selectedLi = finder.find('li:eq(1)')
expectedPath = rootView.project.resolve(selectedLi.text())
expect(rootView.activeEditor().buffer.path).not.toBe expectedPath
expect(rootView.activeEditor().buffer.getPath()).not.toBe expectedPath
expect(rootView.activeEditor().isFocused).toBeFalsy()
selectedLi.mousedown()
expect(rootView.activeEditor().buffer.path).toBe expectedPath
expect(rootView.activeEditor().buffer.getPath()).toBe expectedPath
expect(rootView.activeEditor().isFocused).toBeTruthy()
describe ".findMatches(queryString)", ->

View File

@@ -15,6 +15,9 @@ describe "Snippets extension", ->
rootView.simulateDomAttachment()
rootView.enableKeymap()
afterEach ->
rootView.remove()
describe "when 'tab' is triggered on the editor", ->
beforeEach ->
Snippets.evalSnippets 'js', """

View File

@@ -23,6 +23,7 @@ describe "TreeView", ->
afterEach ->
treeView.deactivate()
rootView.remove()
describe ".initialize(project)", ->
it "renders the root of the project and its contents alphabetically with subdirectories first in a collapsed state", ->
@@ -85,9 +86,10 @@ describe "TreeView", ->
expect(newTreeView).toExist()
expect(newTreeView.selectedEntry()).toMatchSelector(".file:contains(sample.js)")
expect(newTreeView.find(".directory:contains(zed)")).toHaveClass("expanded")
newRootView.remove()
it "restores the focus state of the tree view", ->
treeView.attachToDom()
rootView.attachToDom()
treeView.focus()
expect(treeView).toMatchSelector ':focus'
@@ -98,6 +100,7 @@ describe "TreeView", ->
newTreeView = newRootView.find(".tree-view").view()
expect(newTreeView).toMatchSelector ':focus'
newRootView.remove()
describe "when tree-view:toggle is triggered on the root view", ->
it "shows/hides the tree view", ->