mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Specs cleanup buffers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
Project = require 'project'
|
||||
Buffer = require 'buffer'
|
||||
EditSession = require 'edit-session'
|
||||
|
||||
@@ -11,6 +12,7 @@ describe "EditSession", ->
|
||||
tabText: ' '
|
||||
autoIndent: false
|
||||
softWrap: false
|
||||
project: new Project()
|
||||
|
||||
lineLengths = buffer.getLines().map (line) -> line.length
|
||||
|
||||
@@ -1329,12 +1331,6 @@ describe "EditSession", ->
|
||||
editSession.foldAll()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual([5,5])
|
||||
|
||||
describe ".destroy()", ->
|
||||
it "triggers `destroy` event", ->
|
||||
spyOn(editSession, 'trigger')
|
||||
editSession.destroy()
|
||||
expect(editSession.trigger).toHaveBeenCalledWith('destroy')
|
||||
|
||||
describe ".clipBufferPosition(bufferPosition)", ->
|
||||
it "clips the given position to a valid position", ->
|
||||
expect(editSession.clipBufferPosition([-1, -1])).toEqual [0,0]
|
||||
|
||||
@@ -74,7 +74,6 @@ describe "Editor", ->
|
||||
newEditor.attachToDom()
|
||||
expect(newEditor.scrollTop()).toBe editor.scrollTop()
|
||||
expect(newEditor.scrollView.scrollLeft()).toBe 44
|
||||
newEditor.remove()
|
||||
|
||||
describe "when the editor is attached to the dom", ->
|
||||
it "calculates line height and char width and updates the pixel position of the cursor", ->
|
||||
@@ -126,7 +125,7 @@ describe "Editor", ->
|
||||
describe ".remove()", ->
|
||||
it "removes subscriptions from all edit session buffers", ->
|
||||
previousEditSession = editor.activeEditSession
|
||||
otherEditSession = rootView.project.open('sample.txt')
|
||||
otherEditSession = rootView.project.open(rootView.project.resolve('sample.txt'))
|
||||
expect(previousEditSession.buffer.subscriptionCount()).toBeGreaterThan 1
|
||||
|
||||
editor.edit(otherEditSession)
|
||||
@@ -141,7 +140,7 @@ describe "Editor", ->
|
||||
editor.edit(rootView.project.open())
|
||||
editSession = editor.activeEditSession
|
||||
spyOn(editSession, 'destroy').andCallThrough()
|
||||
spyOn(editor, "remove")
|
||||
spyOn(editor, "remove").andCallThrough()
|
||||
editor.trigger "close"
|
||||
expect(editSession.destroy).toHaveBeenCalled()
|
||||
expect(editor.remove).not.toHaveBeenCalled()
|
||||
@@ -151,20 +150,19 @@ describe "Editor", ->
|
||||
editSession = editor.activeEditSession
|
||||
expect(editor.mini).toBeFalsy()
|
||||
expect(editor.editSessions.length).toBe 1
|
||||
spyOn(editor, 'remove')
|
||||
spyOn(editor, 'remove').andCallThrough()
|
||||
editor.trigger 'close'
|
||||
spyOn(editSession, 'destroy').andCallThrough()
|
||||
expect(editor.remove).toHaveBeenCalled()
|
||||
|
||||
editor.remove()
|
||||
editor = new Editor(mini: true)
|
||||
spyOn(editor, 'remove')
|
||||
editor.trigger 'close'
|
||||
expect(editor.remove).not.toHaveBeenCalled()
|
||||
miniEditor = new Editor(mini: true)
|
||||
spyOn(miniEditor, 'remove').andCallThrough()
|
||||
miniEditor.trigger 'close'
|
||||
expect(miniEditor.remove).not.toHaveBeenCalled()
|
||||
|
||||
describe "when buffer is modified", ->
|
||||
it "triggers alert and does not close session", ->
|
||||
spyOn(editor, 'remove')
|
||||
spyOn(editor, 'remove').andCallThrough()
|
||||
spyOn($native, 'alert')
|
||||
editor.insertText("I AM CHANGED!")
|
||||
editor.trigger "close"
|
||||
@@ -279,12 +277,13 @@ describe "Editor", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView.remove()
|
||||
|
||||
tempFilePath = '/tmp/atom-temp.txt'
|
||||
fs.write(tempFilePath, "")
|
||||
rootView = new RootView(tempFilePath)
|
||||
editor = rootView.activeEditor()
|
||||
project = rootView.project
|
||||
|
||||
editor.edit(rootView.project.open(tempFilePath))
|
||||
expect(editor.buffer.getPath()).toBe tempFilePath
|
||||
|
||||
afterEach ->
|
||||
@@ -316,7 +315,6 @@ describe "Editor", ->
|
||||
it "saves the buffer to the chosen path", ->
|
||||
selectedFilePath = '/tmp/temp.txt'
|
||||
|
||||
console.log 'about to save'
|
||||
editor.save()
|
||||
|
||||
expect(fs.exists(selectedFilePath)).toBeTruthy()
|
||||
@@ -392,10 +390,10 @@ describe "Editor", ->
|
||||
|
||||
describe "when not inside a pane", ->
|
||||
it "does not split the editor, but doesn't throw an exception", ->
|
||||
editor.splitUp()
|
||||
editor.splitDown()
|
||||
editor.splitLeft()
|
||||
editor.splitRight()
|
||||
editor.splitUp().remove()
|
||||
editor.splitDown().remove()
|
||||
editor.splitLeft().remove()
|
||||
editor.splitRight().remove()
|
||||
|
||||
describe "editor-open event", ->
|
||||
it 'only triggers an editor-open event when it is first added to the DOM', ->
|
||||
@@ -1079,7 +1077,6 @@ describe "Editor", ->
|
||||
|
||||
otherEditor.simulateDomAttachment()
|
||||
expect(otherEditor.setSoftWrapColumn).toHaveBeenCalled()
|
||||
otherEditor.remove()
|
||||
|
||||
describe "when some lines at the end of the buffer are not visible on screen", ->
|
||||
beforeEach ->
|
||||
|
||||
@@ -14,6 +14,9 @@ describe "LineMap", ->
|
||||
map = new LineMap
|
||||
[line0, line1, line2, line3, line4] = tokenizedBuffer.linesForScreenRows(0, 4)
|
||||
|
||||
afterEach ->
|
||||
tokenizedBuffer.buffer.destroy()
|
||||
|
||||
describe ".insertAtBufferRow(row, lineFragments)", ->
|
||||
it "inserts the given line fragments before the specified buffer row", ->
|
||||
map.insertAtBufferRow(0, [line2, line3])
|
||||
|
||||
@@ -6,6 +6,9 @@ describe "Project", ->
|
||||
beforeEach ->
|
||||
project = new Project(require.resolve('fixtures/dir'))
|
||||
|
||||
afterEach ->
|
||||
project.destroy()
|
||||
|
||||
describe "when editSession is destroyed", ->
|
||||
it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", ->
|
||||
editSession = project.open("a")
|
||||
|
||||
@@ -391,6 +391,7 @@ describe "RootView", ->
|
||||
newRootView = RootView.deserialize(rootView.serialize())
|
||||
newRootView.activateExtension(extension)
|
||||
expect(extension.activate).toHaveBeenCalledWith(newRootView, "it worked")
|
||||
newRootView.remove()
|
||||
|
||||
it "throws an exception if the extension has no 'name' property", ->
|
||||
expect(-> rootView.activateExtension({ activate: -> })).toThrow()
|
||||
@@ -528,13 +529,13 @@ describe "RootView", ->
|
||||
it "opens an empty buffer in a new editor", ->
|
||||
rootView.open()
|
||||
expect(rootView.activeEditor()).toBeDefined()
|
||||
expect(rootView.activeEditor().buffer.path).toBeUndefined()
|
||||
expect(rootView.activeEditor().buffer.getPath()).toBeUndefined()
|
||||
|
||||
describe "when called with a path", ->
|
||||
it "opens a buffer with the given path in a new editor", ->
|
||||
rootView.open('b')
|
||||
expect(rootView.activeEditor()).toBeDefined()
|
||||
expect(rootView.activeEditor().buffer.path).toBe require.resolve('fixtures/dir/b')
|
||||
expect(rootView.activeEditor().buffer.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
|
||||
describe "when there is an active editor", ->
|
||||
beforeEach ->
|
||||
@@ -543,7 +544,7 @@ describe "RootView", ->
|
||||
describe "when called with no path", ->
|
||||
it "opens an empty buffer in the active editor", ->
|
||||
rootView.open()
|
||||
expect(rootView.activeEditor().buffer.path).toBeUndefined()
|
||||
expect(rootView.activeEditor().buffer.getPath()).toBeUndefined()
|
||||
|
||||
describe "when called with a path", ->
|
||||
[editor1, editor2] = []
|
||||
@@ -562,7 +563,7 @@ describe "RootView", ->
|
||||
|
||||
describe "when the active editor has an edit session for the given path", ->
|
||||
it "re-activates the existing edit session", ->
|
||||
expect(activeEditor.buffer.path).toBe require.resolve('fixtures/dir/a')
|
||||
expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
previousEditSession = activeEditor.activeEditSession
|
||||
|
||||
rootView.open('b')
|
||||
@@ -580,7 +581,7 @@ describe "RootView", ->
|
||||
describe "when the active editor has an edit session for the given path", ->
|
||||
it "re-activates the existing edit session regardless of whether any other editor also has an edit session for the path", ->
|
||||
activeEditor = rootView.activeEditor()
|
||||
expect(activeEditor.buffer.path).toBe require.resolve('fixtures/dir/a')
|
||||
expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a')
|
||||
previousEditSession = activeEditor.activeEditSession
|
||||
|
||||
rootView.open('b')
|
||||
@@ -595,11 +596,11 @@ describe "RootView", ->
|
||||
expect(rootView.activeEditor()).toBe editor1
|
||||
rootView.open('b', allowActiveEditorChange: true)
|
||||
expect(rootView.activeEditor()).toBe editor2
|
||||
expect(editor2.buffer.path).toBe require.resolve('fixtures/dir/b')
|
||||
expect(editor2.buffer.getPath()).toBe require.resolve('fixtures/dir/b')
|
||||
|
||||
describe "when no other editor has an edit session for the path either", ->
|
||||
it "creates a new edit session for the path on the current active editor", ->
|
||||
path = require.resolve('fixtures/sample.js')
|
||||
rootView.open(path, allowActiveEditorChange: true)
|
||||
expect(rootView.activeEditor()).toBe editor1
|
||||
expect(editor1.buffer.path).toBe path
|
||||
expect(editor1.buffer.getPath()).toBe path
|
||||
|
||||
@@ -11,6 +11,9 @@ describe "ScreenLine", ->
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer, tabText)
|
||||
screenLine = tokenizedBuffer.lineForScreenRow(3)
|
||||
|
||||
afterEach ->
|
||||
buffer.destroy()
|
||||
|
||||
describe ".splitAt(column)", ->
|
||||
it "breaks the line fragment into two fragments", ->
|
||||
[left, right] = screenLine.splitAt(31)
|
||||
|
||||
@@ -3,13 +3,16 @@ EditSession = require 'edit-session'
|
||||
Range = require 'range'
|
||||
|
||||
describe "Selection", ->
|
||||
[buffer, selection] = []
|
||||
[buffer, editSession, selection] = []
|
||||
|
||||
beforeEach ->
|
||||
buffer = new Buffer(require.resolve('fixtures/sample.js'))
|
||||
editSession = new EditSession(buffer: buffer, tabText: ' ')
|
||||
selection = editSession.getSelection()
|
||||
|
||||
afterEach ->
|
||||
buffer.destroy()
|
||||
|
||||
describe ".deleteSelectedText()", ->
|
||||
describe "when nothing is selected", ->
|
||||
it "deletes nothing", ->
|
||||
|
||||
@@ -12,6 +12,9 @@ describe "StatusBar", ->
|
||||
editor = rootView.activeEditor()
|
||||
statusBar = rootView.find('.status-bar').view()
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "@initialize", ->
|
||||
it "appends a status bar to all existing and new editors", ->
|
||||
expect(rootView.panes.find('.pane').length).toBe 1
|
||||
@@ -27,6 +30,7 @@ describe "StatusBar", ->
|
||||
|
||||
describe "when associated with an unsaved buffer", ->
|
||||
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
|
||||
rootView.remove()
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
rootView.simulateDomAttachment()
|
||||
|
||||
@@ -9,6 +9,9 @@ describe "TokenizedBuffer", ->
|
||||
buffer = new Buffer(require.resolve('fixtures/sample.js'))
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer, ' ')
|
||||
|
||||
afterEach ->
|
||||
buffer.destroy()
|
||||
|
||||
describe ".findClosingBracket(startBufferPosition)", ->
|
||||
it "returns the position of the matching bracket, skipping any nested brackets", ->
|
||||
expect(tokenizedBuffer.findClosingBracket([1, 29])).toEqual [9, 2]
|
||||
@@ -34,6 +37,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe "coffeescript", ->
|
||||
it "comments/uncomments lines in the given range", ->
|
||||
buffer.destroy()
|
||||
buffer = new Buffer(require.resolve('fixtures/coffee.coffee'))
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer, ' ')
|
||||
|
||||
@@ -52,6 +56,7 @@ describe "TokenizedBuffer", ->
|
||||
describe "fold suggestion", ->
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
buffer.destroy()
|
||||
buffer = new Buffer(require.resolve 'fixtures/sample.js')
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer)
|
||||
|
||||
@@ -71,6 +76,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
describe "coffeescript", ->
|
||||
beforeEach ->
|
||||
buffer.destroy()
|
||||
buffer = new Buffer(require.resolve 'fixtures/coffee.coffee')
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer)
|
||||
|
||||
@@ -223,6 +229,7 @@ describe "TokenizedBuffer", ->
|
||||
|
||||
beforeEach ->
|
||||
tabText = ' '
|
||||
buffer.destroy()
|
||||
buffer = new Buffer(require.resolve('fixtures/sample-with-tabs.coffee'))
|
||||
tokenizedBuffer = new TokenizedBuffer(buffer, tabText)
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ describe "UndoManager", ->
|
||||
buffer = new Buffer(require.resolve('fixtures/sample.js'))
|
||||
undoManager = new UndoManager(buffer)
|
||||
|
||||
afterEach ->
|
||||
buffer.destroy()
|
||||
|
||||
describe ".undo()", ->
|
||||
it "undoes the last change", ->
|
||||
buffer.change(new Range([0, 5], [0, 9]), '')
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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]])
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"]
|
||||
@@ -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)", ->
|
||||
|
||||
@@ -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', """
|
||||
|
||||
@@ -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", ->
|
||||
|
||||
@@ -5,25 +5,27 @@ Keymap = require 'keymap'
|
||||
Point = require 'point'
|
||||
Project = require 'project'
|
||||
Directory = require 'directory'
|
||||
File = require 'file'
|
||||
RootView = require 'root-view'
|
||||
fs = require 'fs'
|
||||
require 'window'
|
||||
$native.showDevTools()
|
||||
|
||||
requireStylesheet "jasmine.css"
|
||||
|
||||
defaultTitle = document.title
|
||||
directoriesWithSubscriptions = null
|
||||
pathsWithSubscriptions = null
|
||||
|
||||
beforeEach ->
|
||||
window.fixturesProject = new Project(require.resolve('fixtures'))
|
||||
window.resetTimeouts()
|
||||
directoriesWithSubscriptions = []
|
||||
pathsWithSubscriptions = []
|
||||
|
||||
afterEach ->
|
||||
delete window.rootView if window.rootView
|
||||
$('#jasmine-content').empty()
|
||||
document.title = defaultTitle
|
||||
ensureNoDirectorySubscriptions()
|
||||
ensureNoPathSubscriptions()
|
||||
|
||||
window.keymap.bindKeys '*', 'meta-w': 'close'
|
||||
$(document).on 'close', -> window.close()
|
||||
@@ -31,19 +33,20 @@ $(document).on 'close', -> window.close()
|
||||
# Don't load user configuration in specs, because it's variable
|
||||
RootView.prototype.loadUserConfiguration = ->
|
||||
|
||||
Directory.prototype.originalOn = Directory.prototype.on
|
||||
Directory.prototype.on = (args...) ->
|
||||
directoriesWithSubscriptions.push(this) if @subscriptionCount() == 0
|
||||
@originalOn(args...)
|
||||
for klass in [Directory, File]
|
||||
klass.prototype.originalOn = klass.prototype.on
|
||||
klass.prototype.on = (args...) ->
|
||||
pathsWithSubscriptions.push(this) if @subscriptionCount() == 0
|
||||
@originalOn(args...)
|
||||
|
||||
ensureNoDirectorySubscriptions = ->
|
||||
ensureNoPathSubscriptions = ->
|
||||
totalSubscriptionCount = 0
|
||||
for directory in directoriesWithSubscriptions
|
||||
totalSubscriptionCount += directory.subscriptionCount()
|
||||
console.log "Non-zero subscription count on", directory if directory.subscriptionCount() > 0
|
||||
for path in pathsWithSubscriptions
|
||||
totalSubscriptionCount += path.subscriptionCount()
|
||||
console.log "Non-zero subscription count on", path if path.subscriptionCount() > 0
|
||||
|
||||
if totalSubscriptionCount > 0
|
||||
throw new Error("Total directory subscription count was #{totalSubscriptionCount}, when it should have been 0.\nSee console for details.")
|
||||
throw new Error("Total path subscription count was #{totalSubscriptionCount}, when it should have been 0.\nSee console for details.")
|
||||
|
||||
# Use underscore's definition of equality for toEqual assertions
|
||||
jasmine.Env.prototype.equals_ = _.isEqual
|
||||
|
||||
@@ -398,7 +398,7 @@ class Editor extends View
|
||||
false
|
||||
|
||||
getOpenBufferPaths: ->
|
||||
editSession.buffer.path for editSession in @editSessions when editSession.buffer.path?
|
||||
editSession.buffer.getPath() for editSession in @editSessions when editSession.buffer.getPath()?
|
||||
|
||||
scrollTop: (scrollTop, options) ->
|
||||
return @cachedScrollTop or 0 unless scrollTop?
|
||||
|
||||
@@ -90,10 +90,15 @@ class Project
|
||||
softTabs: @getSoftTabs()
|
||||
softWrap: @getSoftWrap()
|
||||
|
||||
|
||||
@editSessions.push editSession
|
||||
@trigger 'new-edit-session', editSession
|
||||
editSession
|
||||
|
||||
destroy: ->
|
||||
for editSession in _.clone(@editSessions)
|
||||
@removeEditSession(editSession)
|
||||
|
||||
removeEditSession: (editSession) ->
|
||||
_.remove(@editSessions, editSession)
|
||||
@destroyBufferIfOrphaned(editSession.buffer)
|
||||
|
||||
@@ -183,6 +183,7 @@ class RootView extends View
|
||||
|
||||
remove: ->
|
||||
editor.remove() for editor in @editors()
|
||||
@project.destroy()
|
||||
super
|
||||
|
||||
setFontSize: (newFontSize) ->
|
||||
|
||||
Reference in New Issue
Block a user