Commit 3616e063 authored by Phil Hughes's avatar Phil Hughes

Convert AbuseReports class to a module

parent cbc7d62c
const MAX_MESSAGE_LENGTH = 500; const MAX_MESSAGE_LENGTH = 500;
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message'; const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
class AbuseReports { export default class AbuseReports {
constructor() { constructor() {
$(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage); $(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
$(document) $(document)
...@@ -32,6 +32,3 @@ class AbuseReports { ...@@ -32,6 +32,3 @@ class AbuseReports {
} }
} }
} }
window.gl = window.gl || {};
window.gl.AbuseReports = AbuseReports;
...@@ -76,6 +76,7 @@ import initProjectVisibilitySelector from './project_visibility'; ...@@ -76,6 +76,7 @@ import initProjectVisibilitySelector from './project_visibility';
import GpgBadges from './gpg_badges'; import GpgBadges from './gpg_badges';
import UserFeatureHelper from './helpers/user_feature_helper'; import UserFeatureHelper from './helpers/user_feature_helper';
import initChangesDropdown from './init_changes_dropdown'; import initChangesDropdown from './init_changes_dropdown';
import AbuseReports from './abuse_reports';
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils'; import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
(function() { (function() {
...@@ -557,7 +558,7 @@ import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils'; ...@@ -557,7 +558,7 @@ import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
new Labels(); new Labels();
} }
case 'abuse_reports': case 'abuse_reports':
new gl.AbuseReports(); new AbuseReports();
break; break;
} }
break; break;
......
...@@ -57,7 +57,6 @@ import './u2f/register'; ...@@ -57,7 +57,6 @@ import './u2f/register';
import './u2f/util'; import './u2f/util';
// everything else // everything else
import './abuse_reports';
import './activities'; import './activities';
import './admin'; import './admin';
import './ajax_loading_spinner'; import './ajax_loading_spinner';
......
import '~/lib/utils/text_utility'; import '~/lib/utils/text_utility';
import '~/abuse_reports'; import AbuseReports from '~/abuse_reports';
((global) => { describe('Abuse Reports', () => {
describe('Abuse Reports', () => { const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw'; const MAX_MESSAGE_LENGTH = 500;
const MAX_MESSAGE_LENGTH = 500;
let $messages;
let $messages;
const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH); const findMessage = searchText => $messages.filter(
const findMessage = searchText => $messages.filter( (index, element) => element.innerText.indexOf(searchText) > -1,
(index, element) => element.innerText.indexOf(searchText) > -1, ).first();
).first();
preloadFixtures(FIXTURE);
preloadFixtures(FIXTURE);
beforeEach(function () {
beforeEach(function () { loadFixtures(FIXTURE);
loadFixtures(FIXTURE); this.abuseReports = new AbuseReports();
this.abuseReports = new global.AbuseReports(); $messages = $('.abuse-reports .message');
$messages = $('.abuse-reports .message'); });
});
it('should truncate long messages', () => {
it('should truncate long messages', () => { const $longMessage = findMessage('LONG MESSAGE');
const $longMessage = findMessage('LONG MESSAGE'); expect($longMessage.data('original-message')).toEqual(jasmine.anything());
expect($longMessage.data('original-message')).toEqual(jasmine.anything()); assertMaxLength($longMessage);
assertMaxLength($longMessage); });
});
it('should not truncate short messages', () => {
it('should not truncate short messages', () => { const $shortMessage = findMessage('SHORT MESSAGE');
const $shortMessage = findMessage('SHORT MESSAGE'); expect($shortMessage.data('original-message')).not.toEqual(jasmine.anything());
expect($shortMessage.data('original-message')).not.toEqual(jasmine.anything()); });
});
it('should allow clicking a truncated message to expand and collapse the full message', () => {
it('should allow clicking a truncated message to expand and collapse the full message', () => { const $longMessage = findMessage('LONG MESSAGE');
const $longMessage = findMessage('LONG MESSAGE'); $longMessage.click();
$longMessage.click(); expect($longMessage.data('original-message').length).toEqual($longMessage.text().length);
expect($longMessage.data('original-message').length).toEqual($longMessage.text().length); $longMessage.click();
$longMessage.click(); assertMaxLength($longMessage);
assertMaxLength($longMessage);
});
}); });
})(window.gl); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment