summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/components/multiline_comment_utils_spec.js
blob: 261bfb106e7811bc029954125c0c7e7f630c0cd5 (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
38
39
40
41
42
43
44
45
46
47
48
49
import {
  getSymbol,
  getStartLineNumber,
  getEndLineNumber,
} from '~/notes/components/multiline_comment_utils';

describe('Multiline comment utilities', () => {
  describe('getStartLineNumber', () => {
    it.each`
      lineCode        | type     | result
      ${'abcdef_1_1'} | ${'old'} | ${'-1'}
      ${'abcdef_1_1'} | ${'new'} | ${'+1'}
      ${'abcdef_1_1'} | ${null}  | ${'1'}
      ${'abcdef'}     | ${'new'} | ${''}
      ${'abcdef'}     | ${'old'} | ${''}
      ${'abcdef'}     | ${null}  | ${''}
    `('returns line number', ({ lineCode, type, result }) => {
      expect(getStartLineNumber({ start_line_code: lineCode, start_line_type: type })).toEqual(
        result,
      );
    });
  });
  describe('getEndLineNumber', () => {
    it.each`
      lineCode        | type     | result
      ${'abcdef_1_1'} | ${'old'} | ${'-1'}
      ${'abcdef_1_1'} | ${'new'} | ${'+1'}
      ${'abcdef_1_1'} | ${null}  | ${'1'}
      ${'abcdef'}     | ${'new'} | ${''}
      ${'abcdef'}     | ${'old'} | ${''}
      ${'abcdef'}     | ${null}  | ${''}
    `('returns line number', ({ lineCode, type, result }) => {
      expect(getEndLineNumber({ end_line_code: lineCode, end_line_type: type })).toEqual(result);
    });
  });
  describe('getSymbol', () => {
    it.each`
      type         | result
      ${'new'}     | ${'+'}
      ${'old'}     | ${'-'}
      ${'unused'}  | ${''}
      ${''}        | ${''}
      ${null}      | ${''}
      ${undefined} | ${''}
    `('`$type` returns `$result`', ({ type, result }) => {
      expect(getSymbol(type)).toEqual(result);
    });
  });
});