From a6f700d4ef447f60985a932f06c41ac5735fb35d Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 19 Nov 2020 09:10:28 +1000 Subject: [PATCH] FIX: Show better error if no bookmarks found from search (#11284) See https://meta.discourse.org/t/no-results-for-bookmarks-search-confusing-message/169763 --- app/controllers/users_controller.rb | 4 +++- config/locales/server.en.yml | 1 + spec/requests/users_controller_spec.rb | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8beea25b2f2..d97ad5f71e4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1542,7 +1542,9 @@ class UsersController < ApplicationController if bookmark_list.bookmarks.empty? render json: { bookmarks: [], - no_results_help: I18n.t("user_activity.no_bookmarks.self") + no_results_help: I18n.t( + params[:q].present? ? "user_activity.no_bookmarks.search" : "user_activity.no_bookmarks.self" + ) } else page = params[:page].to_i + 1 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index e519c0f7b92..e753a048dc5 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -954,6 +954,7 @@ en: others: "No activity." no_bookmarks: self: "You have no bookmarked posts; bookmarks allow you to quickly refer to specific posts." + search: "No bookmarks found with the provided search query." others: "No bookmarks." no_likes_given: self: "You have not liked any posts." diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index bc0f0a054b5..be4b5eff8fe 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -4561,6 +4561,31 @@ describe UsersController do get "/u/#{bookmark3.user.username}/bookmarks.json" expect(response.status).to eq(403) end + + it "shows a helpful message if no bookmarks are found" do + bookmark1.destroy + bookmark2.destroy + bookmark3.destroy + sign_in(user) + get "/u/#{user.username}/bookmarks.json" + expect(response.status).to eq(200) + expect(response.parsed_body['bookmarks']).to eq([]) + expect(response.parsed_body['no_results_help']).to eq( + I18n.t('user_activity.no_bookmarks.self') + ) + end + + it "shows a helpful message if no bookmarks are found for the search" do + sign_in(user) + get "/u/#{user.username}/bookmarks.json", params: { + q: 'badsearch' + } + expect(response.status).to eq(200) + expect(response.parsed_body['bookmarks']).to eq([]) + expect(response.parsed_body['no_results_help']).to eq( + I18n.t('user_activity.no_bookmarks.search') + ) + end end def create_second_factor_security_key