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: f5a6e7222f97028189bc494827974cab68043a89 (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
import Vuex from 'vuex';
import { mount } from '@vue/test-utils';
import FileRowExtra from '~/ide/components/file_row_extra.vue';
import { createStoreOptions } from '~/ide/stores';
import { file } from '../helpers';

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

  const createComponent = (fileProps) => {
    const storeConfig = createStoreOptions();

    store = new Vuex.Store({
      ...storeConfig,
      getters: {
        getUnstagedFilesCountForPath: () => () => unstagedFilesCount,
        getStagedFilesCountForPath: () => () => stagedFilesCount,
        getChangesInFolder: () => () => changesCount,
      },
    });

    wrapper = mount(FileRowExtra, {
      store,
      propsData: {
        file: {
          ...file('test'),
          type: 'tree',
          ...fileProps,
        },
        dropdownOpen: false,
      },
    });
  };

  afterEach(() => {
    stagedFilesCount = 0;
    unstagedFilesCount = 0;
    changesCount = 0;
  });

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

        expect(wrapper.find('.ide-file-modified').attributes('title')).toBe(output);
      });
    });
  });

  describe('show tree changes count', () => {
    const findTreeChangesCount = () => wrapper.find('.ide-tree-changes');

    it('does not show for blobs', () => {
      createComponent({ type: 'blob' });

      expect(findTreeChangesCount().exists()).toBe(false);
    });

    it('does not show when changes count is 0', () => {
      createComponent({ type: 'tree' });

      expect(findTreeChangesCount().exists()).toBe(false);
    });

    it('does not show when tree is open', () => {
      changesCount = 1;
      createComponent({ type: 'tree', opened: true });

      expect(findTreeChangesCount().exists()).toBe(false);
    });

    it('shows for trees with changes', () => {
      changesCount = 1;
      createComponent({ type: 'tree', opened: false });

      expect(findTreeChangesCount().exists()).toBe(true);
    });
  });

  describe('changes file icon', () => {
    const findChangedFileIcon = () => wrapper.find('.file-changed-icon');

    it('hides when file is not changed', () => {
      createComponent();

      expect(findChangedFileIcon().exists()).toBe(false);
    });

    it('shows when file is changed', () => {
      createComponent({ type: 'blob', changed: true });

      expect(findChangedFileIcon().exists()).toBe(true);
    });

    it('shows when file is staged', () => {
      createComponent({ type: 'blob', staged: true });

      expect(findChangedFileIcon().exists()).toBe(true);
    });

    it('shows when file is a tempFile', () => {
      createComponent({ type: 'blob', tempFile: true });

      expect(findChangedFileIcon().exists()).toBe(true);
    });

    it('shows when file is renamed', () => {
      createComponent({ type: 'blob', prevPath: 'original-file' });

      expect(findChangedFileIcon().exists()).toBe(true);
    });

    it('hides when tree is renamed', () => {
      createComponent({ type: 'tree', prevPath: 'original-path' });

      expect(findChangedFileIcon().exists()).toBe(false);
    });
  });

  describe('merge request icon', () => {
    const findMergeRequestIcon = () => wrapper.find('[data-testid="git-merge-icon"]');

    it('hides when not a merge request change', () => {
      createComponent();

      expect(findMergeRequestIcon().exists()).toBe(false);
    });

    it('shows when a merge request change', () => {
      createComponent({ mrChange: true });

      expect(findMergeRequestIcon().exists()).toBe(true);
    });
  });
});