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

tree_spec.js « mutations « stores « ide « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67e9f7509da839ae25b27cb69a4f98d2900a58e5 (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
import mutations from '~/ide/stores/mutations/tree';
import state from '~/ide/stores/state';
import { file } from '../../helpers';

describe('Multi-file store tree mutations', () => {
  let localState;
  let localTree;

  beforeEach(() => {
    localState = state();
    localTree = file();

    localState.entries[localTree.path] = localTree;
  });

  describe('TOGGLE_TREE_OPEN', () => {
    it('toggles tree open', () => {
      mutations.TOGGLE_TREE_OPEN(localState, localTree.path);

      expect(localTree.opened).toBeTruthy();

      mutations.TOGGLE_TREE_OPEN(localState, localTree.path);

      expect(localTree.opened).toBeFalsy();
    });
  });

  describe('SET_DIRECTORY_DATA', () => {
    const data = [
      {
        name: 'tree',
      },
      {
        name: 'submodule',
      },
      {
        name: 'blob',
      },
    ];

    it('adds directory data', () => {
      localState.trees['project/master'] = {
        tree: [],
      };

      mutations.SET_DIRECTORY_DATA(localState, {
        data,
        treePath: 'project/master',
      });

      const tree = localState.trees['project/master'];

      expect(tree.tree.length).toBe(3);
      expect(tree.tree[0].name).toBe('tree');
      expect(tree.tree[1].name).toBe('submodule');
      expect(tree.tree[2].name).toBe('blob');
    });

    it('keeps loading state', () => {
      mutations.CREATE_TREE(localState, { treePath: 'project/master' });
      mutations.SET_DIRECTORY_DATA(localState, {
        data,
        treePath: 'project/master',
      });

      expect(localState.trees['project/master'].loading).toBe(true);
    });
  });

  describe('REMOVE_ALL_CHANGES_FILES', () => {
    it('removes all files from changedFiles state', () => {
      localState.changedFiles.push(file('REMOVE_ALL_CHANGES_FILES'));

      mutations.REMOVE_ALL_CHANGES_FILES(localState);

      expect(localState.changedFiles.length).toBe(0);
    });
  });
});