summaryrefslogtreecommitdiff
path: root/spec/features/projects/issues/email_participants_spec.rb
blob: fdfd926b763ecc943e770e0e3ffe3589025f2fd6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'viewing an issue', :js, feature_category: :issue_email_participants do
  let_it_be(:user) { create(:user) }
  let_it_be(:non_member) { create(:user) }
  let_it_be(:project) { create(:project, :public) }
  let_it_be_with_refind(:issue) { create(:issue, project: project) }
  let_it_be(:note) { create(:note_on_issue, project: project, noteable: issue) }
  let_it_be(:participants) { create_list(:issue_email_participant, 4, issue: issue) }

  before do
    project.add_reporter(user)
  end

  shared_examples 'email participants warning' do |selector|
    it 'shows the correct message' do
      expect(find(selector)).to have_content(", and 1 more will be notified of your comment")
    end
  end

  shared_examples 'email participants warning in all editors' do
    context 'for a new note' do
      it_behaves_like 'email participants warning', '.new-note'
    end

    context 'for a reply form' do
      before do
        find('.js-reply-button').click
      end

      it_behaves_like 'email participants warning', '.note-edit-form'
    end
  end

  context 'when issue is confidential' do
    before do
      issue.update!(confidential: true)
      sign_in(user)
      visit project_issue_path(project, issue)
    end

    it_behaves_like 'email participants warning in all editors'
  end

  context 'when issue is not confidential' do
    context 'with signed in user' do
      context 'when user has no role in project' do
        before do
          sign_in(non_member)
          visit project_issue_path(project, issue)
        end

        it_behaves_like 'email participants warning in all editors'
      end

      context 'when user has (at least) reporter role in project' do
        before do
          sign_in(user)
          visit project_issue_path(project, issue)
        end

        it_behaves_like 'email participants warning in all editors'
      end
    end
  end
end