Add a mock-based test for Editor.prototype.split and ensure it doesn't raise exceptions when not in a pane

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-13 11:40:29 -06:00
parent 54a15856bb
commit 1b2b1a324d
2 changed files with 27 additions and 4 deletions

View File

@@ -2144,3 +2144,26 @@ describe "Editor", ->
expect(editor.buffer.path).toBe "0"
editor.loadPreviousEditSession()
expect(editor.buffer.path).toBe "2"
describe "split methods", ->
describe "when inside a pane", ->
fakePane = null
beforeEach ->
fakePane = { splitUp: jasmine.createSpy('splitUp') }
spyOn(editor, 'pane').andReturn(fakePane)
it "calls the corresponding split method on the containing pane with a copy of the editor", ->
editor.splitUp()
expect(fakePane.splitUp).toHaveBeenCalled()
[editorCopy] = fakePane.splitUp.argsForCall[0]
expect(editorCopy.serialize()).toEqual editor.serialize()
expect(editorCopy).not.toBe 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()

View File

@@ -494,16 +494,16 @@ class Editor extends View
@setCursorBufferPosition(fold.start)
splitLeft: ->
@pane().splitLeft(@copy())
@pane()?.splitLeft(@copy())
splitRight: ->
@pane().splitRight(@copy())
@pane()?.splitRight(@copy())
splitUp: ->
@pane().splitUp(@copy())
@pane()?.splitUp(@copy())
splitDown: ->
@pane().splitDown(@copy())
@pane()?.splitDown(@copy())
pane: ->
@parent('.pane').view()