mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
RootView.toggleFileFinder scans urls asynchronously.
This commit is contained in:
@@ -4,28 +4,23 @@ RootView = require 'root-view'
|
||||
|
||||
describe "RootView", ->
|
||||
rootView = null
|
||||
beforeEach -> rootView = RootView.build()
|
||||
url = null
|
||||
|
||||
beforeEach ->
|
||||
url = require.resolve 'fixtures/dir/a'
|
||||
rootView = RootView.build {url}
|
||||
|
||||
describe "initialize", ->
|
||||
describe "when called with a url", ->
|
||||
describe "when the url references a file", ->
|
||||
url = null
|
||||
beforeEach ->
|
||||
url = require.resolve 'fixtures/sample.txt'
|
||||
rootView = RootView.build {url}
|
||||
|
||||
it "creates a project for the file's parent directory", ->
|
||||
it "creates a project for the file's parent directory and opens it in the editor", ->
|
||||
expect(rootView.project.url).toBe fs.directory(url)
|
||||
|
||||
it "opens the file in the editor", ->
|
||||
expect(rootView.editor.buffer.url).toBe url
|
||||
|
||||
describe "when not called with a url", ->
|
||||
it "opens an empty buffer", ->
|
||||
url = null
|
||||
rootView = RootView.build {url}
|
||||
|
||||
expect(rootView.editor.buffer.url).toBeNull()
|
||||
rootView = RootView.build()
|
||||
expect(rootView.editor.buffer.url).toBeUndefined()
|
||||
|
||||
describe ".addPane(view)", ->
|
||||
it "adds the given view to the rootView (at the bottom by default)", ->
|
||||
@@ -33,34 +28,41 @@ describe "RootView", ->
|
||||
rootView.addPane $('<div id="foo">')
|
||||
expect(rootView.vertical.children().length).toBe 2
|
||||
|
||||
describe "toggleFileFinder", ->
|
||||
describe "when the editor has a url", ->
|
||||
baseUrl = require.resolve('fixtures/dir/a')
|
||||
|
||||
beforeEach ->
|
||||
rootView.editor.open baseUrl
|
||||
|
||||
describe ".toggleFileFinder()", ->
|
||||
describe "when there is a project", ->
|
||||
it "shows the FileFinder when it is not on screen and hides it when it is", ->
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
runs ->
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
|
||||
waitsForPromise ->
|
||||
rootView.toggleFileFinder()
|
||||
|
||||
runs ->
|
||||
expect(rootView.find('.file-finder')).toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
|
||||
it "shows all urls for the current project", ->
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.fileFinder.urlList.children('li').length).toBe 3
|
||||
waitsForPromise ->
|
||||
rootView.toggleFileFinder()
|
||||
runs ->
|
||||
expect(rootView.fileFinder.urlList.children('li').length).toBe 3
|
||||
|
||||
it "remove common path prefix from files", ->
|
||||
rootView.toggleFileFinder()
|
||||
commonPathPattern = new RegExp("^" + fs.directory(baseUrl))
|
||||
expect(rootView.fileFinder.urlList.children('li:first').text()).not.toMatch commonPathPattern
|
||||
it "removes common path prefix from files", ->
|
||||
waitsForPromise ->
|
||||
rootView.toggleFileFinder()
|
||||
|
||||
runs ->
|
||||
commonPathPattern = new RegExp("^" + fs.directory(url))
|
||||
expect(rootView.fileFinder.urlList.children('li:first').text()).not.toMatch commonPathPattern
|
||||
|
||||
describe "when there is no project", ->
|
||||
beforeEach ->
|
||||
rootView = RootView.build()
|
||||
|
||||
describe "when the editor has no url", ->
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@@ -15,3 +15,7 @@ window.keydown = (pattern) ->
|
||||
window.createKeyEvent = (pattern) ->
|
||||
$.Event "keydown", atom.keyBinder.parseKeyPattern(pattern)
|
||||
|
||||
window.waitsForPromise = (fn) ->
|
||||
window.waitsFor (moveOn) ->
|
||||
fn().done(moveOn)
|
||||
|
||||
|
||||
@@ -37,9 +37,10 @@ class RootView extends Template
|
||||
@fileFinder = null
|
||||
else
|
||||
directory = fs.directory @editor.buffer.url
|
||||
urls = (url for url in fs.list(directory, true) when fs.isFile url)
|
||||
urls = (url.replace(directory, "") for url in urls)
|
||||
@fileFinder = FileFinder.build({urls})
|
||||
@addPane(@fileFinder)
|
||||
@fileFinder.input.focus()
|
||||
return fs.async.list(directory, true).done (urls) =>
|
||||
urls = (url for url in urls when fs.isFile url)
|
||||
urls = (url.replace(directory, "") for url in urls)
|
||||
@fileFinder = FileFinder.build({urls})
|
||||
@addPane(@fileFinder)
|
||||
@fileFinder.input.focus()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user