summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/stores/mutations_spec.js
blob: d1c9885e01df1efbb41979df6ea4e2d745ccfc1c (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
import mutations from '~/repo/stores/mutations';
import state from '~/repo/stores/state';
import { file } from '../helpers';

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

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

  describe('SET_INITIAL_DATA', () => {
    it('sets all initial data', () => {
      mutations.SET_INITIAL_DATA(localState, {
        test: 'test',
      });

      expect(localState.test).toBe('test');
    });
  });

  describe('SET_PREVIEW_MODE', () => {
    it('sets currentBlobView to repo-preview', () => {
      mutations.SET_PREVIEW_MODE(localState);

      expect(localState.currentBlobView).toBe('repo-preview');

      localState.currentBlobView = 'testing';

      mutations.SET_PREVIEW_MODE(localState);

      expect(localState.currentBlobView).toBe('repo-preview');
    });
  });

  describe('SET_EDIT_MODE', () => {
    it('sets currentBlobView to repo-editor', () => {
      mutations.SET_EDIT_MODE(localState);

      expect(localState.currentBlobView).toBe('repo-editor');

      localState.currentBlobView = 'testing';

      mutations.SET_EDIT_MODE(localState);

      expect(localState.currentBlobView).toBe('repo-editor');
    });
  });

  describe('TOGGLE_LOADING', () => {
    it('toggles loading of entry', () => {
      mutations.TOGGLE_LOADING(localState, entry);

      expect(entry.loading).toBeTruthy();

      mutations.TOGGLE_LOADING(localState, entry);

      expect(entry.loading).toBeFalsy();
    });
  });

  describe('TOGGLE_EDIT_MODE', () => {
    it('toggles editMode', () => {
      mutations.TOGGLE_EDIT_MODE(localState);

      expect(localState.editMode).toBeTruthy();

      mutations.TOGGLE_EDIT_MODE(localState);

      expect(localState.editMode).toBeFalsy();
    });
  });

  describe('TOGGLE_DISCARD_POPUP', () => {
    it('sets discardPopupOpen', () => {
      mutations.TOGGLE_DISCARD_POPUP(localState, true);

      expect(localState.discardPopupOpen).toBeTruthy();

      mutations.TOGGLE_DISCARD_POPUP(localState, false);

      expect(localState.discardPopupOpen).toBeFalsy();
    });
  });

  describe('SET_COMMIT_REF', () => {
    it('sets currentRef', () => {
      mutations.SET_COMMIT_REF(localState, '123');

      expect(localState.currentRef).toBe('123');
    });
  });

  describe('SET_ROOT', () => {
    it('sets isRoot & initialRoot', () => {
      mutations.SET_ROOT(localState, true);

      expect(localState.isRoot).toBeTruthy();
      expect(localState.isInitialRoot).toBeTruthy();

      mutations.SET_ROOT(localState, false);

      expect(localState.isRoot).toBeFalsy();
      expect(localState.isInitialRoot).toBeFalsy();
    });
  });

  describe('SET_PREVIOUS_URL', () => {
    it('sets previousUrl', () => {
      mutations.SET_PREVIOUS_URL(localState, 'testing');

      expect(localState.previousUrl).toBe('testing');
    });
  });
});