summaryrefslogtreecommitdiff
path: root/spec/features/groups/labels/subscription_spec.rb
blob: cbccf4f38807c3b3fc3e6301262bdd38294c3238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true

require 'spec_helper'

describe 'Labels subscription' do
  let(:user)     { create(:user) }
  let(:group)    { create(:group) }
  let!(:label1)  { create(:group_label, group: group, title: 'foo') }
  let!(:label2)  { create(:group_label, group: group, title: 'bar') }

  context 'when signed in' do
    before do
      group.add_developer(user)
      gitlab_sign_in user
    end

    it 'users can subscribe/unsubscribe to group labels', :js do
      visit group_labels_path(group)

      expect(page).to have_content(label1.title)

      within "#group_label_#{label1.id}" do
        expect(page).not_to have_button 'Unsubscribe'

        click_button 'Subscribe'

        expect(page).not_to have_button 'Subscribe'
        expect(page).to have_button 'Unsubscribe'

        click_button 'Unsubscribe'

        expect(page).to have_button 'Subscribe'
        expect(page).not_to have_button 'Unsubscribe'
      end
    end

    context 'subscription filter' do
      before do
        visit group_labels_path(group)
      end

      it 'shows only subscribed labels' do
        label1.subscribe(user)

        click_subscribed_tab

        page.within('.labels-container') do
          expect(page).to have_content label1.title
        end
      end

      it 'shows no subscribed labels message' do
        click_subscribed_tab

        page.within('.labels-container') do
          expect(page).not_to have_content label1.title
          expect(page).to have_content('You do not have any subscriptions yet')
        end
      end
    end
  end

  context 'when not signed in' do
    before do
      visit group_labels_path(group)
    end

    it 'users can not subscribe/unsubscribe to labels' do
      expect(page).to have_content label1.title
      expect(page).not_to have_button('Subscribe')
    end

    it 'does not show subscribed tab' do
      page.within('.nav-tabs') do
        expect(page).not_to have_link 'Subscribed'
      end
    end
  end

  def click_link_on_dropdown(text)
    find('.dropdown-group-label').click

    page.within('.dropdown-group-label') do
      find('a.js-subscribe-button', text: text).click
    end
  end

  def click_subscribed_tab
    page.within('.nav-tabs') do
      click_link 'Subscribed'
    end
  end
end