2012-08-28 02:36:36 +04:00
|
|
|
$ = require 'jquery'
|
2013-04-03 22:01:01 +04:00
|
|
|
fsUtils = require 'fs-utils'
|
2013-02-20 00:12:29 +04:00
|
|
|
Project = require 'project'
|
2012-08-28 02:36:36 +04:00
|
|
|
RootView = require 'root-view'
|
2013-03-12 21:38:05 +04:00
|
|
|
Buffer = require 'text-buffer'
|
2012-08-28 02:36:36 +04:00
|
|
|
Editor = require 'editor'
|
2013-02-28 03:54:06 +04:00
|
|
|
Pane = require 'pane'
|
2012-09-26 03:38:48 +04:00
|
|
|
{View, $$} = require 'space-pen'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "RootView", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
pathToOpen = null
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2013-02-20 04:18:25 +04:00
|
|
|
project.setPath(project.resolve('dir'))
|
2013-02-20 00:12:29 +04:00
|
|
|
pathToOpen = project.resolve('a')
|
2013-02-20 04:18:25 +04:00
|
|
|
window.rootView = new RootView
|
2012-08-28 02:36:36 +04:00
|
|
|
rootView.enableKeymap()
|
2013-02-20 04:18:25 +04:00
|
|
|
rootView.open(pathToOpen)
|
2012-08-28 02:36:36 +04:00
|
|
|
rootView.focus()
|
|
|
|
|
2013-03-07 04:05:26 +04:00
|
|
|
describe "@deserialize()", ->
|
2013-01-18 04:30:09 +04:00
|
|
|
viewState = null
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
describe "when the serialized RootView has an unsaved buffer", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
it "constructs the view with the same panes", ->
|
2013-03-07 04:05:26 +04:00
|
|
|
rootView.attachToDom()
|
2013-01-18 04:30:09 +04:00
|
|
|
rootView.open()
|
2013-03-07 04:05:26 +04:00
|
|
|
editor1 = rootView.getActiveView()
|
2013-01-18 04:30:09 +04:00
|
|
|
buffer = editor1.getBuffer()
|
|
|
|
editor1.splitRight()
|
|
|
|
viewState = rootView.serialize()
|
2013-03-26 01:37:11 +04:00
|
|
|
rootView.remove()
|
2013-03-07 04:05:26 +04:00
|
|
|
|
2013-03-07 23:09:39 +04:00
|
|
|
window.rootView = deserialize(viewState)
|
2013-03-07 04:05:26 +04:00
|
|
|
rootView.attachToDom()
|
2013-02-21 03:43:29 +04:00
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
expect(rootView.getEditors().length).toBe 2
|
2013-03-07 04:05:26 +04:00
|
|
|
expect(rootView.getActiveView().getText()).toBe buffer.getText()
|
|
|
|
expect(rootView.title).toBe "untitled - #{project.getPath()}"
|
2013-01-18 04:30:09 +04:00
|
|
|
|
|
|
|
describe "when the serialized RootView has a project", ->
|
|
|
|
describe "when there are open editors", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
it "constructs the view with the same panes", ->
|
2013-01-18 04:30:09 +04:00
|
|
|
rootView.attachToDom()
|
2013-03-07 04:05:26 +04:00
|
|
|
pane1 = rootView.getActivePane()
|
|
|
|
pane2 = pane1.splitRight()
|
|
|
|
pane3 = pane2.splitRight()
|
|
|
|
pane4 = pane2.splitDown()
|
2013-05-15 05:58:10 +04:00
|
|
|
pane2.showItem(project.open('b'))
|
|
|
|
pane3.showItem(project.open('../sample.js'))
|
2013-03-07 04:05:26 +04:00
|
|
|
pane3.activeItem.setCursorScreenPosition([2, 4])
|
2013-05-15 05:58:10 +04:00
|
|
|
pane4.showItem(project.open('../sample.txt'))
|
2013-03-07 04:05:26 +04:00
|
|
|
pane4.activeItem.setCursorScreenPosition([0, 2])
|
|
|
|
pane2.focus()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
viewState = rootView.serialize()
|
2013-03-26 01:37:11 +04:00
|
|
|
rootView.remove()
|
2013-03-07 23:09:39 +04:00
|
|
|
window.rootView = deserialize(viewState)
|
2013-01-18 04:30:09 +04:00
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
expect(rootView.getEditors().length).toBe 4
|
|
|
|
editor1 = rootView.panes.find('.row > .pane .editor:eq(0)').view()
|
|
|
|
editor3 = rootView.panes.find('.row > .pane .editor:eq(1)').view()
|
|
|
|
editor2 = rootView.panes.find('.row > .column > .pane .editor:eq(0)').view()
|
|
|
|
editor4 = rootView.panes.find('.row > .column > .pane .editor:eq(1)').view()
|
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
expect(editor1.getPath()).toBe project.resolve('a')
|
|
|
|
expect(editor2.getPath()).toBe project.resolve('b')
|
|
|
|
expect(editor3.getPath()).toBe project.resolve('../sample.js')
|
2013-01-18 04:30:09 +04:00
|
|
|
expect(editor3.getCursorScreenPosition()).toEqual [2, 4]
|
2013-02-20 04:18:25 +04:00
|
|
|
expect(editor4.getPath()).toBe project.resolve('../sample.txt')
|
2013-01-18 04:30:09 +04:00
|
|
|
expect(editor4.getCursorScreenPosition()).toEqual [0, 2]
|
|
|
|
|
|
|
|
# ensure adjust pane dimensions is called
|
|
|
|
expect(editor1.width()).toBeGreaterThan 0
|
|
|
|
expect(editor2.width()).toBeGreaterThan 0
|
|
|
|
expect(editor3.width()).toBeGreaterThan 0
|
|
|
|
expect(editor4.width()).toBeGreaterThan 0
|
|
|
|
|
|
|
|
# ensure correct editor is focused again
|
|
|
|
expect(editor2.isFocused).toBeTruthy()
|
|
|
|
expect(editor1.isFocused).toBeFalsy()
|
|
|
|
expect(editor3.isFocused).toBeFalsy()
|
|
|
|
expect(editor4.isFocused).toBeFalsy()
|
|
|
|
|
2013-04-03 22:01:01 +04:00
|
|
|
expect(rootView.title).toBe "#{fsUtils.base(editor2.getPath())} - #{project.getPath()}"
|
2013-01-18 04:30:09 +04:00
|
|
|
|
|
|
|
describe "where there are no open editors", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
it "constructs the view with no open editors", ->
|
2013-03-07 04:05:26 +04:00
|
|
|
rootView.getActivePane().remove()
|
2013-02-20 00:12:29 +04:00
|
|
|
expect(rootView.getEditors().length).toBe 0
|
2013-02-20 04:18:25 +04:00
|
|
|
|
2013-01-18 04:30:09 +04:00
|
|
|
viewState = rootView.serialize()
|
2013-03-26 01:37:11 +04:00
|
|
|
rootView.remove()
|
2013-03-07 23:09:39 +04:00
|
|
|
window.rootView = deserialize(viewState)
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-02-20 00:12:29 +04:00
|
|
|
rootView.attachToDom()
|
|
|
|
expect(rootView.getEditors().length).toBe 0
|
2013-01-11 04:24:36 +04:00
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe "focus", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
describe "when there is an active view", ->
|
|
|
|
it "hands off focus to the active view", ->
|
|
|
|
editor = rootView.getActiveView()
|
|
|
|
editor.isFocused = false
|
2012-09-26 01:11:07 +04:00
|
|
|
rootView.focus()
|
2013-02-22 05:32:03 +04:00
|
|
|
expect(editor.isFocused).toBeTruthy()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-02-22 05:32:03 +04:00
|
|
|
describe "when there is no active view", ->
|
2013-02-20 04:18:25 +04:00
|
|
|
beforeEach ->
|
2013-02-22 05:32:03 +04:00
|
|
|
rootView.getActivePane().remove()
|
|
|
|
expect(rootView.getActiveView()).toBeUndefined()
|
2013-02-20 04:18:25 +04:00
|
|
|
rootView.attachToDom()
|
2013-02-22 05:32:03 +04:00
|
|
|
expect(document.activeElement).toBe document.body
|
2013-02-20 04:18:25 +04:00
|
|
|
|
2012-09-26 03:38:48 +04:00
|
|
|
describe "when are visible focusable elements (with a -1 tabindex)", ->
|
|
|
|
it "passes focus to the first focusable element", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
focusable1 = $$ -> @div "One", id: 'one', tabindex: -1
|
|
|
|
focusable2 = $$ -> @div "Two", id: 'two', tabindex: -1
|
|
|
|
rootView.horizontal.append(focusable1, focusable2)
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-09-26 03:38:48 +04:00
|
|
|
|
2013-02-20 04:18:25 +04:00
|
|
|
rootView.focus()
|
2013-02-22 05:32:03 +04:00
|
|
|
expect(document.activeElement).toBe focusable1[0]
|
2012-09-26 00:22:06 +04:00
|
|
|
|
2012-09-26 01:11:07 +04:00
|
|
|
describe "when there are no visible focusable elements", ->
|
2013-02-09 02:56:55 +04:00
|
|
|
it "surrenders focus to the body", ->
|
2013-02-22 05:32:03 +04:00
|
|
|
focusable = $$ -> @div "One", id: 'one', tabindex: -1
|
|
|
|
rootView.horizontal.append(focusable)
|
|
|
|
focusable.hide()
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-09-26 00:22:06 +04:00
|
|
|
|
2013-02-22 05:32:03 +04:00
|
|
|
rootView.focus()
|
|
|
|
expect(document.activeElement).toBe document.body
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "keymap wiring", ->
|
|
|
|
commandHandler = null
|
|
|
|
beforeEach ->
|
|
|
|
commandHandler = jasmine.createSpy('commandHandler')
|
|
|
|
rootView.on('foo-command', commandHandler)
|
|
|
|
|
|
|
|
window.keymap.bindKeys('*', 'x': 'foo-command')
|
|
|
|
|
2013-02-22 05:22:55 +04:00
|
|
|
describe "when a keydown event is triggered on the RootView", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
it "triggers matching keybindings for that event", ->
|
|
|
|
event = keydownEvent 'x', target: rootView[0]
|
|
|
|
|
|
|
|
rootView.trigger(event)
|
|
|
|
expect(commandHandler).toHaveBeenCalled()
|
|
|
|
|
2013-03-07 02:12:02 +04:00
|
|
|
describe "window title", ->
|
2013-02-22 05:22:55 +04:00
|
|
|
describe "when the project has no path", ->
|
|
|
|
it "sets the title to 'untitled'", ->
|
|
|
|
project.setPath(undefined)
|
|
|
|
expect(rootView.title).toBe 'untitled'
|
|
|
|
|
|
|
|
describe "when the project has a path", ->
|
2013-02-26 03:26:50 +04:00
|
|
|
beforeEach ->
|
|
|
|
rootView.open('b')
|
2013-02-22 05:22:55 +04:00
|
|
|
|
|
|
|
describe "when there is an active pane item", ->
|
|
|
|
it "sets the title to the pane item's title plus the project path", ->
|
|
|
|
item = rootView.getActivePaneItem()
|
|
|
|
expect(rootView.title).toBe "#{item.getTitle()} - #{project.getPath()}"
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-03-07 02:12:02 +04:00
|
|
|
describe "when the title of the active pane item changes", ->
|
|
|
|
it "updates the window title based on the item's new title", ->
|
|
|
|
editSession = rootView.getActivePaneItem()
|
|
|
|
editSession.buffer.setPath('/tmp/hi')
|
|
|
|
expect(rootView.title).toBe "#{editSession.getTitle()} - #{project.getPath()}"
|
|
|
|
|
2013-02-26 03:26:50 +04:00
|
|
|
describe "when the active pane's item changes", ->
|
|
|
|
it "updates the title to the new item's title plus the project path", ->
|
|
|
|
rootView.getActivePane().showNextItem()
|
|
|
|
item = rootView.getActivePaneItem()
|
|
|
|
expect(rootView.title).toBe "#{item.getTitle()} - #{project.getPath()}"
|
|
|
|
|
|
|
|
describe "when the last pane item is removed", ->
|
2013-04-04 02:14:42 +04:00
|
|
|
it "update the title to contain the project's path", ->
|
2013-02-26 03:26:50 +04:00
|
|
|
rootView.getActivePane().remove()
|
|
|
|
expect(rootView.getActivePaneItem()).toBeUndefined()
|
2013-04-04 03:01:17 +04:00
|
|
|
expect(rootView.title).toBe "atom - #{project.getPath()}"
|
2013-02-26 03:26:50 +04:00
|
|
|
|
|
|
|
describe "when an inactive pane's item changes", ->
|
|
|
|
it "does not update the title", ->
|
|
|
|
pane = rootView.getActivePane()
|
|
|
|
pane.splitRight()
|
|
|
|
initialTitle = rootView.title
|
|
|
|
pane.showNextItem()
|
|
|
|
expect(rootView.title).toBe initialTitle
|
|
|
|
|
2012-08-28 02:36:36 +04:00
|
|
|
describe "font size adjustment", ->
|
|
|
|
it "increases/decreases font size when increase/decrease-font-size events are triggered", ->
|
2013-02-22 05:30:25 +04:00
|
|
|
fontSizeBefore = config.get('editor.fontSize')
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger 'window:increase-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 1
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger 'window:increase-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 2
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore + 1
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
expect(config.get('editor.fontSize')).toBe fontSizeBefore
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
it "does not allow the font size to be less than 1", ->
|
2012-12-18 05:52:20 +04:00
|
|
|
config.set("editor.fontSize", 1)
|
2012-12-13 03:23:36 +04:00
|
|
|
rootView.trigger 'window:decrease-font-size'
|
2013-02-22 05:30:25 +04:00
|
|
|
expect(config.get('editor.fontSize')).toBe 1
|
2012-09-20 20:31:04 +04:00
|
|
|
|
2013-02-21 03:43:29 +04:00
|
|
|
describe ".open(path, options)", ->
|
2013-02-19 04:28:29 +04:00
|
|
|
describe "when there is no active pane", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
beforeEach ->
|
2013-02-28 03:54:06 +04:00
|
|
|
spyOn(Pane.prototype, 'focus')
|
2013-02-19 04:28:29 +04:00
|
|
|
rootView.getActivePane().remove()
|
|
|
|
expect(rootView.getActivePane()).toBeUndefined()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when called with no path", ->
|
2013-02-28 03:54:06 +04:00
|
|
|
it "creates a empty edit session as an item on a new pane, and focuses the pane", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
editSession = rootView.open()
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(rootView.getActivePane().activeItem).toBe editSession
|
2013-02-19 04:28:29 +04:00
|
|
|
expect(editSession.getPath()).toBeUndefined()
|
2013-02-28 03:54:06 +04:00
|
|
|
expect(rootView.getActivePane().focus).toHaveBeenCalled()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when called with a path", ->
|
2013-02-28 03:54:06 +04:00
|
|
|
it "creates an edit session for the given path as an item on a new pane, and focuses the pane", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
editSession = rootView.open('b')
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(rootView.getActivePane().activeItem).toBe editSession
|
2013-04-03 22:01:01 +04:00
|
|
|
expect(editSession.getPath()).toBe fsUtils.resolveOnLoadPath('fixtures/dir/b')
|
2013-02-28 03:54:06 +04:00
|
|
|
expect(rootView.getActivePane().focus).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when the changeFocus option is false", ->
|
|
|
|
it "does not focus the new pane", ->
|
|
|
|
editSession = rootView.open('b', changeFocus: false)
|
|
|
|
expect(rootView.getActivePane().focus).not.toHaveBeenCalled()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
2013-02-19 04:28:29 +04:00
|
|
|
describe "when there is an active pane", ->
|
|
|
|
[activePane, initialItemCount] = []
|
2012-08-28 02:36:36 +04:00
|
|
|
beforeEach ->
|
2013-02-19 04:28:29 +04:00
|
|
|
activePane = rootView.getActivePane()
|
2013-02-28 03:54:06 +04:00
|
|
|
spyOn(activePane, 'focus')
|
2013-02-19 04:28:29 +04:00
|
|
|
initialItemCount = activePane.getItems().length
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when called with no path", ->
|
2013-02-28 03:54:06 +04:00
|
|
|
it "opens an edit session with an empty buffer as an item on the active pane and focuses it", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
editSession = rootView.open()
|
2013-02-19 04:28:29 +04:00
|
|
|
expect(activePane.getItems().length).toBe initialItemCount + 1
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(activePane.activeItem).toBe editSession
|
2013-02-19 04:28:29 +04:00
|
|
|
expect(editSession.getPath()).toBeUndefined()
|
2013-02-28 03:54:06 +04:00
|
|
|
expect(activePane.focus).toHaveBeenCalled()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "when called with a path", ->
|
2013-02-19 04:28:29 +04:00
|
|
|
describe "when the active pane already has an edit session item for the path being opened", ->
|
|
|
|
it "shows the existing edit session on the pane", ->
|
2013-02-28 01:15:38 +04:00
|
|
|
previousEditSession = activePane.activeItem
|
2013-02-19 04:28:29 +04:00
|
|
|
|
|
|
|
editSession = rootView.open('b')
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(activePane.activeItem).toBe editSession
|
2013-02-19 04:28:29 +04:00
|
|
|
expect(editSession).not.toBe previousEditSession
|
2013-02-28 03:54:06 +04:00
|
|
|
|
|
|
|
editSession = rootView.open(previousEditSession.getPath())
|
|
|
|
expect(editSession).toBe previousEditSession
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(activePane.activeItem).toBe editSession
|
2013-02-19 04:28:29 +04:00
|
|
|
|
2013-02-28 03:54:06 +04:00
|
|
|
expect(activePane.focus).toHaveBeenCalled()
|
|
|
|
|
2013-02-19 04:28:29 +04:00
|
|
|
describe "when the active pane does not have an edit session item for the path being opened", ->
|
|
|
|
it "creates a new edit session for the given path in the active editor", ->
|
|
|
|
editSession = rootView.open('b')
|
|
|
|
expect(activePane.items.length).toBe 2
|
2013-02-28 01:15:38 +04:00
|
|
|
expect(activePane.activeItem).toBe editSession
|
2013-02-28 03:54:06 +04:00
|
|
|
expect(activePane.focus).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when the changeFocus option is false", ->
|
|
|
|
it "does not focus the active pane", ->
|
|
|
|
editSession = rootView.open('b', changeFocus: false)
|
|
|
|
expect(activePane.focus).not.toHaveBeenCalled()
|
2012-09-20 03:53:24 +04:00
|
|
|
|
2012-10-19 01:44:21 +04:00
|
|
|
describe "window:toggle-invisibles event", ->
|
|
|
|
it "shows/hides invisibles in all open and future editors", ->
|
|
|
|
rootView.height(200)
|
|
|
|
rootView.attachToDom()
|
2013-02-22 05:49:42 +04:00
|
|
|
rightEditor = rootView.getActiveView()
|
2012-10-19 01:44:21 +04:00
|
|
|
rightEditor.setText(" \t ")
|
|
|
|
leftEditor = rightEditor.splitLeft()
|
|
|
|
expect(rightEditor.find(".line:first").text()).toBe " "
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
2012-12-21 03:42:38 +04:00
|
|
|
withInvisiblesShowing = "#{rightEditor.invisibles.space}#{rightEditor.invisibles.tab} #{rightEditor.invisibles.space}#{rightEditor.invisibles.eol}"
|
|
|
|
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger "window:toggle-invisibles"
|
2012-12-21 03:42:38 +04:00
|
|
|
expect(rightEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
2012-10-19 01:44:21 +04:00
|
|
|
|
|
|
|
lowerLeftEditor = leftEditor.splitDown()
|
2012-12-21 03:42:38 +04:00
|
|
|
expect(lowerLeftEditor.find(".line:first").text()).toBe withInvisiblesShowing
|
2012-10-19 01:44:21 +04:00
|
|
|
|
2012-10-19 22:51:36 +04:00
|
|
|
rootView.trigger "window:toggle-invisibles"
|
2012-10-19 01:44:21 +04:00
|
|
|
expect(rightEditor.find(".line:first").text()).toBe " "
|
|
|
|
expect(leftEditor.find(".line:first").text()).toBe " "
|
|
|
|
|
|
|
|
lowerRightEditor = rightEditor.splitDown()
|
|
|
|
expect(lowerRightEditor.find(".line:first").text()).toBe " "
|
2013-01-10 01:18:10 +04:00
|
|
|
|
2012-10-11 05:43:56 +04:00
|
|
|
describe ".eachEditor(callback)", ->
|
2012-10-11 05:41:12 +04:00
|
|
|
beforeEach ->
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
it "invokes the callback for existing editor", ->
|
|
|
|
count = 0
|
|
|
|
callbackEditor = null
|
|
|
|
callback = (editor) ->
|
|
|
|
callbackEditor = editor
|
|
|
|
count++
|
|
|
|
rootView.eachEditor(callback)
|
|
|
|
expect(count).toBe 1
|
2013-02-22 05:49:42 +04:00
|
|
|
expect(callbackEditor).toBe rootView.getActiveView()
|
2012-10-11 05:41:12 +04:00
|
|
|
|
|
|
|
it "invokes the callback for new editor", ->
|
|
|
|
count = 0
|
|
|
|
callbackEditor = null
|
|
|
|
callback = (editor) ->
|
|
|
|
callbackEditor = editor
|
|
|
|
count++
|
|
|
|
|
|
|
|
rootView.eachEditor(callback)
|
|
|
|
count = 0
|
|
|
|
callbackEditor = null
|
2013-02-22 05:49:42 +04:00
|
|
|
rootView.getActiveView().splitRight()
|
2012-10-11 05:41:12 +04:00
|
|
|
expect(count).toBe 1
|
2013-02-22 05:49:42 +04:00
|
|
|
expect(callbackEditor).toBe rootView.getActiveView()
|
2012-10-12 20:16:46 +04:00
|
|
|
|
|
|
|
describe ".eachBuffer(callback)", ->
|
|
|
|
beforeEach ->
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
it "invokes the callback for existing buffer", ->
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
rootView.eachBuffer(callback)
|
|
|
|
expect(count).toBe 1
|
2013-02-22 05:49:42 +04:00
|
|
|
expect(callbackBuffer).toBe rootView.getActiveView().getBuffer()
|
2012-10-12 20:16:46 +04:00
|
|
|
|
|
|
|
it "invokes the callback for new buffer", ->
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
callback = (buffer) ->
|
|
|
|
callbackBuffer = buffer
|
|
|
|
count++
|
|
|
|
|
|
|
|
rootView.eachBuffer(callback)
|
|
|
|
count = 0
|
|
|
|
callbackBuffer = null
|
|
|
|
rootView.open(require.resolve('fixtures/sample.txt'))
|
|
|
|
expect(count).toBe 1
|
2013-02-22 05:49:42 +04:00
|
|
|
expect(callbackBuffer).toBe rootView.getActiveView().getBuffer()
|
2013-04-29 21:27:39 +04:00
|
|
|
|
|
|
|
describe "when a 'new-editor' event is triggered", ->
|
|
|
|
it "opens a new untitled editor", ->
|
|
|
|
itemCount = rootView.getActivePane().getItems().length
|
|
|
|
rootView.trigger 'new-editor'
|
|
|
|
expect(rootView.getActivePaneItem().getPath()).toBeUndefined()
|
|
|
|
expect(rootView.getActivePaneItem().getBuffer().fileExists()).toBeFalsy()
|
|
|
|
expect(rootView.getActivePane().getItems().length).toBe itemCount + 1
|