From cffb73bc8d3d39e4ebaf5b87463a8050cd2465bc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 10 Jan 2013 13:23:59 -0800 Subject: [PATCH] Show notification that Gist was created --- src/packages/gists/lib/gists.coffee | 8 ++++++- src/packages/gists/spec/gists-spec.coffee | 28 ++++++++++++++++++----- src/packages/gists/stylesheets/gists.css | 11 +++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/packages/gists/stylesheets/gists.css diff --git a/src/packages/gists/lib/gists.coffee b/src/packages/gists/lib/gists.coffee index ee5591988..008c7d48d 100644 --- a/src/packages/gists/lib/gists.coffee +++ b/src/packages/gists/lib/gists.coffee @@ -1,4 +1,5 @@ $ = require 'jquery' +{$$} = require 'space-pen' module.exports = activate: (rootView) -> @@ -16,4 +17,9 @@ module.exports = dataType: 'json' contentType: 'application/json; charset=UTF-8' data: JSON.stringify(gist) - success: (response) -> pasteboard.write(response.html_url) + success: (response) -> + pasteboard.write(response.html_url) + notification = $$ -> + @div "Gist #{response.id} created", class: 'gist-notification' + rootView.append(notification.hide()) + notification.fadeIn().delay(1800).fadeOut(complete: -> $(this).remove()) diff --git a/src/packages/gists/spec/gists-spec.coffee b/src/packages/gists/spec/gists-spec.coffee index c4f69c9c7..91c52a0ba 100644 --- a/src/packages/gists/spec/gists-spec.coffee +++ b/src/packages/gists/spec/gists-spec.coffee @@ -17,21 +17,37 @@ describe "Gists package", -> describe "when gist:create is triggered on an editor", -> describe "when the editor has no selection", -> - it "creates an Ajax request to api.github.com with the entire buffer contents as the Gist's content", -> + [request, originalFxOffValue] = [] + + beforeEach -> + originalFxOffValue = $.fx.off + $.fx.off = true editor.trigger 'gist:create' expect($.ajax).toHaveBeenCalled() request = $.ajax.argsForCall[0][0] + + afterEach -> + $.fx.off = originalFxOffValue + + it "creates an Ajax request to api.github.com with the entire buffer contents as the Gist's content", -> expect(request.url).toBe 'https://api.github.com/gists' expect(request.type).toBe 'POST' requestData = JSON.parse(request.data) expect(requestData.public).toBeFalsy() expect(requestData.files).toEqual 'sample.js': content: editor.getText() - it "places the created Gist's URL on the clipboard", -> - editor.trigger 'gist:create' - request = $.ajax.argsForCall[0][0] - request.success(html_url: 'https://gist.github.com/1') - expect(pasteboard.read()[0]).toBe 'https://gist.github.com/1' + describe "when the server responds successfully", -> + beforeEach -> + request.success(html_url: 'https://gist.github.com/1', id: '1') + + it "places the created Gist's URL on the clipboard", -> + expect(pasteboard.read()[0]).toBe 'https://gist.github.com/1' + + it "flashes that the Gist was created", -> + expect(rootView.find('.gist-notification')).toExist() + expect(rootView.find('.gist-notification').text()).toBe 'Gist 1 created' + advanceClock(2000) + expect(rootView.find('.gist-notification')).not.toExist() describe "when the editor has a selection", -> beforeEach -> diff --git a/src/packages/gists/stylesheets/gists.css b/src/packages/gists/stylesheets/gists.css new file mode 100644 index 000000000..7bb372e2a --- /dev/null +++ b/src/packages/gists/stylesheets/gists.css @@ -0,0 +1,11 @@ +.gist-notification { + position: absolute; + top: 6px; + left: 50%; + margin-left: -5%; + z-index: 99; + padding: 10px; + -webkit-box-shadow: 0px 0px 5px 5px #222; + color: #FFF; + background-color: #444; +}