2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Navigation bar counter', :use_clean_rails_memory_store_caching do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, namespace: user.namespace) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
before do
|
|
|
|
issue.assignees = [user]
|
|
|
|
merge_request.update!(assignees: [user])
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it 'reflects dashboard issues count' do
|
|
|
|
visit issues_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect_counters('issues', '1', n_("%d assigned issue", "%d assigned issues", 1) % 1)
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
issue.assignees = []
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
user.invalidate_cache_counts
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
travel_to(3.minutes.from_now) do
|
|
|
|
visit issues_path
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect_counters('issues', '0', n_("%d assigned issue", "%d assigned issues", 0) % 0)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it 'reflects dashboard merge requests count', :js do
|
|
|
|
visit merge_requests_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect_counters('merge_requests', '1', n_("%d merge request", "%d merge requests", 1) % 1)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
merge_request.update!(assignees: [])
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
user.invalidate_cache_counts
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
travel_to(3.minutes.from_now) do
|
|
|
|
visit merge_requests_path
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect_counters('merge_requests', '0', n_("%d merge request", "%d merge requests", 0) % 0)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_path
|
2019-02-15 15:39:39 +05:30
|
|
|
issues_dashboard_path(assignee_username: user.username)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests_path
|
2019-02-15 15:39:39 +05:30
|
|
|
merge_requests_dashboard_path(assignee_username: user.username)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
def expect_counters(issuable_type, count, badge_label)
|
2021-11-18 22:05:49 +05:30
|
|
|
dashboard_count = find('.gl-tabs-nav li a.active')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dashboard_count).to have_content(count)
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_css(".dashboard-shortcuts-#{issuable_type}", visible: :all, text: count)
|
|
|
|
expect(page).to have_css("span[aria-label='#{badge_label}']", visible: :all, text: count)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|