From 22f3397af24fed2424783ad6952521f277aaa82c Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 16 Nov 2012 11:10:11 -0800 Subject: [PATCH] Display error when no tags are found for a file. --- .../spec/outline-view-spec.coffee | 71 +++++++++++++++---- .../outline-view/src/outline-view.coffee | 10 ++- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/extensions/outline-view/spec/outline-view-spec.coffee b/src/extensions/outline-view/spec/outline-view-spec.coffee index 97ac1a9d1..646bdb6b2 100644 --- a/src/extensions/outline-view/spec/outline-view-spec.coffee +++ b/src/extensions/outline-view/spec/outline-view-spec.coffee @@ -14,22 +14,65 @@ describe "OutlineView", -> afterEach -> rootView.deactivate() - it "displays all JavaScript functions with line numbers", -> - rootView.open('sample.js') - expect(rootView.find('.outline-view')).not.toExist() - attachSpy = spyOn(outlineView, 'attach').andCallThrough() - rootView.getActiveEditor().trigger "outline-view:toggle" + describe "when tags can be generated for a file", -> + it "initially displays all JavaScript functions with line numbers", -> + rootView.open('sample.js') + expect(rootView.find('.outline-view')).not.toExist() + attachSpy = spyOn(outlineView, 'attach').andCallThrough() + rootView.getActiveEditor().trigger "outline-view:toggle" - waitsFor -> - attachSpy.callCount > 0 + waitsFor -> + attachSpy.callCount > 0 - runs -> - expect(rootView.find('.outline-view')).toExist() - expect(outlineView.list.children('li').length).toBe 2 - expect(outlineView.list.children('li:first').find('.function-name')).toHaveText 'quicksort' - expect(outlineView.list.children('li:first').find('.function-line')).toHaveText 'Line 1' - expect(outlineView.list.children('li:last').find('.function-name')).toHaveText 'quicksort.sort' - expect(outlineView.list.children('li:last').find('.function-line')).toHaveText 'Line 2' + runs -> + expect(rootView.find('.outline-view')).toExist() + expect(outlineView.list.children('li').length).toBe 2 + expect(outlineView.list.children('li:first').find('.function-name')).toHaveText 'quicksort' + expect(outlineView.list.children('li:first').find('.function-line')).toHaveText 'Line 1' + expect(outlineView.list.children('li:last').find('.function-name')).toHaveText 'quicksort.sort' + expect(outlineView.list.children('li:last').find('.function-line')).toHaveText 'Line 2' + expect(outlineView).not.toHaveClass "error" + expect(outlineView.error).not.toBeVisible() + + it "displays error when no tags match text in mini-editor", -> + rootView.open('sample.js') + expect(rootView.find('.outline-view')).not.toExist() + attachSpy = spyOn(outlineView, 'attach').andCallThrough() + rootView.getActiveEditor().trigger "outline-view:toggle" + + waitsFor -> + attachSpy.callCount > 0 + + runs -> + outlineView.miniEditor.setText("nothing will match this") + expect(rootView.find('.outline-view')).toExist() + expect(outlineView.list.children('li').length).toBe 0 + expect(outlineView.error).toBeVisible() + expect(outlineView.error.text().length).toBeGreaterThan 0 + expect(outlineView).toHaveClass "error" + + # Should remove error + outlineView.miniEditor.setText("") + expect(outlineView.list.children('li').length).toBe 2 + expect(outlineView).not.toHaveClass "error" + expect(outlineView.error).not.toBeVisible() + + describe "when tags can't be generated for a file", -> + it "shows an error message when no matching tags are found", -> + rootView.open('sample.txt') + expect(rootView.find('.outline-view')).not.toExist() + attachSpy = spyOn(outlineView, 'attach').andCallThrough() + rootView.getActiveEditor().trigger "outline-view:toggle" + + waitsFor -> + attachSpy.callCount > 0 + + runs -> + expect(rootView.find('.outline-view')).toExist() + expect(outlineView.list.children('li').length).toBe 0 + expect(outlineView.error).toBeVisible() + expect(outlineView.error.text().length).toBeGreaterThan 0 + expect(outlineView).toHaveClass "error" it "moves the cursor to the selected function", -> tags = [] diff --git a/src/extensions/outline-view/src/outline-view.coffee b/src/extensions/outline-view/src/outline-view.coffee index 8a275f6a6..22725703c 100644 --- a/src/extensions/outline-view/src/outline-view.coffee +++ b/src/extensions/outline-view/src/outline-view.coffee @@ -39,8 +39,14 @@ class OutlineView extends SelectList path = @rootView.getActiveEditor().getPath() new TagGenerator(path, callback).generate().done => if tags.length > 0 - @setArray(tags) - @attach() + @miniEditor.show() + @setArray(tags) + else + @miniEditor.hide() + @setError("No symbols found") + setTimeout (=> @detach()), 2000 + + @attach() confirmed : ({position, name}) -> @cancel()