diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/dashboard/merge_requests_spec.rb | 6 | ||||
-rw-r--r-- | spec/frontend/commons/nav/user_merge_requests_spec.js | 15 | ||||
-rw-r--r-- | spec/helpers/dashboard_helper_spec.rb | 6 | ||||
-rw-r--r-- | spec/helpers/merge_requests_helper_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/charts_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 15 | ||||
-rw-r--r-- | spec/policies/project_policy_spec.rb | 34 | ||||
-rw-r--r-- | spec/services/merge_requests/update_service_spec.rb | 13 |
8 files changed, 83 insertions, 74 deletions
diff --git a/spec/features/dashboard/merge_requests_spec.rb b/spec/features/dashboard/merge_requests_spec.rb index 0e76b5478a1..26b376be660 100644 --- a/spec/features/dashboard/merge_requests_spec.rb +++ b/spec/features/dashboard/merge_requests_spec.rb @@ -110,6 +110,12 @@ RSpec.describe 'Dashboard Merge Requests' do visit merge_requests_dashboard_path(assignee_username: current_user.username) end + it 'includes assigned and reviewers in badge' do + expect(find('.merge-requests-count')).to have_content('3') + expect(find('.js-assigned-mr-count')).to have_content('2') + expect(find('.js-reviewer-mr-count')).to have_content('1') + end + it 'shows assigned merge requests' do expect(page).to have_content(assigned_merge_request.title) expect(page).to have_content(assigned_merge_request_from_fork.title) diff --git a/spec/frontend/commons/nav/user_merge_requests_spec.js b/spec/frontend/commons/nav/user_merge_requests_spec.js index 4da6d53557a..5f81067f84f 100644 --- a/spec/frontend/commons/nav/user_merge_requests_spec.js +++ b/spec/frontend/commons/nav/user_merge_requests_spec.js @@ -8,7 +8,7 @@ import Api from '~/api'; jest.mock('~/api'); const TEST_COUNT = 1000; -const MR_COUNT_CLASS = 'merge-requests-count'; +const MR_COUNT_CLASS = 'js-merge-requests-count'; describe('User Merge Requests', () => { let channelMock; @@ -24,7 +24,9 @@ describe('User Merge Requests', () => { newBroadcastChannelMock = jest.fn().mockImplementation(() => channelMock); global.BroadcastChannel = newBroadcastChannelMock; - setFixtures(`<div class="${MR_COUNT_CLASS}">0</div>`); + setFixtures( + `<div><div class="${MR_COUNT_CLASS}">0</div><div class="js-assigned-mr-count"></div><div class="js-reviewer-mr-count"></div></div>`, + ); }); const findMRCountText = () => document.body.querySelector(`.${MR_COUNT_CLASS}`).textContent; @@ -33,7 +35,10 @@ describe('User Merge Requests', () => { beforeEach(() => { Api.userCounts.mockReturnValue( Promise.resolve({ - data: { merge_requests: TEST_COUNT }, + data: { + assigned_merge_requests: TEST_COUNT, + review_requested_merge_requests: TEST_COUNT, + }, }), ); }); @@ -46,7 +51,7 @@ describe('User Merge Requests', () => { }); it('updates the top count of merge requests', () => { - expect(findMRCountText()).toEqual(TEST_COUNT.toLocaleString()); + expect(findMRCountText()).toEqual(Number(TEST_COUNT + TEST_COUNT).toLocaleString()); }); it('calls the API', () => { @@ -54,7 +59,7 @@ describe('User Merge Requests', () => { }); it('posts count to BroadcastChannel', () => { - expect(channelMock.postMessage).toHaveBeenCalledWith(TEST_COUNT); + expect(channelMock.postMessage).toHaveBeenCalledWith(TEST_COUNT + TEST_COUNT); }); }); diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/dashboard_helper_spec.rb index 65182dcb729..8a76771be0a 100644 --- a/spec/helpers/dashboard_helper_spec.rb +++ b/spec/helpers/dashboard_helper_spec.rb @@ -89,4 +89,10 @@ RSpec.describe DashboardHelper do it { is_expected.to eq(false) } end + + describe '#reviewer_mrs_dashboard_path' do + subject { helper.reviewer_mrs_dashboard_path } + + it { is_expected.to eq(merge_requests_dashboard_path(reviewer_username: user.username)) } + end end diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index 377e2c43a72..821faaab194 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -67,4 +67,37 @@ RSpec.describe MergeRequestsHelper do end end end + + describe '#user_merge_requests_counts' do + let(:user) do + double( + assigned_open_merge_requests_count: 1, + review_requested_open_merge_requests_count: 2 + ) + end + + subject { helper.user_merge_requests_counts } + + before do + allow(helper).to receive(:current_user).and_return(user) + end + + it "returns assigned, review requested and total merge request counts" do + expect(subject).to eq( + assigned: user.assigned_open_merge_requests_count, + review_requested: user.review_requested_open_merge_requests_count, + total: user.assigned_open_merge_requests_count + user.review_requested_open_merge_requests_count + ) + end + + context 'when merge_request_reviewers is disabled' do + before do + stub_feature_flags(merge_request_reviewers: false) + end + + it 'returns review_requested as 0' do + expect(subject[:review_requested]).to eq(0) + end + end + end end diff --git a/spec/lib/gitlab/ci/charts_spec.rb b/spec/lib/gitlab/ci/charts_spec.rb index c7869383dc4..cfc2019a89b 100644 --- a/spec/lib/gitlab/ci/charts_spec.rb +++ b/spec/lib/gitlab/ci/charts_spec.rb @@ -47,10 +47,6 @@ RSpec.describe Gitlab::Ci::Charts do subject { chart.to } - before do - create(:ci_empty_pipeline, project: project, duration: 120) - end - it 'includes the whole current day' do is_expected.to eq(Date.today.end_of_day) end @@ -62,37 +58,6 @@ RSpec.describe Gitlab::Ci::Charts do it 'uses %d %B as labels format' do expect(chart.labels).to include(chart.from.strftime('%d %B')) end - - it 'returns count of pipelines run each day in the current week' do - expect(chart.total).to contain_exactly(0, 0, 0, 0, 0, 0, 0, 1) - end - end - - context 'weekchart_non_utc' do - today = Date.today - end_of_today = Time.use_zone(Time.find_zone('Asia/Dubai')) { today.end_of_day } - - let(:project) { create(:project) } - let(:chart) do - allow(Date).to receive(:today).and_return(today) - allow(today).to receive(:end_of_day).and_return(end_of_today) - Gitlab::Ci::Charts::WeekChart.new(project) - end - - subject { chart.total } - - before do - create(:ci_empty_pipeline, project: project, duration: 120) - end - - it 'uses a non-utc time zone for range times' do - expect(chart.to.zone).to eq(end_of_today.zone) - expect(chart.from.zone).to eq(end_of_today.zone) - end - - it 'returns count of pipelines run each day in the current week' do - is_expected.to contain_exactly(0, 0, 0, 0, 0, 0, 0, 1) - end end context 'pipeline_times' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fb05c9e8052..3c5bc125011 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4084,6 +4084,7 @@ RSpec.describe User do cache_mock = double expect(cache_mock).to receive(:delete).with(['users', user.id, 'assigned_open_merge_requests_count']) + expect(cache_mock).to receive(:delete).with(['users', user.id, 'review_requested_open_merge_requests_count']) allow(Rails).to receive(:cache).and_return(cache_mock) @@ -4163,6 +4164,20 @@ RSpec.describe User do end end + describe '#review_requested_open_merge_requests_count' do + it 'returns number of open merge requests from non-archived projects' do + user = create(:user) + project = create(:project, :public) + archived_project = create(:project, :public, :archived) + + create(:merge_request, source_project: project, author: user, reviewers: [user]) + create(:merge_request, :closed, source_project: project, author: user, reviewers: [user]) + create(:merge_request, source_project: archived_project, author: user, reviewers: [user]) + + expect(user.review_requested_open_merge_requests_count(force: true)).to eq 1 + end + end + describe '#assigned_open_issues_count' do it 'returns number of open issues from non-archived projects' do user = create(:user) diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index 7f6c47d675b..c21d3b0939f 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -401,40 +401,6 @@ RSpec.describe ProjectPolicy do end end - describe 'bot_log_in' do - let(:bot_user) { create(:user, :project_bot) } - let(:project) { private_project } - - context 'when bot is in project and is not blocked' do - before do - project.add_maintainer(bot_user) - end - - it 'is a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_truthy - end - end - - context 'when project bot is invalid' do - context 'when bot is not in project' do - it 'is not a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_falsy - end - end - - context 'when bot user is blocked' do - before do - project.add_maintainer(bot_user) - bot_user.block! - end - - it 'is not a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_falsy - end - end - end - end - context 'support bot' do let(:current_user) { User.support_bot } diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index be802c430ff..fdda1515cce 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -521,6 +521,19 @@ RSpec.describe MergeRequests::UpdateService, :mailer do should_email(user2) should_email(user3) end + + it 'updates open merge request counter for reviewers', :use_clean_rails_memory_store_caching do + merge_request.reviewers = [user3] + + # Cache them to ensure the cache gets invalidated on update + expect(user2.review_requested_open_merge_requests_count).to eq(0) + expect(user3.review_requested_open_merge_requests_count).to eq(1) + + update_merge_request(reviewer_ids: [user2.id]) + + expect(user2.review_requested_open_merge_requests_count).to eq(1) + expect(user3.review_requested_open_merge_requests_count).to eq(0) + end end context 'when the milestone is removed' do |