BigW Consortium Gitlab

abuse_reports_spec.js 1.45 KB
Newer Older
1 2
require('~/lib/utils/text_utility');
require('~/abuse_reports');
3 4

((global) => {
5 6 7 8 9
  describe('Abuse Reports', () => {
    const FIXTURE = 'abuse_reports/abuse_reports_list.html.raw';
    const MAX_MESSAGE_LENGTH = 500;

    let messages;
10

11 12 13 14
    const assertMaxLength = $message => expect($message.text().length).toEqual(MAX_MESSAGE_LENGTH);
    const findMessage = searchText => messages.filter(
      (index, element) => element.innerText.indexOf(searchText) > -1,
    ).first();
15

16
    preloadFixtures(FIXTURE);
17

18
    beforeEach(function () {
19
      loadFixtures(FIXTURE);
20 21
      this.abuseReports = new global.AbuseReports();
      messages = $('.abuse-reports .message');
22 23
    });

24 25
    it('should truncate long messages', () => {
      const $longMessage = findMessage('LONG MESSAGE');
26 27 28 29
      expect($longMessage.data('original-message')).toEqual(jasmine.anything());
      assertMaxLength($longMessage);
    });

30 31
    it('should not truncate short messages', () => {
      const $shortMessage = findMessage('SHORT MESSAGE');
32 33 34
      expect($shortMessage.data('original-message')).not.toEqual(jasmine.anything());
    });

35 36
    it('should allow clicking a truncated message to expand and collapse the full message', () => {
      const $longMessage = findMessage('LONG MESSAGE');
37 38 39 40 41 42 43
      $longMessage.click();
      expect($longMessage.data('original-message').length).toEqual($longMessage.text().length);
      $longMessage.click();
      assertMaxLength($longMessage);
    });
  });
})(window.gl);