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

file_row_extra_spec.js « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a7a1fe7db08c46123a3532fa0e1f36375961b71 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import Vue, { nextTick } from 'vue';
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import FileRowExtra from '~/ide/components/file_row_extra.vue';
import { createStore } from '~/ide/stores';
import { file } from '../helpers';

describe('IDE extra file row component', () => {
  let Component;
  let vm;
  let unstagedFilesCount = 0;
  let stagedFilesCount = 0;
  let changesCount = 0;

  beforeAll(() => {
    Component = Vue.extend(FileRowExtra);
  });

  beforeEach(() => {
    vm = createComponentWithStore(Component, createStore(), {
      file: {
        ...file('test'),
      },
      dropdownOpen: false,
    });

    jest.spyOn(vm, 'getUnstagedFilesCountForPath', 'get').mockReturnValue(() => unstagedFilesCount);
    jest.spyOn(vm, 'getStagedFilesCountForPath', 'get').mockReturnValue(() => stagedFilesCount);
    jest.spyOn(vm, 'getChangesInFolder', 'get').mockReturnValue(() => changesCount);

    vm.$mount();
  });

  afterEach(() => {
    vm.$destroy();

    stagedFilesCount = 0;
    unstagedFilesCount = 0;
    changesCount = 0;
  });

  describe('folderChangesTooltip', () => {
    it('returns undefined when changes count is 0', () => {
      changesCount = 0;

      expect(vm.folderChangesTooltip).toBe(undefined);
    });

    [
      { input: 1, output: '1 changed file' },
      { input: 2, output: '2 changed files' },
    ].forEach(({ input, output }) => {
      it('returns changed files count if changes count is not 0', () => {
        changesCount = input;

        expect(vm.folderChangesTooltip).toBe(output);
      });
    });
  });

  describe('show tree changes count', () => {
    it('does not show for blobs', () => {
      vm.file.type = 'blob';

      expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
    });

    it('does not show when changes count is 0', () => {
      vm.file.type = 'tree';

      expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
    });

    it('does not show when tree is open', async () => {
      vm.file.type = 'tree';
      vm.file.opened = true;
      changesCount = 1;

      await nextTick();
      expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null);
    });

    it('shows for trees with changes', async () => {
      vm.file.type = 'tree';
      vm.file.opened = false;
      changesCount = 1;

      await nextTick();
      expect(vm.$el.querySelector('.ide-tree-changes')).not.toBe(null);
    });
  });

  describe('changes file icon', () => {
    it('hides when file is not changed', () => {
      expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
    });

    it('shows when file is changed', async () => {
      vm.file.changed = true;

      await nextTick();
      expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
    });

    it('shows when file is staged', async () => {
      vm.file.staged = true;

      await nextTick();
      expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
    });

    it('shows when file is a tempFile', async () => {
      vm.file.tempFile = true;

      await nextTick();
      expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
    });

    it('shows when file is renamed', async () => {
      vm.file.prevPath = 'original-file';

      await nextTick();
      expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null);
    });

    it('hides when file is renamed', async () => {
      vm.file.prevPath = 'original-file';
      vm.file.type = 'tree';

      await nextTick();
      expect(vm.$el.querySelector('.file-changed-icon')).toBe(null);
    });
  });

  describe('merge request icon', () => {
    it('hides when not a merge request change', () => {
      expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).toBe(null);
    });

    it('shows when a merge request change', async () => {
      vm.file.mrChange = true;

      await nextTick();
      expect(vm.$el.querySelector('[data-testid="git-merge-icon"]')).not.toBe(null);
    });
  });
});