summaryrefslogtreecommitdiff
path: root/spec/features/projects/labels/subscription_spec.rb
blob: 58421e11e0a468d6554ac9450914636dc447eb59 (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
require 'spec_helper'

feature 'Labels subscription', feature: true do
  let(:user)     { create(:user) }
  let(:group)    { create(:group) }
  let(:project)  { create(:empty_project, :public, namespace: group) }
  let!(:bug)     { create(:label, project: project, title: 'bug') }
  let!(:feature) { create(:group_label, group: group, title: 'feature') }

  context 'when signed in' do
    before do
      project.team << [user, :developer]
      sign_in user
    end

    scenario 'users can subscribe/unsubscribe to labels', js: true do
      visit project_labels_path(project)

      expect(page).to have_content('bug')
      expect(page).to have_content('feature')

      within "#project_label_#{bug.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

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

        click_link_on_dropdown('Group level')

        expect(page).not_to have_selector('.dropdown-group-label')
        expect(page).to have_button 'Unsubscribe'

        click_button 'Unsubscribe'

        expect(page).to have_selector('.dropdown-group-label')

        click_link_on_dropdown('Project level')

        expect(page).not_to have_selector('.dropdown-group-label')
        expect(page).to have_button 'Unsubscribe'
      end
    end
  end

  context 'when not signed in' do
    it 'users can not subscribe/unsubscribe to labels' do
      visit project_labels_path(project)

      expect(page).to have_content 'bug'
      expect(page).to have_content 'feature'
      expect(page).not_to have_button('Subscribe')
      expect(page).not_to have_selector('.dropdown-group-label')
    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
end