summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/extend_spec.js
blob: 88909999c823267474e59b60d0722d423d2de82d (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
import extendStore from '~/ide/stores/extend';
import terminalPlugin from '~/ide/stores/plugins/terminal';
import terminalSyncPlugin from '~/ide/stores/plugins/terminal_sync';

jest.mock('~/ide/stores/plugins/terminal', () => jest.fn());
jest.mock('~/ide/stores/plugins/terminal_sync', () => jest.fn());

describe('ide/stores/extend', () => {
  let store;
  let el;

  beforeEach(() => {
    store = {};
    el = {};

    [terminalPlugin, terminalSyncPlugin].forEach((x) => {
      const plugin = jest.fn();

      x.mockImplementation(() => plugin);
    });
  });

  afterEach(() => {
    terminalPlugin.mockClear();
    terminalSyncPlugin.mockClear();
  });

  const withGonFeatures = (features) => {
    global.gon.features = features;
  };

  describe('terminalPlugin', () => {
    beforeEach(() => {
      extendStore(store, el);
    });

    it('is created', () => {
      expect(terminalPlugin).toHaveBeenCalledWith(el);
    });

    it('is called with store', () => {
      expect(terminalPlugin()).toHaveBeenCalledWith(store);
    });
  });

  describe('terminalSyncPlugin', () => {
    describe('when buildServiceProxy feature is enabled', () => {
      beforeEach(() => {
        withGonFeatures({ buildServiceProxy: true });

        extendStore(store, el);
      });

      it('is created', () => {
        expect(terminalSyncPlugin).toHaveBeenCalledWith(el);
      });

      it('is called with store', () => {
        expect(terminalSyncPlugin()).toHaveBeenCalledWith(store);
      });
    });

    describe('when buildServiceProxy feature is disabled', () => {
      it('is not created', () => {
        extendStore(store, el);

        expect(terminalSyncPlugin).not.toHaveBeenCalled();
      });
    });
  });
});