summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/extend_spec.js
blob: b0f1063153e8d17386f96d1e0f553eb80155da4c (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
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 prevGon;
  let store;
  let el;

  beforeEach(() => {
    prevGon = global.gon;
    store = {};
    el = {};

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

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

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

  const withGonFeatures = features => {
    global.gon = { ...global.gon, 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();
      });
    });
  });
});