From f11d51746d62a44c613f5efb7de16fa7f4b3990a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 15 Jan 2017 01:58:38 +0100 Subject: [PATCH 1/6] Downgrade thor to 0.19.1 Version 0.19.4 prints errors to the console, which can be weird for podmins. See erikhuda/thor#538 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4b4f790f7..ab4a78f3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -831,7 +831,7 @@ GEM unicode-display_width (~> 1.1.1) test_after_commit (1.1.0) activerecord (>= 3.2) - thor (0.19.4) + thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) timecop (0.8.1) From de789267fc5f34c82e01e1581246d9d65ea0be23 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 15 Jan 2017 00:40:48 +0100 Subject: [PATCH 2/6] Remove id selectors for mobile photo show page closes #7279 --- .../stylesheets/color_themes/dark/mobile.scss | 4 +- app/assets/stylesheets/mobile/mobile.scss | 52 ++++++++----------- app/views/photos/show.mobile.haml | 4 +- features/mobile/multiphoto.feature | 2 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/assets/stylesheets/color_themes/dark/mobile.scss b/app/assets/stylesheets/color_themes/dark/mobile.scss index 3f10c1483..eb8c50e20 100644 --- a/app/assets/stylesheets/color_themes/dark/mobile.scss +++ b/app/assets/stylesheets/color_themes/dark/mobile.scss @@ -43,7 +43,7 @@ body { .stream-element.unread { background-color: $gray; } .stream-element.read { background-color: $gray-darker; } - #show_content .photo { border-color: $border-grey; } + .photos .photo { border-color: $border-grey; } .header-full-width { border-bottom: 1px solid $border-grey; } @@ -60,6 +60,6 @@ body { } } } -// scss-lint:enable IdSelector, SelectorFormat, NestingDepth, SelectorDepth +// scss-lint:enable SelectorFormat, NestingDepth, SelectorDepth @import 'mobile/mobile'; diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index e078bf234..1e1fc8d4a 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -269,11 +269,8 @@ footer { font-size: 14px; } -#show_content { +.photos { padding-bottom: 24px; - border-bottom: 1px solid #bbb; - font-size: larger; - text-align: center; img:not(.avatar) { max-width: 100%; @@ -287,37 +284,30 @@ footer { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); border-color: #DDDDDD #BBBBBB #AAAAAA; border-bottom-width: 0px; - margin-top: 12px; min-height: 100px; - line-height: 5; - } - - .controls { - font: { - size: smaller; }; - } - - &.photos { - border-bottom: 0 !important; } } -#photo_controls { - .arrow { - font-size: 10em; - text-decoration: none; - text-shadow: 0 0 3px $white; - position: fixed; - bottom: -0.2em; - z-index: 1; - &.left { - left: -0.2em; - } - &.right { - right: -0.2em; - text-align: right; - } - .entypo-chevron-left, .entypo-chevron-right { margin-right: 0; } +.photo-controls .arrow { + bottom: -.2em; + font-size: 10em; + position: fixed; + text-decoration: none; + text-shadow: 0 0 3px $white; + z-index: 1; + + &.left { + left: -.2em; + } + + &.right { + right: -.2em; + text-align: right; + } + + .entypo-chevron-left, + .entypo-chevron-right { + margin-right: 0; } } diff --git a/app/views/photos/show.mobile.haml b/app/views/photos/show.mobile.haml index 7d3120709..04cda5bdd 100644 --- a/app/views/photos/show.mobile.haml +++ b/app/views/photos/show.mobile.haml @@ -5,7 +5,7 @@ :css footer{display: none;} -#show_content.photos +.photos .photo = image_tag photo.url(:scaled_full) .stream-element.photo_mobile @@ -24,7 +24,7 @@ = timeago(photo.created_at) -if additional_photos && additional_photos.length > 1 - #photo_controls + .photo-controls - if previous_photo != additional_photos.last = link_to(content_tag(:i, nil, id: "arrow-left", class: "entypo-chevron-left"), person_photo_path(previous_photo.author, previous_photo), diff --git a/features/mobile/multiphoto.feature b/features/mobile/multiphoto.feature index c56b6989e..44ca51026 100644 --- a/features/mobile/multiphoto.feature +++ b/features/mobile/multiphoto.feature @@ -17,7 +17,7 @@ Feature: viewing photos on the mobile main page When I press "Share" And I go to the stream page And I click on selector "img.stream-photo" - Then I should see a "img" within "#show_content" + Then I should see a "img" within ".photos" And I should not see a "#arrow-right" within "#main" And I should not see a "#arrow-left" within "#main" From b8d3323de03c7e4d57eb746678de0ca5e533ce82 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Nov 2016 17:26:25 +0100 Subject: [PATCH 3/6] Return error when unlike failed --- app/controllers/likes_controller.rb | 7 ++++++- config/locales/diaspora/en.yml | 2 ++ spec/controllers/likes_controller_spec.rb | 8 +++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 5c2c65789..8f9197c3c 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -31,7 +31,12 @@ class LikesController < ApplicationController end def destroy - @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id) + begin + @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id) + rescue ActiveRecord::RecordNotFound + render text: I18n.t("likes.destroy.error"), status: 404 + return + end current_user.retract(@like) respond_to do |format| diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 6fa0ba688..b41a72035 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -591,6 +591,8 @@ en: likes: create: error: "Failed to like." + destroy: + error: "Failed to unlike." notifications: started_sharing: diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 2aa04680e..928b1f64c 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -133,14 +133,12 @@ describe LikesController, :type => :controller do it 'does not let a user destroy other likes' do like2 = eve.like!(@message) - like_count = Like.count - expect { - delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id - }.to raise_error(ActiveRecord::RecordNotFound) + delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id + expect(response.status).to eq(404) + expect(response.body).to eq(I18n.t("likes.destroy.error")) expect(Like.count).to eq(like_count) - end end end From d609238ed4a6277e7334274224d079573ba86c85 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 26 Nov 2016 19:18:50 +0100 Subject: [PATCH 4/6] Refactor mobile alerts for error responses, add them to container with fixed position --- app/assets/javascripts/mobile/mobile_alert.js | 10 +++++++++- .../mobile/mobile_conversations.js | 5 ++--- .../stylesheets/mobile/flash_messages.scss | 20 +++++++++++++++++++ app/assets/stylesheets/mobile/mobile.scss | 1 + app/views/conversations/new.mobile.haml | 1 - app/views/layouts/application.mobile.haml | 3 +++ spec/javascripts/mobile/mobile_alert_spec.js | 14 +++++++++++++ .../mobile/mobile_conversations_spec.js | 13 +++++++++--- 8 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 app/assets/stylesheets/mobile/flash_messages.scss diff --git a/app/assets/javascripts/mobile/mobile_alert.js b/app/assets/javascripts/mobile/mobile_alert.js index 67e23a58a..354b90cb9 100644 --- a/app/assets/javascripts/mobile/mobile_alert.js +++ b/app/assets/javascripts/mobile/mobile_alert.js @@ -14,6 +14,14 @@ success: function(message) { this._flash(message, "success"); }, - error: function(message) { this._flash(message, "danger"); } + error: function(message) { this._flash(message, "danger"); }, + + handleAjaxError: function(response) { + if (response.status === 0) { + this.error(Diaspora.I18n.t("errors.connection")); + } else { + this.error(response.responseText); + } + } }; })(); diff --git a/app/assets/javascripts/mobile/mobile_conversations.js b/app/assets/javascripts/mobile/mobile_conversations.js index 4fef1b5b3..bf88bb5ff 100644 --- a/app/assets/javascripts/mobile/mobile_conversations.js +++ b/app/assets/javascripts/mobile/mobile_conversations.js @@ -10,9 +10,8 @@ Diaspora.Mobile.changeLocation(Routes.conversation(data.id)); }, - conversationCreateError: function(evt, resp) { - Diaspora.Mobile.Alert.error(resp.responseText); - $("html").animate({scrollTop: 0}); + conversationCreateError: function(evt, response) { + Diaspora.Mobile.Alert.handleAjaxError(response); } }; })(); diff --git a/app/assets/stylesheets/mobile/flash_messages.scss b/app/assets/stylesheets/mobile/flash_messages.scss new file mode 100644 index 000000000..945c2d1d5 --- /dev/null +++ b/app/assets/stylesheets/mobile/flash_messages.scss @@ -0,0 +1,20 @@ +.flash-messages-container { + background-color: rgba($black, .5); + padding: 0 10px; + position: fixed; + top: $mobile-navbar-height; + width: 100%; + z-index: 9; + + .flash-messages { + width: 100%; + } + + .alert { + margin-bottom: 10px; + } + + .alert:first-of-type { + margin-top: 10px; + } +} diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index 1e1fc8d4a..e48c64596 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -11,6 +11,7 @@ @import "mobile/header"; @import "mobile/tags"; @import "mobile/conversations"; +@import 'mobile/flash_messages'; @import "mobile/settings"; @import "mobile/stream_element"; @import "mobile/comments"; diff --git a/app/views/conversations/new.mobile.haml b/app/views/conversations/new.mobile.haml index 1da58fcfa..d8e8feb04 100644 --- a/app/views/conversations/new.mobile.haml +++ b/app/views/conversations/new.mobile.haml @@ -24,7 +24,6 @@ }); .col-md-6.col-md-offset-3#new_conversation_pane - #flash-messages .container-fluid.row %h3 = t("conversations.index.new_conversation") diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 618327572..55e4e7189 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -28,6 +28,9 @@ - if user_signed_in? = render "layouts/drawer" + .flash-messages-container + .flash-messages#flash-messages + #main{:role => "main"} - if current_page?(:activity_stream) %h3 diff --git a/spec/javascripts/mobile/mobile_alert_spec.js b/spec/javascripts/mobile/mobile_alert_spec.js index ffb789ef7..26e127d8b 100644 --- a/spec/javascripts/mobile/mobile_alert_spec.js +++ b/spec/javascripts/mobile/mobile_alert_spec.js @@ -26,4 +26,18 @@ describe("Diaspora.Mobile.Alert", function() { expect(Diaspora.Mobile.Alert._flash).toHaveBeenCalledWith("Oh noez!", "danger"); }); }); + + describe("handleAjaxError", function() { + it("shows a generic error if the connection failed", function() { + spyOn(Diaspora.Mobile.Alert, "error"); + Diaspora.Mobile.Alert.handleAjaxError({status: 0}); + expect(Diaspora.Mobile.Alert.error).toHaveBeenCalledWith(Diaspora.I18n.t("errors.connection")); + }); + + it("shows the error given in the responseText otherwise", function() { + spyOn(Diaspora.Mobile.Alert, "error"); + Diaspora.Mobile.Alert.handleAjaxError({status: 400, responseText: "some specific ajax error"}); + expect(Diaspora.Mobile.Alert.error).toHaveBeenCalledWith("some specific ajax error"); + }); + }); }); diff --git a/spec/javascripts/mobile/mobile_conversations_spec.js b/spec/javascripts/mobile/mobile_conversations_spec.js index 34281e27f..060a56950 100644 --- a/spec/javascripts/mobile/mobile_conversations_spec.js +++ b/spec/javascripts/mobile/mobile_conversations_spec.js @@ -4,6 +4,11 @@ describe("Diaspora.Mobile.Conversations", function() { Diaspora.Page = "ConversationsNew"; }); + afterEach(function() { + $(document).off("ajax:success", Diaspora.Mobile.Conversations.conversationCreateSuccess); + $(document).off("ajax:error", Diaspora.Mobile.Conversations.conversationCreateError); + }); + describe("conversationCreateSuccess", function() { it("is called when there was a successful ajax request for the conversation form", function() { spyOn(Diaspora.Mobile.Conversations, "conversationCreateSuccess"); @@ -43,10 +48,12 @@ describe("Diaspora.Mobile.Conversations", function() { }); it("shows a flash message", function() { - spyOn(Diaspora.Mobile.Alert, "error"); + spyOn(Diaspora.Mobile.Alert, "handleAjaxError").and.callThrough(); Diaspora.Mobile.Conversations.initialize(); - $("#new-conversation").trigger("ajax:error", [{responseText: "Oh noez! Something went wrong!"}]); - expect(Diaspora.Mobile.Alert.error).toHaveBeenCalledWith("Oh noez! Something went wrong!"); + var response = {status: 422, responseText: "Oh noez! Something went wrong!"}; + $("#new-conversation").trigger("ajax:error", response); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalledWith(response); + expect($("#flash-messages")).toHaveText("Oh noez! Something went wrong!"); }); }); }); From bc5848fe9eb01304ac0a7c535b89b7bab0a2ce2d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 26 Nov 2016 19:29:15 +0100 Subject: [PATCH 5/6] Use new ajax error handling for reshare failures --- .../javascripts/mobile/mobile_post_actions.js | 6 +----- spec/javascripts/mobile/mobile_post_actions_spec.js | 13 ++++--------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/mobile/mobile_post_actions.js b/app/assets/javascripts/mobile/mobile_post_actions.js index 56df0e533..f7064baef 100644 --- a/app/assets/javascripts/mobile/mobile_post_actions.js +++ b/app/assets/javascripts/mobile/mobile_post_actions.js @@ -99,11 +99,7 @@ Diaspora.Mobile.PostActions.toggleActive(link); }, error: function(response) { - if (response.status === 0) { - alert(Diaspora.I18n.t("errors.connection")); - } else { - alert(response.responseText); - } + Diaspora.Mobile.Alert.handleAjaxError(response); }, complete: function() { Diaspora.Mobile.PostActions.hideLoader(link); diff --git a/spec/javascripts/mobile/mobile_post_actions_spec.js b/spec/javascripts/mobile/mobile_post_actions_spec.js index 80d410ea3..c2e158202 100644 --- a/spec/javascripts/mobile/mobile_post_actions_spec.js +++ b/spec/javascripts/mobile/mobile_post_actions_spec.js @@ -198,7 +198,6 @@ describe("Diaspora.Mobile.PostActions", function(){ Diaspora.Mobile.PostActions.initialize(); this.reshareLink = $(".stream .reshare-action"); spyOn(window, "confirm").and.returnValue(true); - spyOn(window, "alert"); }); it("always calls showLoader before sending request and hideLoader after receiving response", function(){ @@ -223,16 +222,12 @@ describe("Diaspora.Mobile.PostActions", function(){ expect(Diaspora.Mobile.PostActions.toggleActive).toHaveBeenCalledWith(this.reshareLink); }); - it("pops an alert on server errors", function() { + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { + spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); this.reshareLink.click(); jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "reshare failed"}); - expect(window.alert).toHaveBeenCalledWith("reshare failed"); - }); - - it("pops an alert on network errors", function() { - this.reshareLink.click(); - jasmine.Ajax.requests.mostRecent().abort(); - expect(window.alert).toHaveBeenCalledWith(Diaspora.I18n.t("errors.connection")); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); + expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("reshare failed"); }); }); }); From d0e70ccd6a94a7f4402d4b8d54041008ad00919b Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Nov 2016 17:14:17 +0100 Subject: [PATCH 6/6] Use new ajax error handling for like, unlike and comment failures closes #7227 --- Changelog.md | 1 + .../javascripts/mobile/mobile_comments.js | 5 +- .../javascripts/mobile/mobile_post_actions.js | 6 ++ .../mobile/mobile_comments_spec.js | 70 ++++++++++++++----- .../mobile/mobile_post_actions_spec.js | 16 +++++ 5 files changed, 78 insertions(+), 20 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2c4896ef7..47c7e1646 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ * Increase the spacing above and below post contents [#7267](https://github.com/diaspora/diaspora/pull/7267) * Replace fileuploader-custom with FineUploader [#7083](https://github.com/diaspora/diaspora/pull/7083) * Always show mobile reaction counts [#7207](https://github.com/diaspora/diaspora/pull/7207) +* Refactor mobile alerts for error responses [#7227](https://github.com/diaspora/diaspora/pull/7227) ## Bug fixes * Fix background color of year on notifications page with dark theme [#7263](https://github.com/diaspora/diaspora/pull/7263) diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js index 55fdfb44d..0861ec0f2 100644 --- a/app/assets/javascripts/mobile/mobile_comments.js +++ b/app/assets/javascripts/mobile/mobile_comments.js @@ -50,8 +50,9 @@ $.post(form.attr("action") + "?format=mobile", form.serialize(), function(data){ Diaspora.Mobile.Comments.updateStream(form, data); - }, "html").fail(function(){ - Diaspora.Mobile.Comments.resetCommentBox(this); + }, "html").fail(function(response) { + Diaspora.Mobile.Alert.handleAjaxError(response); + Diaspora.Mobile.Comments.resetCommentBox(form); }); autosize($(".add-comment-switcher:not(.hidden) textarea")); diff --git a/app/assets/javascripts/mobile/mobile_post_actions.js b/app/assets/javascripts/mobile/mobile_post_actions.js index f7064baef..7df54d6a9 100644 --- a/app/assets/javascripts/mobile/mobile_post_actions.js +++ b/app/assets/javascripts/mobile/mobile_post_actions.js @@ -35,6 +35,9 @@ Diaspora.Mobile.PostActions.showLoader(link); }, success: onSuccess, + error: function(response) { + Diaspora.Mobile.Alert.handleAjaxError(response); + }, complete: function() { Diaspora.Mobile.PostActions.hideLoader(link); } @@ -61,6 +64,9 @@ Diaspora.Mobile.PostActions.showLoader(link); }, success: onSuccess, + error: function(response) { + Diaspora.Mobile.Alert.handleAjaxError(response); + }, complete: function() { Diaspora.Mobile.PostActions.hideLoader(link); } diff --git a/spec/javascripts/mobile/mobile_comments_spec.js b/spec/javascripts/mobile/mobile_comments_spec.js index d2405a4e6..602db13f6 100644 --- a/spec/javascripts/mobile/mobile_comments_spec.js +++ b/spec/javascripts/mobile/mobile_comments_spec.js @@ -1,8 +1,22 @@ describe("Diaspora.Mobile.Comments", function(){ + beforeEach(function() { + spec.loadFixture("aspects_index_mobile_post_with_comments"); + this.bottomBar = $(".bottom-bar").first(); + this.link = $(".stream .show-comments").first(); + }); + + describe("initialize", function() { + it("calls submitComment when the comment form has been submitted", function() { + spyOn(Diaspora.Mobile.Comments, "submitComment"); + Diaspora.Mobile.Comments.initialize(); + Diaspora.Mobile.Comments.showCommentBox($(".stream .comment-action").first()); + $(".stream .new_comment").first().submit(); + expect(Diaspora.Mobile.Comments.submitComment).toHaveBeenCalled(); + }); + }); + describe("toggleComments", function() { beforeEach(function() { - spec.loadFixture("aspects_index_mobile_post_with_comments"); - this.link = $(".stream .show-comments").first(); spyOn(Diaspora.Mobile.Comments, "showComments"); spyOn(Diaspora.Mobile.Comments, "hideComments"); }); @@ -30,9 +44,6 @@ describe("Diaspora.Mobile.Comments", function(){ describe("showUnloadedComments", function() { beforeEach(function() { - spec.loadFixture("aspects_index_mobile_post_with_comments"); - this.link = $(".stream .show-comments").first(); - this.bottomBar = this.link.closest(".bottom-bar").first(); this.commentActionLink = this.bottomBar.find("a.comment-action"); }); @@ -79,26 +90,51 @@ describe("Diaspora.Mobile.Comments", function(){ }); }); - describe("createComment", function () { + describe("submitComment", function() { beforeEach(function() { - spec.loadFixture("aspects_index_mobile_post_with_comments"); - var link = $(".stream .comment-action").first(); - Diaspora.Mobile.Comments.showCommentBox(link); - $(".stream .new_comment").submit(Diaspora.Mobile.Comments.submitComment); + Diaspora.Mobile.Comments.initialize(); + Diaspora.Mobile.Comments.showCommentBox($(".stream .comment-action").first()); }); it("doesn't submit an empty comment", function() { - var form = $(".stream .new_comment").first(); - spyOn(jQuery, "ajax"); - form.submit(); - expect(jQuery.ajax).not.toHaveBeenCalled(); + $(".stream .new_comment").first().submit(); + expect(jasmine.Ajax.requests.count()).toBe(0); + }); + + it("submits comments with text", function() { + $(".stream .new_comment textarea").val("comment text"); + $(".stream .new_comment").first().submit(); + expect(jasmine.Ajax.requests.mostRecent().data().text).toEqual(["comment text"]); + }); + + it("calls updateStream on success", function() { + spyOn(Diaspora.Mobile.Comments, "updateStream"); + $(".stream .new_comment textarea").val("comment text"); + $(".stream .new_comment").first().submit(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 200, responseText: "foo"}); + expect(Diaspora.Mobile.Comments.updateStream).toHaveBeenCalledWith($(".stream .new_comment").first(), "foo"); + }); + + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { + spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); + $(".stream .new_comment textarea").val("comment text"); + $(".stream .new_comment").first().submit(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"}); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); + expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! comment failed!"); + }); + + it("calls resetCommentBox on errors", function() { + spyOn(Diaspora.Mobile.Comments, "resetCommentBox"); + $(".stream .new_comment textarea").val("comment text"); + $(".stream .new_comment").first().submit(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! comment failed!"}); + expect(Diaspora.Mobile.Comments.resetCommentBox).toHaveBeenCalledWith($(".stream .new_comment").first()); }); }); describe("increaseReactionCount", function(){ beforeEach(function() { - spec.loadFixture("aspects_index_mobile_post_with_comments"); - this.bottomBar = $(".bottom-bar").first(); this.toggleReactionsLink = this.bottomBar.find(".show-comments").first(); }); @@ -123,8 +159,6 @@ describe("Diaspora.Mobile.Comments", function(){ describe("bottomBarLazy", function(){ beforeEach(function() { - spec.loadFixture("aspects_index_mobile_post_with_comments"); - this.bottomBar = $(".bottom-bar").first(); this.bottomBarLazy = Diaspora.Mobile.Comments.bottomBarLazy(this.bottomBar); }); diff --git a/spec/javascripts/mobile/mobile_post_actions_spec.js b/spec/javascripts/mobile/mobile_post_actions_spec.js index c2e158202..a33a29994 100644 --- a/spec/javascripts/mobile/mobile_post_actions_spec.js +++ b/spec/javascripts/mobile/mobile_post_actions_spec.js @@ -118,6 +118,14 @@ describe("Diaspora.Mobile.PostActions", function(){ expect(this.likeCounter.text()).toBe("0"); }); + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { + spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); + Diaspora.Mobile.PostActions.like(this.likeCounter, this.link); + jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! like failed!"}); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); + expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! like failed!"); + }); + it("activates link on success", function(){ spyOn(Diaspora.Mobile.PostActions, "toggleActive"); var data = this.link.data("url"); @@ -166,6 +174,14 @@ describe("Diaspora.Mobile.PostActions", function(){ expect(this.likeCounter.text()).toBe("1"); }); + it("lets Diaspora.Mobile.Alert handle AJAX errors", function() { + spyOn(Diaspora.Mobile.Alert, "handleAjaxError"); + Diaspora.Mobile.PostActions.unlike(this.likeCounter, this.link); + jasmine.Ajax.requests.mostRecent().respondWith({status: 400, responseText: "oh noez! unlike failed!"}); + expect(Diaspora.Mobile.Alert.handleAjaxError).toHaveBeenCalled(); + expect(Diaspora.Mobile.Alert.handleAjaxError.calls.argsFor(0)[0].responseText).toBe("oh noez! unlike failed!"); + }); + it("deactivates link on success", function(){ spyOn(Diaspora.Mobile.PostActions, "toggleActive"); var data = this.link.data("url");