From 6dddb1aa26d7b424b6059a8e0bb46a23b64f315f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 3 Jan 2012 16:39:09 -0700 Subject: [PATCH] RootView.toggleFileFinder scans urls asynchronously. --- spec/atom/root-view-spec.coffee | 68 +++++++++++++++++---------------- spec/spec-helper.coffee | 4 ++ src/atom/root-view.coffee | 11 +++--- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 44d901d13..12cfa39d1 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -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 $('
') 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() - diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 388107963..4d2fb0d41 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -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) + diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index 4ff40f9cf..14cb7add1 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -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()