summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/modules/pane/actions_spec.js
blob: 98c4f22dac82099267d3366a10628f8c7bd08154 (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
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/ide/stores/modules/pane/actions';
import * as types from '~/ide/stores/modules/pane/mutation_types';

describe('IDE pane module actions', () => {
  const TEST_VIEW = { name: 'test' };
  const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true };

  describe('toggleOpen', () => {
    it('dispatches open if closed', () => {
      return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }]);
    });

    it('dispatches close if opened', () => {
      return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }]);
    });
  });

  describe('open', () => {
    describe('with a view specified', () => {
      it('commits SET_OPEN and SET_CURRENT_VIEW', () => {
        return testAction(
          actions.open,
          TEST_VIEW,
          {},
          [
            { type: types.SET_OPEN, payload: true },
            { type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name },
          ],
          [],
        );
      });

      it('commits KEEP_ALIVE_VIEW if keepAlive is true', () => {
        return testAction(
          actions.open,
          TEST_VIEW_KEEP_ALIVE,
          {},
          [
            { type: types.SET_OPEN, payload: true },
            { type: types.SET_CURRENT_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
            { type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
          ],
          [],
        );
      });
    });

    describe('without a view specified', () => {
      it('commits SET_OPEN', () => {
        return testAction(
          actions.open,
          undefined,
          {},
          [{ type: types.SET_OPEN, payload: true }],
          [],
        );
      });
    });
  });

  describe('close', () => {
    it('commits SET_OPEN', () => {
      return testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], []);
    });
  });
});