2011-12-29 05:14:32 +04:00
|
|
|
$ = require 'jquery'
|
2011-12-30 23:50:29 +04:00
|
|
|
fs = require 'fs'
|
2011-12-29 05:14:32 +04:00
|
|
|
RootView = require 'root-view'
|
2012-03-19 18:48:16 +04:00
|
|
|
Buffer = require 'buffer'
|
2011-12-29 05:14:32 +04:00
|
|
|
|
|
|
|
describe "RootView", ->
|
|
|
|
rootView = null
|
2012-01-05 23:01:17 +04:00
|
|
|
project = null
|
2012-01-04 03:39:09 +04:00
|
|
|
url = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
url = require.resolve 'fixtures/dir/a'
|
2012-02-06 23:12:45 +04:00
|
|
|
rootView = new RootView({url})
|
2012-01-11 23:42:22 +04:00
|
|
|
rootView.enableKeymap()
|
2012-01-05 23:01:17 +04:00
|
|
|
project = rootView.project
|
2011-12-29 05:14:32 +04:00
|
|
|
|
2012-01-04 01:57:10 +04:00
|
|
|
describe "initialize", ->
|
2012-01-04 22:51:41 +04:00
|
|
|
describe "when called with a url that references a file", ->
|
|
|
|
it "creates a project for the file's parent directory and opens it in the editor", ->
|
|
|
|
expect(rootView.project.url).toBe fs.directory(url)
|
2012-01-24 05:28:16 +04:00
|
|
|
expect(rootView.editor.buffer.path).toBe url
|
2012-01-04 22:51:41 +04:00
|
|
|
|
|
|
|
describe "when called with a url that references a directory", ->
|
2012-01-05 06:08:23 +04:00
|
|
|
it "creates a project for the directory and opens an empty buffer", ->
|
|
|
|
url = require.resolve 'fixtures/dir/'
|
2012-02-06 23:12:45 +04:00
|
|
|
rootView = new RootView({url})
|
2012-01-04 22:51:41 +04:00
|
|
|
|
|
|
|
expect(rootView.project.url).toBe url
|
|
|
|
expect(rootView.editor.buffer.url).toBeUndefined()
|
2012-01-04 01:57:10 +04:00
|
|
|
|
|
|
|
describe "when not called with a url", ->
|
|
|
|
it "opens an empty buffer", ->
|
2012-02-06 23:12:45 +04:00
|
|
|
rootView = new RootView
|
2012-01-04 03:39:09 +04:00
|
|
|
expect(rootView.editor.buffer.url).toBeUndefined()
|
2012-01-04 01:57:10 +04:00
|
|
|
|
2012-03-19 18:34:37 +04:00
|
|
|
describe "split editor panes", ->
|
|
|
|
describe "when split-right is triggered on the editor", ->
|
2012-03-19 19:04:39 +04:00
|
|
|
it "places the a new editor to the right of the current editor in a .horizontal div, and focuses the new editor", ->
|
2012-03-19 18:34:37 +04:00
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
expect(rootView.find('.horizontal')).not.toExist()
|
|
|
|
|
|
|
|
editor1 = rootView.find('.editor').view()
|
2012-03-19 18:48:16 +04:00
|
|
|
editor1.setBuffer(new Buffer(require.resolve 'fixtures/sample.js'))
|
|
|
|
editor1.setCursorScreenPosition([3, 2])
|
2012-03-19 18:34:37 +04:00
|
|
|
editor1.trigger 'split-right'
|
|
|
|
|
|
|
|
expect(rootView.find('.horizontal')).toExist()
|
|
|
|
expect(rootView.find('.horizontal .editor').length).toBe 2
|
|
|
|
expect(rootView.find('.horizontal .editor:eq(0)').view()).toBe editor1
|
|
|
|
editor2 = rootView.find('.horizontal .editor:eq(1)').view()
|
|
|
|
expect(editor2.buffer).toBe editor1.buffer
|
2012-03-19 18:48:16 +04:00
|
|
|
expect(editor2.getCursorScreenPosition()).toEqual [3, 2]
|
|
|
|
expect(editor1).toHaveClass 'split'
|
|
|
|
expect(editor2).toHaveClass 'split'
|
|
|
|
|
|
|
|
expect(editor1.has(':focus')).not.toExist()
|
|
|
|
expect(editor2.has(':focus')).toExist()
|
2012-03-19 18:34:37 +04:00
|
|
|
|
|
|
|
# insertion reflected in both buffers
|
|
|
|
editor1.buffer.insert([0, 0], 'ABC')
|
|
|
|
expect(editor1.lines.find('.line:first').text()).toContain 'ABC'
|
|
|
|
expect(editor2.lines.find('.line:first').text()).toContain 'ABC'
|
|
|
|
|
2012-03-19 19:22:13 +04:00
|
|
|
describe "when split-left is triggered on the editor", ->
|
|
|
|
it "places the a new editor to the left of the current editor in a .horizontal div, and focuses the new editor", ->
|
|
|
|
rootView.attachToDom()
|
|
|
|
|
|
|
|
expect(rootView.find('.horizontal')).not.toExist()
|
|
|
|
|
|
|
|
editor1 = rootView.find('.editor').view()
|
|
|
|
editor1.setBuffer(new Buffer(require.resolve 'fixtures/sample.js'))
|
|
|
|
editor1.setCursorScreenPosition([3, 2])
|
|
|
|
editor1.trigger 'split-left'
|
|
|
|
|
|
|
|
expect(rootView.find('.horizontal')).toExist()
|
|
|
|
expect(rootView.find('.horizontal .editor').length).toBe 2
|
|
|
|
expect(rootView.find('.horizontal .editor:eq(1)').view()).toBe editor1
|
|
|
|
editor2 = rootView.find('.horizontal .editor:eq(0)').view()
|
|
|
|
expect(editor2.buffer).toBe editor1.buffer
|
|
|
|
expect(editor2.getCursorScreenPosition()).toEqual [3, 2]
|
|
|
|
expect(editor1).toHaveClass 'split'
|
|
|
|
expect(editor2).toHaveClass 'split'
|
|
|
|
|
|
|
|
expect(editor1.has(':focus')).not.toExist()
|
|
|
|
expect(editor2.has(':focus')).toExist()
|
|
|
|
|
|
|
|
# insertion reflected in both buffers
|
|
|
|
editor1.buffer.insert([0, 0], 'ABC')
|
|
|
|
expect(editor1.lines.find('.line:first').text()).toContain 'ABC'
|
|
|
|
expect(editor2.lines.find('.line:first').text()).toContain 'ABC'
|
2012-03-19 18:34:37 +04:00
|
|
|
|
2011-12-29 05:14:32 +04:00
|
|
|
describe ".addPane(view)", ->
|
|
|
|
it "adds the given view to the rootView (at the bottom by default)", ->
|
2012-03-16 03:18:26 +04:00
|
|
|
expect(rootView.children().length).toBe 1
|
2011-12-29 05:14:32 +04:00
|
|
|
rootView.addPane $('<div id="foo">')
|
2012-03-16 03:18:26 +04:00
|
|
|
expect(rootView.children().length).toBe 2
|
2011-12-29 05:14:32 +04:00
|
|
|
|
2012-01-12 01:13:37 +04:00
|
|
|
describe "the file finder", ->
|
|
|
|
describe "when the toggle-file-finder event is triggered", ->
|
|
|
|
describe "when there is a project", ->
|
|
|
|
it "shows the FileFinder when it is not on screen and hides it when it is", ->
|
|
|
|
runs ->
|
2012-01-25 06:14:44 +04:00
|
|
|
rootView.attachToDom()
|
2012-01-12 01:13:37 +04:00
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
rootView.resultOfTrigger 'toggle-file-finder'
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(rootView.find('.file-finder')).toExist()
|
|
|
|
expect(rootView.find('.file-finder input:focus')).toExist()
|
2012-01-25 05:30:40 +04:00
|
|
|
rootView.trigger 'toggle-file-finder'
|
|
|
|
expect(rootView.find('.editor:has(:focus)')).toExist()
|
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2012-01-12 01:13:37 +04:00
|
|
|
|
|
|
|
it "shows all relative file paths for the current project", ->
|
|
|
|
waitsForPromise ->
|
|
|
|
rootView.resultOfTrigger 'toggle-file-finder'
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
project.getFilePaths().done (paths) ->
|
|
|
|
expect(rootView.fileFinder.urlList.children('li').length).toBe paths.length
|
|
|
|
|
|
|
|
for path in paths
|
|
|
|
relativePath = path.replace(project.url, '')
|
|
|
|
expect(rootView.fileFinder.urlList.find("li:contains(#{relativePath}):not(:contains(#{project.url}))")).toExist()
|
|
|
|
|
|
|
|
describe "when there is no project", ->
|
|
|
|
beforeEach ->
|
2012-02-06 23:12:45 +04:00
|
|
|
rootView = new RootView
|
2012-01-12 01:13:37 +04:00
|
|
|
|
|
|
|
it "does not open the FileFinder", ->
|
|
|
|
expect(rootView.editor.buffer.url).toBeUndefined()
|
2012-01-04 03:39:09 +04:00
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2012-01-11 08:06:34 +04:00
|
|
|
rootView.trigger 'toggle-file-finder'
|
2012-01-04 03:39:09 +04:00
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2011-12-30 00:23:04 +04:00
|
|
|
|
2012-01-12 01:13:37 +04:00
|
|
|
describe "when a path is selected in the file finder", ->
|
|
|
|
it "opens the file associated with that path in the editor", ->
|
|
|
|
waitsForPromise -> rootView.resultOfTrigger 'toggle-file-finder'
|
|
|
|
runs ->
|
|
|
|
firstLi = rootView.fileFinder.find('li:first')
|
|
|
|
rootView.fileFinder.trigger 'select'
|
|
|
|
expect(rootView.editor.buffer.url).toBe(project.url + firstLi.text())
|
2012-01-05 23:01:17 +04:00
|
|
|
|
2012-01-11 11:54:14 +04:00
|
|
|
describe "global keymap wiring", ->
|
|
|
|
commandHandler = null
|
|
|
|
beforeEach ->
|
|
|
|
commandHandler = jasmine.createSpy('commandHandler')
|
|
|
|
rootView.on('foo-command', commandHandler)
|
2012-02-29 23:33:15 +04:00
|
|
|
|
|
|
|
window.keymap.bindKeys('*', 'x': 'foo-command')
|
2012-01-11 11:54:14 +04:00
|
|
|
|
|
|
|
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
|
|
|
|
it "triggers matching keybindings for that event", ->
|
|
|
|
event = keydownEvent 'x', target: rootView[0]
|
2012-01-11 23:42:22 +04:00
|
|
|
|
2012-01-11 11:54:14 +04:00
|
|
|
rootView.trigger(event)
|
|
|
|
expect(commandHandler).toHaveBeenCalled()
|
2012-01-05 23:01:17 +04:00
|
|
|
|