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'
|
|
|
|
|
|
|
|
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'
|
|
|
|
rootView = RootView.build {url}
|
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)
|
|
|
|
expect(rootView.editor.buffer.url).toBe url
|
|
|
|
|
|
|
|
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-01-04 22:51:41 +04:00
|
|
|
rootView = RootView.build {url}
|
|
|
|
|
|
|
|
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-01-04 03:39:09 +04:00
|
|
|
rootView = RootView.build()
|
|
|
|
expect(rootView.editor.buffer.url).toBeUndefined()
|
2012-01-04 01:57:10 +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)", ->
|
|
|
|
expect(rootView.vertical.children().length).toBe 1
|
|
|
|
rootView.addPane $('<div id="foo">')
|
|
|
|
expect(rootView.vertical.children().length).toBe 2
|
|
|
|
|
2012-01-04 03:39:09 +04:00
|
|
|
describe ".toggleFileFinder()", ->
|
|
|
|
describe "when there is a project", ->
|
|
|
|
it "shows the FileFinder when it is not on screen and hides it when it is", ->
|
|
|
|
runs ->
|
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2011-12-30 23:50:29 +04:00
|
|
|
|
2012-01-04 03:39:09 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
rootView.toggleFileFinder()
|
2011-12-30 00:23:04 +04:00
|
|
|
|
2012-01-04 03:39:09 +04:00
|
|
|
runs ->
|
|
|
|
expect(rootView.find('.file-finder')).toExist()
|
|
|
|
rootView.toggleFileFinder()
|
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2011-12-30 00:23:04 +04:00
|
|
|
|
2012-01-05 23:13:55 +04:00
|
|
|
it "shows all relative file paths for the current project", ->
|
2012-01-04 03:39:09 +04:00
|
|
|
waitsForPromise ->
|
|
|
|
rootView.toggleFileFinder()
|
2012-01-05 23:01:17 +04:00
|
|
|
|
|
|
|
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()
|
2011-12-30 23:50:29 +04:00
|
|
|
|
2012-01-04 03:39:09 +04:00
|
|
|
describe "when there is no project", ->
|
|
|
|
beforeEach ->
|
|
|
|
rootView = RootView.build()
|
2011-12-30 00:23:04 +04:00
|
|
|
|
|
|
|
it "does not open the FileFinder", ->
|
|
|
|
expect(rootView.editor.buffer.url).toBeUndefined()
|
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
|
|
|
rootView.toggleFileFinder()
|
|
|
|
expect(rootView.find('.file-finder')).not.toExist()
|
2011-12-29 05:30:34 +04:00
|
|
|
|
2012-01-05 23:13:55 +04:00
|
|
|
describe "when a path is selected in the file finder", ->
|
2012-01-05 23:01:17 +04:00
|
|
|
it "opens the file associated with that path in the editor", ->
|
|
|
|
waitsForPromise -> rootView.toggleFileFinder()
|
|
|
|
runs ->
|
|
|
|
firstLi = rootView.fileFinder.find('li:first')
|
|
|
|
rootView.fileFinder.select()
|
|
|
|
expect(rootView.editor.buffer.url).toBe(project.url + firstLi.text())
|
|
|
|
|
2012-01-11 03:46:54 +04:00
|
|
|
describe "when a key is typed in the editor that has a binding in the keymap", ->
|
|
|
|
it "triggers the key binding's command as an event and does not insert a character", ->
|
2012-01-11 04:06:14 +04:00
|
|
|
rootView.globalKeymap.bindKeys('.editor', 'x': 'fooCommand')
|
2012-01-05 23:01:17 +04:00
|
|
|
|
2012-01-11 03:46:54 +04:00
|
|
|
fooCommandHandler = jasmine.createSpy('fooCommandHandler')
|
|
|
|
rootView.editor.on('fooCommand', fooCommandHandler)
|
2012-01-05 23:01:17 +04:00
|
|
|
|
2012-01-11 03:46:54 +04:00
|
|
|
event = keydownEvent 'x', target: rootView.find('textarea')[0]
|
|
|
|
rootView.editor.aceEditor.onCommandKey event, 0, event.which
|
|
|
|
|
|
|
|
expect(fooCommandHandler).toHaveBeenCalled()
|
2012-01-05 23:01:17 +04:00
|
|
|
|