summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/stores/collapse_utils_spec.js
blob: d3019f4b9a4f0669ed7ad6cbf0ee35128bc65375 (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
import {
  isDescriptionSystemNote,
  getTimeDifferenceMinutes,
  collapseSystemNotes,
} from '~/notes/stores/collapse_utils';
import { notesWithDescriptionChanges, collapsedSystemNotes } from '../mock_data';

describe('Collapse utils', () => {
  const mockSystemNote = {
    note: 'changed the description',
    note_html: '<p dir="auto">changed the description</p>',
    system: true,
    created_at: '2018-05-14T21:28:00.000Z',
  };

  it('checks if a system note is of a description type', () => {
    expect(isDescriptionSystemNote(mockSystemNote)).toEqual(true);
  });

  it('returns false when a system note is not a description type', () => {
    expect(isDescriptionSystemNote(Object.assign({}, mockSystemNote, { note: 'foo' }))).toEqual(
      false,
    );
  });

  it('gets the time difference between two notes', () => {
    const anotherSystemNote = {
      created_at: '2018-05-14T21:33:00.000Z',
    };

    expect(getTimeDifferenceMinutes(mockSystemNote, anotherSystemNote)).toEqual(5);
  });

  it('collapses all description system notes made within 10 minutes or less from each other', () => {
    expect(collapseSystemNotes(notesWithDescriptionChanges)).toEqual(collapsedSystemNotes);
  });
});