Skip to content
Snippets Groups Projects
Commit 6ab71599 authored by 🤖 GitLab Bot 🤖's avatar 🤖 GitLab Bot 🤖
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 8cc2cd21
No related branches found
No related tags found
No related merge requests found
Showing
with 164 additions and 535 deletions
......@@ -490,7 +490,11 @@ export default {
>
<span class="gl-display-inline-flex" :class="{ 'gl-rotate-90': list.collapsed }">
<gl-tooltip :target="() => $refs.itemCount" :title="itemsTooltipLabel" />
<span ref="itemCount" class="gl-display-inline-flex gl-align-items-center">
<span
ref="itemCount"
class="gl-display-inline-flex gl-align-items-center"
data-testid="item-count"
>
<gl-icon class="gl-mr-2" :name="countIcon" :size="14" />
<item-count
v-if="!isLoading"
......
......@@ -109,9 +109,9 @@ export function updateEpicsCount({
epicBoardList: {
...epicBoardList,
metadata: {
...epicBoardList.metadata,
epicsCount: epicBoardList.metadata.epicsCount - 1,
totalWeight: epicBoardList.metadata.totalWeight - epicWeight,
...epicBoardList.metadata,
},
},
}),
......@@ -127,9 +127,9 @@ export function updateEpicsCount({
epicBoardList: {
...epicBoardList,
metadata: {
...epicBoardList.metadata,
epicsCount: epicBoardList.metadata.epicsCount + 1,
totalWeight: epicBoardList.metadata.totalWeight + epicWeight,
...epicBoardList.metadata,
},
},
}),
......
import $ from 'jquery';
import { parseBoolean } from '~/lib/utils/common_utils';
import { truncate } from '~/lib/utils/text_utility';
const MAX_MESSAGE_LENGTH = 500;
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
export default class AbuseReports {
constructor() {
$(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
$(document)
.off('click', MESSAGE_CELL_SELECTOR)
.on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation);
}
truncateLongMessage() {
const $messageCellElement = $(this);
const reportMessage = $messageCellElement.text();
if (reportMessage.length > MAX_MESSAGE_LENGTH) {
$messageCellElement.data('originalMessage', reportMessage);
$messageCellElement.data('messageTruncated', 'true');
$messageCellElement.text(truncate(reportMessage, MAX_MESSAGE_LENGTH));
}
}
toggleMessageTruncation() {
const $messageCellElement = $(this);
const originalMessage = $messageCellElement.data('originalMessage');
if (!originalMessage) return;
if (parseBoolean($messageCellElement.data('messageTruncated'))) {
$messageCellElement.data('messageTruncated', 'false');
$messageCellElement.text(originalMessage);
} else {
$messageCellElement.data('messageTruncated', 'true');
$messageCellElement.text(truncate(originalMessage, MAX_MESSAGE_LENGTH));
}
}
}
import { initAbuseReportsApp } from '~/admin/abuse_reports';
import initDeprecatedRemoveRowBehavior from '~/behaviors/deprecated_remove_row_behavior';
import UsersSelect from '~/users_select';
import AbuseReports from './abuse_reports';
new AbuseReports(); /* eslint-disable-line no-new */
new UsersSelect(); /* eslint-disable-line no-new */
initDeprecatedRemoveRowBehavior();
initAbuseReportsApp();
......@@ -3,8 +3,8 @@
class Admin::AbuseReportsController < Admin::ApplicationController
feature_category :insider_threat
before_action :set_status_param, only: :index, if: -> { Feature.enabled?(:abuse_reports_list) }
before_action :find_abuse_report, only: [:show, :update, :moderate_user, :destroy]
before_action :set_status_param, only: :index
before_action :find_abuse_report, only: [:show, :moderate_user, :update, :destroy]
before_action only: :show do
push_frontend_feature_flag(:abuse_report_labels)
end
......
......@@ -27,30 +27,16 @@ def execute
private
def filter_reports
if Feature.disabled?(:abuse_reports_list)
filter_by_user_id
return
end
filter_by_status
filter_by_user
filter_by_reporter
filter_by_category
end
def filter_by_user_id
return unless params[:user_id].present?
@reports = @reports.by_user_id(params[:user_id])
end
def filter_by_status
return unless params[:status].present?
status = params[:status]
status = STATUS_OPEN unless status.in?(AbuseReport.statuses.keys)
case status
case status_filter
when 'open'
@reports = @reports.open
when 'closed'
......@@ -92,11 +78,6 @@ def sort_key
end
def sort_reports
if Feature.disabled?(:abuse_reports_list)
@reports = @reports.with_order_id_desc
return
end
# let sub_query in aggregate_reports do the sorting if sorting by number of reports
return if sort_key.in?(SORT_BY_COUNT)
......@@ -107,15 +88,6 @@ def find_user_id(username)
User.by_username(username).pick(:id)
end
def status_open?
return unless Feature.enabled?(:abuse_reports_list) && params[:status].present?
status = params[:status]
status = STATUS_OPEN unless status.in?(AbuseReport.statuses.keys)
status == STATUS_OPEN
end
def aggregate_reports
if status_open?
sort_by_count = sort_key.in?(SORT_BY_COUNT)
......@@ -124,4 +96,19 @@ def aggregate_reports
@reports
end
def status_filter
@status_filter ||=
if params[:status].in?(AbuseReport.statuses.keys)
params[:status]
else
STATUS_OPEN
end
end
def status_open?
return false if params[:status].blank?
status_filter == STATUS_OPEN
end
end
- reporter = abuse_report.reporter
- user = abuse_report.user
%tr
%th.d-block.d-sm-none
%strong= _('User')
%td
- if user
= link_to user.name, user
.light.small
= html_escape(_('Joined %{time_ago}')) % { time_ago: time_ago_with_tooltip(user.created_at).html_safe }
- else
= _('(removed)')
%td
- if reporter
%strong.subheading.d-block.d-sm-none
= _('Reported by %{reporter}').html_safe % { reporter: reporter ? link_to(reporter.name, reporter) : _('(removed)') }
.light.gl-display-none.gl-sm-display-block
= link_to(reporter.name, reporter)
.light.small
= time_ago_with_tooltip(abuse_report.created_at)
- else
= _('(removed)')
%td
%strong.subheading.d-block.d-sm-none
= _('Message')
.message
= markdown_field(abuse_report, :message)
%td
- if user && user != current_user
= render Pajamas::ButtonComponent.new(href: admin_abuse_report_path(abuse_report, remove_user: true), variant: :danger, block: true, button_options: { data: { confirm: _("USER %{user} WILL BE REMOVED! Are you sure?") % { user: user.name }, confirm_btn_variant: "danger", remote: true, method: :delete }, class: "js-remove-tr" }) do
= _('Remove user & report')
- if user.blocked?
= render Pajamas::ButtonComponent.new(href: block_admin_user_path(user), block: true, disabled: true, button_options: { data: { confirm: _('USER WILL BE BLOCKED! Are you sure?'), method: :put } }) do
= _('Already blocked')
- else
= render Pajamas::ButtonComponent.new(href: block_admin_user_path(user), block: true, button_options: { data: { confirm: _('USER WILL BE BLOCKED! Are you sure?'), method: :put } }) do
= _('Block user')
= render Pajamas::ButtonComponent.new(href: [:admin, abuse_report], block: true, button_options: { data: { remote: true, method: :delete }, class: "js-remove-tr" }) do
= _('Remove report')
......@@ -2,35 +2,5 @@
%h1.page-title.gl-font-size-h-display= _('Abuse Reports')
- if Feature.enabled?(:abuse_reports_list)
#js-abuse-reports-list-app{ data: abuse_reports_list_data(@abuse_reports) }
= gl_loading_icon(css_class: 'gl-my-5', size: 'md')
- else
.row-content-block.second-block
= form_tag admin_abuse_reports_path, method: :get, class: 'filter-form' do
.filter-categories.flex-fill
.filter-item.inline
= dropdown_tag(user_dropdown_label(params[:user_id], 'User'),
options: { toggle_class: 'js-filter-submit js-user-search',
title: _('Filter by user'), filter: true, filterInput: 'input#user-search',
dropdown_class: 'dropdown-menu-selectable dropdown-menu-user js-filter-submit',
placeholder: _('Search users'),
data: { current_user: true, field_name: 'user_id' }})
.abuse-reports
- if @abuse_reports.present?
.table-holder
%table.table.responsive-table
%thead.d-none.d-md-table-header-group
%tr
%th= _('User')
%th= _('Reported by')
%th.wide= _('Message')
%th= _('Action')
= render @abuse_reports
= paginate @abuse_reports, theme: 'gitlab'
- else
.empty-state
.text-center
%h4= _("There are no abuse reports!")
%h3= emoji_icon('tada')
#js-abuse-reports-list-app{ data: abuse_reports_list_data(@abuse_reports) }
= gl_loading_icon(css_class: 'gl-my-5', size: 'md')
---
name: abuse_reports_list
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/110205
rollout_issue_url:
milestone: '15.10'
type: development
group: group::anti-abuse
default_enabled: false
......@@ -20149,9 +20149,6 @@ msgstr ""
msgid "Filter by test cases that are currently open."
msgstr ""
 
msgid "Filter by user"
msgstr ""
msgid "Filter parameters are not valid. Make sure that the end date is after the start date."
msgstr ""
 
......@@ -27333,9 +27330,6 @@ msgstr ""
msgid "Join your team on GitLab and contribute to an existing project"
msgstr ""
 
msgid "Joined %{time_ago}"
msgstr ""
msgid "Joined %{user_created_time}"
msgstr ""
 
......@@ -39234,9 +39228,6 @@ msgstr ""
msgid "Remove priority"
msgstr ""
 
msgid "Remove report"
msgstr ""
msgid "Remove reviewer"
msgstr ""
 
......@@ -39261,9 +39252,6 @@ msgstr ""
msgid "Remove user"
msgstr ""
 
msgid "Remove user & report"
msgstr ""
msgid "Remove user from group"
msgstr ""
 
......@@ -39543,12 +39531,6 @@ msgstr ""
msgid "Reported %{timeAgo} by %{reportedBy}"
msgstr ""
 
msgid "Reported by"
msgstr ""
msgid "Reported by %{reporter}"
msgstr ""
msgid "Reporter"
msgstr ""
 
......@@ -47675,9 +47657,6 @@ msgstr ""
msgid "There are no Spam Logs"
msgstr ""
 
msgid "There are no abuse reports!"
msgstr ""
msgid "There are no approval rules for the given `represent_as` parameter. Use a valid User/Group/Role name instead."
msgstr ""
 
......@@ -50112,9 +50091,6 @@ msgstr ""
msgid "USER %{user_name} WILL BE REMOVED! Are you sure?"
msgstr ""
 
msgid "USER %{user} WILL BE REMOVED! Are you sure?"
msgstr ""
msgid "USER WILL BE BLOCKED! Are you sure?"
msgstr ""
 
......@@ -11,291 +11,195 @@
let_it_be(:closed_report) { create(:abuse_report, :closed, user: user, category: 'spam') }
describe 'as an admin' do
include FilteredSearchHelpers
before do
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
end
context 'when abuse_reports_list feature flag is enabled' do
include FilteredSearchHelpers
before do
visit admin_abuse_reports_path
end
let(:abuse_report_row_selector) { '[data-testid="abuse-report-row"]' }
it 'only includes open reports by default' do
expect_displayed_reports_count(2)
expect_report_shown(open_report, open_report2)
within '[data-testid="abuse-reports-filtered-search-bar"]' do
expect(page).to have_content 'Status = Open'
end
end
it 'can be filtered by status, user, reporter, and category', :aggregate_failures do
# filter by status
filter %w[Status Closed]
expect_displayed_reports_count(1)
expect_report_shown(closed_report)
expect_report_not_shown(open_report, open_report2)
filter %w[Status Open]
expect_displayed_reports_count(2)
expect_report_shown(open_report, open_report2)
expect_report_not_shown(closed_report)
# filter by user
filter(['User', open_report2.user.username])
expect_displayed_reports_count(1)
expect_report_shown(open_report2)
expect_report_not_shown(open_report, closed_report)
visit admin_abuse_reports_path
end
# filter by reporter
filter(['Reporter', open_report.reporter.username])
let(:abuse_report_row_selector) { '[data-testid="abuse-report-row"]' }
expect_displayed_reports_count(1)
expect_report_shown(open_report)
expect_report_not_shown(open_report2, closed_report)
it 'only includes open reports by default' do
expect_displayed_reports_count(2)
# filter by category
filter(['Category', open_report2.category])
expect_report_shown(open_report, open_report2)
expect_displayed_reports_count(1)
expect_report_shown(open_report2)
expect_report_not_shown(open_report, closed_report)
within '[data-testid="abuse-reports-filtered-search-bar"]' do
expect(page).to have_content 'Status = Open'
end
end
it 'can be sorted by created_at and updated_at in desc and asc order', :aggregate_failures do
sort_by 'Created date'
# created_at desc
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(report_text(open_report))
# created_at asc
toggle_sort_direction
expect(report_rows[0].text).to include(report_text(open_report))
expect(report_rows[1].text).to include(report_text(open_report2))
it 'can be filtered by status, user, reporter, and category', :aggregate_failures do
# filter by status
filter %w[Status Closed]
expect_displayed_reports_count(1)
expect_report_shown(closed_report)
expect_report_not_shown(open_report, open_report2)
# updated_at asc
sort_by 'Updated date'
filter %w[Status Open]
expect_displayed_reports_count(2)
expect_report_shown(open_report, open_report2)
expect_report_not_shown(closed_report)
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(report_text(open_report))
# filter by user
filter(['User', open_report2.user.username])
# updated_at desc
toggle_sort_direction
expect_displayed_reports_count(1)
expect_report_shown(open_report2)
expect_report_not_shown(open_report, closed_report)
expect(report_rows[0].text).to include(report_text(open_report))
expect(report_rows[1].text).to include(report_text(open_report2))
end
# filter by reporter
filter(['Reporter', open_report.reporter.username])
context 'when multiple reports for the same user are created' do
let_it_be(:open_report3) { create(:abuse_report, category: 'spam', user: user) }
let_it_be(:closed_report2) { create(:abuse_report, :closed, user: user, category: 'spam') }
expect_displayed_reports_count(1)
expect_report_shown(open_report)
expect_report_not_shown(open_report2, closed_report)
it 'aggregates open reports by user & category', :aggregate_failures do
expect_displayed_reports_count(2)
# filter by category
filter(['Category', open_report2.category])
expect_aggregated_report_shown(open_report, 2)
expect_report_shown(open_report2)
end
expect_displayed_reports_count(1)
expect_report_shown(open_report2)
expect_report_not_shown(open_report, closed_report)
end
it 'can sort aggregated reports by number_of_reports in desc order only', :aggregate_failures do
sort_by 'Number of Reports'
it 'can be sorted by created_at and updated_at in desc and asc order', :aggregate_failures do
sort_by 'Created date'
# created_at desc
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(report_text(open_report))
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
# created_at asc
toggle_sort_direction
toggle_sort_direction
expect(report_rows[0].text).to include(report_text(open_report))
expect(report_rows[1].text).to include(report_text(open_report2))
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
end
# updated_at asc
sort_by 'Updated date'
it 'can sort aggregated reports by created_at and updated_at in desc and asc order', :aggregate_failures do
# number_of_reports desc (default)
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(report_text(open_report))
# created_at desc
sort_by 'Created date'
# updated_at desc
toggle_sort_direction
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(aggregated_report_text(open_report, 2))
# created_at asc
toggle_sort_direction
expect(report_rows[0].text).to include(report_text(open_report))
expect(report_rows[1].text).to include(report_text(open_report2))
end
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
context 'when multiple reports for the same user are created' do
let_it_be(:open_report3) { create(:abuse_report, category: 'spam', user: user) }
let_it_be(:closed_report2) { create(:abuse_report, :closed, user: user, category: 'spam') }
sort_by 'Updated date'
it 'aggregates open reports by user & category', :aggregate_failures do
expect_displayed_reports_count(2)
# updated_at asc
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(aggregated_report_text(open_report, 2))
expect_aggregated_report_shown(open_report, 2)
expect_report_shown(open_report2)
end
# updated_at desc
toggle_sort_direction
it 'can sort aggregated reports by number_of_reports in desc order only', :aggregate_failures do
sort_by 'Number of Reports'
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
end
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
it 'does not aggregate closed reports', :aggregate_failures do
filter %w[Status Closed]
toggle_sort_direction
expect_displayed_reports_count(2)
expect_report_shown(closed_report, closed_report2)
end
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
end
def report_rows
page.all(abuse_report_row_selector)
end
it 'can sort aggregated reports by created_at and updated_at in desc and asc order', :aggregate_failures do
# number_of_reports desc (default)
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
def report_text(report)
"#{report.user.name} reported for #{report.category} by #{report.reporter.name}"
end
# created_at desc
sort_by 'Created date'
def aggregated_report_text(report, count)
"#{report.user.name} reported for #{report.category} by #{count} users"
end
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(aggregated_report_text(open_report, 2))
def expect_report_shown(*reports)
reports.each do |r|
expect(page).to have_content(report_text(r))
end
end
# created_at asc
toggle_sort_direction
def expect_report_not_shown(*reports)
reports.each do |r|
expect(page).not_to have_content(report_text(r))
end
end
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
def expect_aggregated_report_shown(*reports, count)
reports.each do |r|
expect(page).to have_content(aggregated_report_text(r, count))
end
end
sort_by 'Updated date'
def expect_displayed_reports_count(count)
expect(page).to have_css(abuse_report_row_selector, count: count)
end
# updated_at asc
expect(report_rows[0].text).to include(report_text(open_report2))
expect(report_rows[1].text).to include(aggregated_report_text(open_report, 2))
def filter(tokens)
# remove all existing filters first
page.find_all('.gl-token-close').each(&:click)
# updated_at desc
toggle_sort_direction
select_tokens(*tokens, submit: true, input_text: 'Filter reports')
expect(report_rows[0].text).to include(aggregated_report_text(open_report, 2))
expect(report_rows[1].text).to include(report_text(open_report2))
end
def sort_by(sort)
page.within('.vue-filtered-search-bar-container .sort-dropdown-container') do
page.find('.gl-dropdown-toggle').click
it 'does not aggregate closed reports', :aggregate_failures do
filter %w[Status Closed]
page.within('.dropdown-menu') do
click_button sort
wait_for_requests
end
end
expect_displayed_reports_count(2)
expect_report_shown(closed_report, closed_report2)
end
end
context 'when abuse_reports_list feature flag is disabled' do
before do
stub_feature_flags(abuse_reports_list: false)
visit admin_abuse_reports_path
end
def report_rows
page.all(abuse_report_row_selector)
end
it 'displays all abuse reports', :aggregate_failures do
expect_report_shown(open_report)
expect_report_actions_shown(open_report)
def report_text(report)
"#{report.user.name} reported for #{report.category} by #{report.reporter.name}"
end
expect_report_shown(open_report2)
expect_report_actions_shown(open_report2)
def aggregated_report_text(report, count)
"#{report.user.name} reported for #{report.category} by #{count} users"
end
expect_report_shown(closed_report)
expect_report_actions_shown(closed_report)
def expect_report_shown(*reports)
reports.each do |r|
expect(page).to have_content(report_text(r))
end
end
context 'when an admin has been reported for abuse' do
let_it_be(:admin_abuse_report) { create(:abuse_report, user: admin) }
it 'displays the abuse report without actions' do
expect_report_shown(admin_abuse_report)
expect_report_actions_not_shown(admin_abuse_report)
end
def expect_report_not_shown(*reports)
reports.each do |r|
expect(page).not_to have_content(report_text(r))
end
end
context 'when multiple users have been reported for abuse' do
let(:report_count) { AbuseReport.default_per_page + 3 }
before do
report_count.times do
create(:abuse_report, user: create(:user))
end
end
context 'in the abuse report view', :aggregate_failures do
it 'adds pagination' do
visit admin_abuse_reports_path
expect(page).to have_selector('.pagination')
expect(page).to have_selector('.pagination .js-pagination-page', count: (report_count.to_f / AbuseReport.default_per_page).ceil)
end
end
def expect_aggregated_report_shown(*reports, count)
reports.each do |r|
expect(page).to have_content(aggregated_report_text(r, count))
end
end
context 'when filtering reports' do
it 'can be filtered by reported-user', :aggregate_failures do
visit admin_abuse_reports_path
page.within '.filter-form' do
click_button 'User'
wait_for_requests
page.within '.dropdown-menu-user' do
click_link user.name
end
wait_for_requests
end
def expect_displayed_reports_count(count)
expect(page).to have_css(abuse_report_row_selector, count: count)
end
expect_report_shown(open_report)
expect_report_shown(closed_report)
end
end
def filter(tokens)
# remove all existing filters first
page.find_all('.gl-token-close').each(&:click)
def expect_report_shown(report)
page.within(:table_row, { "User" => report.user.name, "Reported by" => report.reporter.name }) do
expect(page).to have_content(report.user.name)
expect(page).to have_content(report.reporter.name)
expect(page).to have_content(report.message)
expect(page).to have_link(report.user.name, href: user_path(report.user))
end
end
select_tokens(*tokens, submit: true, input_text: 'Filter reports')
end
def expect_report_actions_shown(report)
page.within(:table_row, { "User" => report.user.name, "Reported by" => report.reporter.name }) do
expect(page).to have_link('Remove user & report')
expect(page).to have_link('Block user')
expect(page).to have_link('Remove user')
end
end
def sort_by(sort)
page.within('.vue-filtered-search-bar-container .sort-dropdown-container') do
page.find('.gl-dropdown-toggle').click
def expect_report_actions_not_shown(report)
page.within(:table_row, { "User" => report.user.name, "Reported by" => report.reporter.name }) do
expect(page).not_to have_link('Remove user & report')
expect(page).not_to have_link('Block user')
expect(page).not_to have_link('Remove user')
page.within('.dropdown-menu') do
click_button sort
wait_for_requests
end
end
end
......
......@@ -17,17 +17,21 @@
create(:abuse_report, :closed, category: 'phishing', user: user_2, reporter: reporter_2, id: 2)
end
let(:params) { {} }
subject(:finder) { described_class.new(params).execute }
describe '#execute' do
context 'when params is empty' do
shared_examples 'returns all abuse reports' do
it 'returns all abuse reports' do
expect(finder).to match_array([abuse_report_1, abuse_report_2])
end
end
context 'when params is empty' do
let(:params) { {} }
it_behaves_like 'returns all abuse reports'
end
shared_examples 'returns filtered reports' do |filter_field|
it "returns abuse reports filtered by #{filter_field}_id" do
expect(finder).to match_array(filtered_reports)
......@@ -41,9 +45,7 @@
.and_return(nil)
end
it 'returns all abuse reports' do
expect(finder).to match_array([abuse_report_1, abuse_report_2])
end
it_behaves_like 'returns all abuse reports'
end
end
......@@ -169,39 +171,5 @@
end
end
end
context 'when legacy view is enabled' do
before do
stub_feature_flags(abuse_reports_list: false)
end
context 'when params is empty' do
it 'returns all abuse reports' do
expect(subject).to match_array([abuse_report_1, abuse_report_2])
end
end
context 'when params[:user_id] is present' do
let(:params) { { user_id: user_1 } }
it 'returns abuse reports for the specified user' do
expect(subject).to match_array([abuse_report_1])
end
end
context 'when sorting' do
it 'returns reports sorted by id in descending order' do
expect(subject).to match_array([abuse_report_2, abuse_report_1])
end
end
context 'when any of the new filters are present such as params[:status]' do
let(:params) { { status: 'open' } }
it 'returns all abuse reports' do
expect(subject).to match_array([abuse_report_1, abuse_report_2])
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::AbuseReportsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
include AdminModeHelper
let(:admin) { create(:admin) }
let!(:abuse_report) { create(:abuse_report) }
let!(:abuse_report_with_short_message) { create(:abuse_report, message: 'SHORT MESSAGE') }
let!(:abuse_report_with_long_message) { create(:abuse_report, message: "LONG MESSAGE\n" * 50) }
render_views
before do
stub_feature_flags(abuse_reports_list: false)
sign_in(admin)
enable_admin_mode!(admin)
end
it 'abuse_reports/abuse_reports_list.html' do
get :index
expect(response).to be_successful
end
end
import $ from 'jquery';
import htmlAbuseReportsList from 'test_fixtures/abuse_reports/abuse_reports_list.html';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import AbuseReports from '~/pages/admin/abuse_reports/abuse_reports';
describe('Abuse Reports', () => {
const MAX_MESSAGE_LENGTH = 500;
let $messages;
const assertMaxLength = ($message) => {
expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
};
const findMessage = (searchText) =>
$messages.filter((index, element) => element.innerText.indexOf(searchText) > -1).first();
beforeEach(() => {
setHTMLFixture(htmlAbuseReportsList);
new AbuseReports(); // eslint-disable-line no-new
$messages = $('.abuse-reports .message');
});
afterEach(() => {
resetHTMLFixture();
});
it('should truncate long messages', () => {
const $longMessage = findMessage('LONG MESSAGE');
expect($longMessage.data('originalMessage')).toEqual(expect.anything());
assertMaxLength($longMessage);
});
it('should not truncate short messages', () => {
const $shortMessage = findMessage('SHORT MESSAGE');
expect($shortMessage.data('originalMessage')).not.toEqual(expect.anything());
});
it('should allow clicking a truncated message to expand and collapse the full message', () => {
const $longMessage = findMessage('LONG MESSAGE');
$longMessage.click();
expect($longMessage.data('originalMessage').length).toEqual($longMessage.text().length);
$longMessage.click();
assertMaxLength($longMessage);
});
});
......@@ -29,18 +29,6 @@
expect(assigns(:abuse_reports).count).to eq 1
expect(assigns(:abuse_reports).first.closed?).to eq true
end
context 'when abuse_reports_list flag is disabled' do
before do
stub_feature_flags(abuse_reports_list: false)
end
it 'returns all reports by default' do
get admin_abuse_reports_path
expect(assigns(:abuse_reports).count).to eq 2
end
end
end
describe 'GET #show' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment