Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils_spec.js « merge_conflicts « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5bf7ecf8cfef3d16f3661796ebf76610828d63b3 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as utils from '~/merge_conflicts/utils';

describe('merge conflicts utils', () => {
  describe('getFilePath', () => {
    it('returns new path if they are the same', () => {
      expect(utils.getFilePath({ new_path: 'a', old_path: 'a' })).toBe('a');
    });

    it('returns concatenated paths if they are different', () => {
      expect(utils.getFilePath({ new_path: 'b', old_path: 'a' })).toBe('a → b');
    });
  });

  describe('checkLineLengths', () => {
    it('add empty lines to the left when right has more lines', () => {
      const result = utils.checkLineLengths({ left: [1], right: [1, 2] });

      expect(result.left).toHaveLength(result.right.length);
      expect(result.left).toStrictEqual([1, { lineType: 'emptyLine', richText: '' }]);
    });

    it('add empty lines to the right when left has more lines', () => {
      const result = utils.checkLineLengths({ left: [1, 2], right: [1] });

      expect(result.right).toHaveLength(result.left.length);
      expect(result.right).toStrictEqual([1, { lineType: 'emptyLine', richText: '' }]);
    });
  });

  describe('getHeadHeaderLine', () => {
    it('decorates the id', () => {
      expect(utils.getHeadHeaderLine(1)).toStrictEqual({
        buttonTitle: 'Use ours',
        id: 1,
        isHead: true,
        isHeader: true,
        isSelected: false,
        isUnselected: false,
        richText: 'HEAD//our changes',
        section: 'head',
        type: 'new',
      });
    });
  });

  describe('decorateLineForInlineView', () => {
    it.each`
      type       | truthyProp
      ${'new'}   | ${'isHead'}
      ${'old'}   | ${'isOrigin'}
      ${'match'} | ${'hasMatch'}
    `(
      'when the type is $type decorates the line with $truthyProp set as true',
      ({ type, truthyProp }) => {
        expect(utils.decorateLineForInlineView({ type, rich_text: 'rich' }, 1, true)).toStrictEqual(
          {
            id: 1,
            hasConflict: true,
            isHead: false,
            isOrigin: false,
            hasMatch: false,
            richText: 'rich',
            isSelected: false,
            isUnselected: false,
            [truthyProp]: true,
          },
        );
      },
    );
  });

  describe('getLineForParallelView', () => {
    it.todo('should return a proper value');
  });

  describe('getOriginHeaderLine', () => {
    it('decorates the id', () => {
      expect(utils.getOriginHeaderLine(1)).toStrictEqual({
        buttonTitle: 'Use theirs',
        id: 1,
        isHeader: true,
        isOrigin: true,
        isSelected: false,
        isUnselected: false,
        richText: 'origin//their changes',
        section: 'origin',
        type: 'old',
      });
    });
  });
  describe('setInlineLine', () => {
    it.todo('should return a proper value');
  });
  describe('setParallelLine', () => {
    it.todo('should return a proper value');
  });
  describe('decorateFiles', () => {
    it.todo('should return a proper value');
  });
  describe('restoreFileLinesState', () => {
    it.todo('should return a proper value');
  });
  describe('markLine', () => {
    it.todo('should return a proper value');
  });
});