issuables_counter_spec.rb 1.56 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Navigation bar counter', :use_clean_rails_memory_store_caching do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:empty_project, namespace: user.namespace) }
6 7
  let(:issue) { create(:issue, project: project) }
  let(:merge_request) { create(:merge_request, source_project: project) }
8 9

  before do
10
    issue.assignees = [user]
11
    merge_request.update(assignee: user)
12
    sign_in(user)
13 14 15
  end

  it 'reflects dashboard issues count' do
16
    visit issues_path
17

18
    expect_counters('issues', '1')
19

20
    issue.assignees = []
21

22
    user.invalidate_cache_counts
23

24 25 26 27 28
    Timecop.travel(3.minutes.from_now) do
      visit issues_path

      expect_counters('issues', '0')
    end
29 30 31
  end

  it 'reflects dashboard merge requests count' do
32
    visit merge_requests_path
33

34
    expect_counters('merge_requests', '1')
35

36
    merge_request.update(assignee: nil)
37

38 39
    user.invalidate_cache_counts

40 41 42 43 44 45 46 47 48 49 50 51 52
    Timecop.travel(3.minutes.from_now) do
      visit merge_requests_path

      expect_counters('merge_requests', '0')
    end
  end

  def issues_path
    issues_dashboard_path(assignee_id: user.id)
  end

  def merge_requests_path
    merge_requests_dashboard_path(assignee_id: user.id)
53 54 55
  end

  def expect_counters(issuable_type, count)
56
    dashboard_count = find('.nav-links li.active')
57
    nav_count = find(".dashboard-shortcuts-#{issuable_type}")
58
    header_count = find(".header-content .#{issuable_type.tr('_', '-')}-count")
59

60
    expect(dashboard_count).to have_content(count)
61 62
    expect(nav_count).to have_content(count)
    expect(header_count).to have_content(count)
63 64
  end
end