File: user_toggles_subscription_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (96 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download
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
94
95
96
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "User toggles subscription", :js, feature_category: :team_planning do
  let(:project) { create(:project_empty_repo, :public) }
  let(:user) { create(:user) }
  let(:user2) { create(:user) }
  let(:issue) { create(:issue, project: project, author: user) }

  context 'user is not logged in' do
    before do
      stub_feature_flags(notifications_todos_buttons: false)
      visit(project_issue_path(project, issue))
    end

    it 'does not display the Notification toggle' do
      find('.detail-page-header-actions .gl-new-dropdown-toggle').click

      expect(page).not_to have_selector('.is-checked:not(.is-checked)')
    end
  end

  context 'user is logged in' do
    before do
      stub_feature_flags(notifications_todos_buttons: false)
      project.add_developer(user)
      sign_in(user)
      visit(project_issue_path(project, issue))
    end

    it 'unsubscribes from issue' do
      find('.detail-page-header-actions .gl-new-dropdown-toggle').click

      within_testid('notification-toggle') do
        subscription_button = find_by_testid('toggle-wrapper')

        # Check we're subscribed.
        expect(subscription_button).to have_css("button.is-checked")

        # Toggle subscription.
        subscription_button.find('button').click
        wait_for_requests

        # Check we're unsubscribed.
        expect(subscription_button).to have_css("button:not(.is-checked)")
      end
    end
  end

  context 'user is logged in without edit permission' do
    before do
      stub_feature_flags(notifications_todos_buttons: false)
      sign_in(user2)

      visit(project_issue_path(project, issue))
    end

    it 'subscribes to issue' do
      find('.detail-page-header-actions .gl-new-dropdown-toggle').click

      within_testid('notification-toggle') do
        subscription_button = find_by_testid('toggle-wrapper')

        # Check we're not subscribed.
        expect(subscription_button).to have_css("button:not(.is-checked)")

        # Toggle subscription.
        subscription_button.find('button').click
        wait_for_requests

        # Check we're subscribed.
        expect(subscription_button).to have_css("button.is-checked")
      end
    end
  end

  context 'with notifications_todos_buttons feature flag enabled' do
    before do
      stub_feature_flags(notifications_todos_buttons: true)
      sign_in(user2)

      visit(project_issue_path(project, issue))
    end

    it 'toggles subscription', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/435076' do
      subscription_button = find_by_testid('subscribe-button')

      expect(page).to have_selector("button[title='Notifications off']")
      subscription_button.click
      wait_for_requests

      expect(page).to have_selector("button[title='Notifications on']")
    end
  end
end