Welcome to mirror list, hosted at ThFree Co, Russian Federation.

abuse_report_spec.rb « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1df5c2d6f05ee0ff430c7a62ec5ce3fe24fc95b (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Abuse reports', :js, feature_category: :insider_threat do
  let_it_be(:abusive_user) { create(:user, :no_super_sidebar) }

  let_it_be(:reporter1) { create(:user, :no_super_sidebar) }

  let_it_be(:project) { create(:project, :public, :repository) }
  let_it_be(:issue) { create(:issue, project: project, author: abusive_user) }

  before do
    sign_in(reporter1)
    stub_feature_flags(moved_mr_sidebar: false)
  end

  describe 'report abuse to administrator' do
    shared_examples 'cancel report' do
      it 'redirects backs to user profile when cancel button is clicked' do
        fill_and_submit_abuse_category_form

        click_link 'Cancel'

        expect(page).to have_current_path(user_path(abusive_user))
      end
    end

    context 'when reporting an issue for abuse' do
      before do
        visit project_issue_path(project, issue)

        click_button 'Issue actions'
      end

      it_behaves_like 'reports the user with an abuse category'

      it 'redirects backs to the issue when cancel button is clicked' do
        fill_and_submit_abuse_category_form

        click_link 'Cancel'

        expect(page).to have_current_path(project_issue_path(project, issue))
      end
    end

    context 'when reporting an incident for abuse' do
      let_it_be(:incident) { create(:incident, project: project, author: abusive_user) }

      before do
        visit incident_project_issues_path(project, incident)
        click_button 'Incident actions'
      end

      it_behaves_like 'reports the user with an abuse category'
    end

    describe 'when user_profile_overflow_menu FF turned on' do
      context 'when reporting a user profile for abuse' do
        let_it_be(:reporter2) { create(:user, :no_super_sidebar) }

        before do
          visit user_path(abusive_user)
          find_by_testid('base-dropdown-toggle').click
        end

        it_behaves_like 'reports the user with an abuse category'

        it 'allows the reporter to report the same user for different abuse categories' do
          visit user_path(abusive_user)

          find_by_testid('base-dropdown-toggle').click
          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'

          visit user_path(abusive_user)

          find_by_testid('base-dropdown-toggle').click
          fill_and_submit_abuse_category_form("They're being offensive or abusive.")
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'
        end

        it 'allows multiple users to report the same user' do
          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'

          gitlab_sign_out
          gitlab_sign_in(reporter2)

          visit user_path(abusive_user)

          find_by_testid('base-dropdown-toggle').click
          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'
        end

        it_behaves_like 'cancel report'
      end
    end

    describe 'when user_profile_overflow_menu FF turned off' do
      context 'when reporting a user profile for abuse' do
        let_it_be(:reporter2) { create(:user, :no_super_sidebar) }

        before do
          stub_feature_flags(user_profile_overflow_menu_vue: false)
          visit user_path(abusive_user)
        end

        it_behaves_like 'reports the user with an abuse category'

        it 'allows the reporter to report the same user for different abuse categories' do
          visit user_path(abusive_user)

          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'

          visit user_path(abusive_user)

          fill_and_submit_abuse_category_form("They're being offensive or abusive.")
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'
        end

        it 'allows multiple users to report the same user' do
          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'

          gitlab_sign_out
          gitlab_sign_in(reporter2)

          visit user_path(abusive_user)

          fill_and_submit_abuse_category_form
          fill_and_submit_report_abuse_form

          expect(page).to have_content 'Thank you for your report'
        end

        it_behaves_like 'cancel report'
      end
    end

    context 'when reporting an merge request for abuse' do
      let_it_be(:merge_request) { create(:merge_request, source_project: project, author: abusive_user) }

      before do
        visit project_merge_request_path(project, merge_request)
        find_by_testid('merge-request-actions').click
      end

      it_behaves_like 'reports the user with an abuse category'
    end

    context 'when reporting a comment' do
      let_it_be(:issue) { create(:issue, project: project, author: abusive_user) }
      let_it_be(:comment) do
        create(:discussion_note_on_issue, author: abusive_user, project: project, noteable: issue, note: 'some note')
      end

      before do
        visit project_issue_path(project, issue)
        find('.more-actions-toggle button').click
      end

      it_behaves_like 'reports the user with an abuse category'
    end
  end

  # TODO: implement tests before the FF "user_profile_overflow_menu_vue" is turned on
  # See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/122971
  # Related Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/416983

  private

  def fill_and_submit_abuse_category_form(category = "They're posting spam.")
    click_button 'Report abuse'

    choose category
    click_button 'Next'
  end

  def fill_and_submit_report_abuse_form
    fill_in 'abuse_report_message', with: 'This user sends spam'
    click_button 'Send report'
  end
end