diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index f5ef4f6f3..d7cbd3fa9 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -51,27 +51,32 @@ class DashboardsController < ApplicationController def following_tags fetch_and_authorize_user @followed_tags = follows_for(user: @user, type: "ActsAsTaggableOn::Tag", order_by: :points) + @collections_count = collections_count(@user) end def following_users fetch_and_authorize_user @follows = follows_for(user: @user, type: "User") + @collections_count = collections_count(@user) end def following_organizations fetch_and_authorize_user @followed_organizations = follows_for(user: @user, type: "Organization") + @collections_count = collections_count(@user) end def following_podcasts fetch_and_authorize_user @followed_podcasts = follows_for(user: @user, type: "Podcast") + @collections_count = collections_count(@user) end def followers fetch_and_authorize_user @follows = Follow.followable_user(@user.id) .includes(:follower).order(created_at: :desc).limit(follows_limit) + @collections_count = collections_count(@user) end def analytics @@ -125,4 +130,8 @@ class DashboardsController < ApplicationController per_page end + + def collections_count(user) + user.collections.non_empty.count + end end diff --git a/spec/system/dashboards/user_visits_dashboard_spec.rb b/spec/system/dashboards/user_visits_dashboard_spec.rb index aef259c64..7cbdd67c4 100644 --- a/spec/system/dashboards/user_visits_dashboard_spec.rb +++ b/spec/system/dashboards/user_visits_dashboard_spec.rb @@ -3,12 +3,14 @@ require "rails_helper" RSpec.describe "Dashboard", type: :system, js: true do let(:user) { create(:user) } let(:listing) { create(:listing) } - - before do - sign_in user - end + let(:collection) { create(:collection, :with_articles) } + let(:collection_user) { collection.user } context "when looking at analytics counters" do + before do + sign_in user + end + it "shows the count of unspent credits" do Credit.add_to(user, 2) @@ -27,4 +29,29 @@ RSpec.describe "Dashboard", type: :system, js: true do end end end + + context "when looking at actions panel" do + before do + sign_in collection_user + end + + it "shows the user-collections count on current dashboard tab", :aggregate_failures do + dashboard_paths = [ + dashboard_path, + dashboard_following_path, + dashboard_following_tags_path, + dashboard_following_users_path, + dashboard_following_organizations_path, + dashboard_following_podcasts_path, + ] + + dashboard_paths.each do |path| + visit path + + within "main#main-content nav" do + expect(page).to have_text(/Series\n1/) + end + end + end + end end