Merge branch 'abuse-reports-module' into 'master'
Convert AbuseReports class to a module See merge request gitlab-org/gitlab-ce!14709
This commit is contained in:
commit
705d0e35da
|
@ -1,7 +1,7 @@
|
|||
const MAX_MESSAGE_LENGTH = 500;
|
||||
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
|
||||
|
||||
class AbuseReports {
|
||||
export default class AbuseReports {
|
||||
constructor() {
|
||||
$(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
|
||||
$(document)
|
||||
|
@ -32,6 +32,3 @@ class AbuseReports {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.gl = window.gl || {};
|
||||
window.gl.AbuseReports = AbuseReports;
|
||||
|
|
|
@ -75,6 +75,7 @@ import initProjectVisibilitySelector from './project_visibility';
|
|||
import GpgBadges from './gpg_badges';
|
||||
import UserFeatureHelper from './helpers/user_feature_helper';
|
||||
import initChangesDropdown from './init_changes_dropdown';
|
||||
import AbuseReports from './abuse_reports';
|
||||
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
|
||||
import AjaxLoadingSpinner from './ajax_loading_spinner';
|
||||
|
||||
|
@ -561,7 +562,7 @@ import AjaxLoadingSpinner from './ajax_loading_spinner';
|
|||
new Labels();
|
||||
}
|
||||
case 'abuse_reports':
|
||||
new gl.AbuseReports();
|
||||
new AbuseReports();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -54,7 +54,6 @@ import './u2f/register';
|
|||
import './u2f/util';
|
||||
|
||||
// everything else
|
||||
import './abuse_reports';
|
||||
import './activities';
|
||||
import './admin';
|
||||
import './api';
|
||||
|
|
|
@ -1,43 +1,41 @@
|
|||
import '~/lib/utils/text_utility';
|
||||
import '~/abuse_reports';
|
||||
import AbuseReports from '~/abuse_reports';
|
||||
|
||||
((global) => {
|
||||
describe('Abuse Reports', () => {
|
||||
const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
|
||||
const MAX_MESSAGE_LENGTH = 500;
|
||||
describe('Abuse Reports', () => {
|
||||
const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
|
||||
const MAX_MESSAGE_LENGTH = 500;
|
||||
|
||||
let $messages;
|
||||
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();
|
||||
const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
|
||||
const findMessage = searchText => $messages.filter(
|
||||
(index, element) => element.innerText.indexOf(searchText) > -1,
|
||||
).first();
|
||||
|
||||
preloadFixtures(FIXTURE);
|
||||
preloadFixtures(FIXTURE);
|
||||
|
||||
beforeEach(function () {
|
||||
loadFixtures(FIXTURE);
|
||||
this.abuseReports = new global.AbuseReports();
|
||||
$messages = $('.abuse-reports .message');
|
||||
});
|
||||
|
||||
it('should truncate long messages', () => {
|
||||
const $longMessage = findMessage('LONG MESSAGE');
|
||||
expect($longMessage.data('original-message')).toEqual(jasmine.anything());
|
||||
assertMaxLength($longMessage);
|
||||
});
|
||||
|
||||
it('should not truncate short messages', () => {
|
||||
const $shortMessage = findMessage('SHORT MESSAGE');
|
||||
expect($shortMessage.data('original-message')).not.toEqual(jasmine.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('original-message').length).toEqual($longMessage.text().length);
|
||||
$longMessage.click();
|
||||
assertMaxLength($longMessage);
|
||||
});
|
||||
beforeEach(function () {
|
||||
loadFixtures(FIXTURE);
|
||||
this.abuseReports = new AbuseReports();
|
||||
$messages = $('.abuse-reports .message');
|
||||
});
|
||||
})(window.gl);
|
||||
|
||||
it('should truncate long messages', () => {
|
||||
const $longMessage = findMessage('LONG MESSAGE');
|
||||
expect($longMessage.data('original-message')).toEqual(jasmine.anything());
|
||||
assertMaxLength($longMessage);
|
||||
});
|
||||
|
||||
it('should not truncate short messages', () => {
|
||||
const $shortMessage = findMessage('SHORT MESSAGE');
|
||||
expect($shortMessage.data('original-message')).not.toEqual(jasmine.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('original-message').length).toEqual($longMessage.text().length);
|
||||
$longMessage.click();
|
||||
assertMaxLength($longMessage);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue