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

getters_spec.js « stores « repo « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 952b8ec3a5903ac87ad350d67d3ff6bfcc893a36 (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 * as getters from '~/repo/stores/getters';
import state from '~/repo/stores/state';
import { file } from '../helpers';

describe('Multi-file store getters', () => {
  let localState;

  beforeEach(() => {
    localState = state();
  });

  describe('treeList', () => {
    it('returns flat tree list', () => {
      localState.tree.push(file('1'));
      localState.tree[0].tree.push(file('2'));
      localState.tree[0].tree[0].tree.push(file('3'));

      const treeList = getters.treeList(localState);

      expect(treeList.length).toBe(3);
      expect(treeList[1].name).toBe(localState.tree[0].tree[0].name);
      expect(treeList[2].name).toBe(localState.tree[0].tree[0].tree[0].name);
    });
  });

  describe('changedFiles', () => {
    it('returns a list of changed opened files', () => {
      localState.openFiles.push(file());
      localState.openFiles.push(file('changed'));
      localState.openFiles[1].changed = true;

      const changedFiles = getters.changedFiles(localState);

      expect(changedFiles.length).toBe(1);
      expect(changedFiles[0].name).toBe('changed');
    });
  });

  describe('activeFile', () => {
    it('returns the current active file', () => {
      localState.openFiles.push(file());
      localState.openFiles.push(file('active'));
      localState.openFiles[1].active = true;

      expect(getters.activeFile(localState).name).toBe('active');
    });

    it('returns undefined if no active files are found', () => {
      localState.openFiles.push(file());
      localState.openFiles.push(file('active'));

      expect(getters.activeFile(localState)).toBeUndefined();
    });
  });

  describe('activeFileExtension', () => {
    it('returns the file extension for the current active file', () => {
      localState.openFiles.push(file('active'));
      localState.openFiles[0].active = true;
      localState.openFiles[0].path = 'test.js';

      expect(getters.activeFileExtension(localState)).toBe('.js');

      localState.openFiles[0].path = 'test.es6.js';

      expect(getters.activeFileExtension(localState)).toBe('.js');
    });
  });

  describe('isCollapsed', () => {
    it('returns true if state has open files', () => {
      localState.openFiles.push(file());

      expect(getters.isCollapsed(localState)).toBeTruthy();
    });

    it('returns false if state has no open files', () => {
      expect(getters.isCollapsed(localState)).toBeFalsy();
    });
  });

  describe('canEditFile', () => {
    beforeEach(() => {
      localState.onTopOfBranch = true;
      localState.canCommit = true;

      localState.openFiles.push(file());
      localState.openFiles[0].active = true;
    });

    it('returns true if user can commit and has open files', () => {
      expect(getters.canEditFile(localState)).toBeTruthy();
    });

    it('returns false if user can commit and has no open files', () => {
      localState.openFiles = [];

      expect(getters.canEditFile(localState)).toBeFalsy();
    });

    it('returns false if user can commit and active file is binary', () => {
      localState.openFiles[0].binary = true;

      expect(getters.canEditFile(localState)).toBeFalsy();
    });

    it('returns false if user cant commit', () => {
      localState.canCommit = false;

      expect(getters.canEditFile(localState)).toBeFalsy();
    });

    it('returns false if user can commit but on a branch', () => {
      localState.onTopOfBranch = false;

      expect(getters.canEditFile(localState)).toBeFalsy();
    });
  });

  describe('modifiedFiles', () => {
    it('returns a list of modified files', () => {
      localState.openFiles.push(file());
      localState.openFiles.push(file('changed'));
      localState.openFiles[1].changed = true;

      const modifiedFiles = getters.modifiedFiles(localState);

      expect(modifiedFiles.length).toBe(1);
      expect(modifiedFiles[0].name).toBe('changed');
    });
  });

  describe('addedFiles', () => {
    it('returns a list of added files', () => {
      localState.openFiles.push(file());
      localState.openFiles.push(file('added'));
      localState.openFiles[1].changed = true;
      localState.openFiles[1].tempFile = true;

      const modifiedFiles = getters.addedFiles(localState);

      expect(modifiedFiles.length).toBe(1);
      expect(modifiedFiles[0].name).toBe('added');
    });
  });
});