Show Series counts on all Dashboard Tabs (#17513)

* implementation and tests

* refactor specs
This commit is contained in:
Arit Amana 2022-04-29 11:58:06 -04:00 committed by GitHub
parent 18a2ce4e51
commit 4b04d06adf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 4 deletions

View file

@ -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

View file

@ -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