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

terminal_spec.js « plugins « stores « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4cdad16ecb9964e93b5c7365073293515be8a73 (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
import { createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { TEST_HOST } from 'helpers/test_constants';
import terminalModule from '~/ide/stores/modules/terminal';
import { SET_BRANCH_WORKING_REFERENCE } from '~/ide/stores/mutation_types';
import createTerminalPlugin from '~/ide/stores/plugins/terminal';

const TEST_DATASET = {
  eeWebTerminalSvgPath: `${TEST_HOST}/web/terminal/svg`,
  eeWebTerminalHelpPath: `${TEST_HOST}/web/terminal/help`,
  eeWebTerminalConfigHelpPath: `${TEST_HOST}/web/terminal/config/help`,
  eeWebTerminalRunnersHelpPath: `${TEST_HOST}/web/terminal/runners/help`,
};
const localVue = createLocalVue();
localVue.use(Vuex);

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

  beforeEach(() => {
    const el = document.createElement('div');
    Object.assign(el.dataset, TEST_DATASET);

    store = new Vuex.Store({
      mutations: {
        [SET_BRANCH_WORKING_REFERENCE]: () => {},
      },
    });

    jest.spyOn(store, 'registerModule').mockImplementation();
    jest.spyOn(store, 'dispatch').mockImplementation();

    const plugin = createTerminalPlugin(el);

    plugin(store);
  });

  it('registers terminal module', () => {
    expect(store.registerModule).toHaveBeenCalledWith('terminal', terminalModule());
  });

  it('dispatches terminal/setPaths', () => {
    expect(store.dispatch).toHaveBeenCalledWith('terminal/setPaths', {
      webTerminalSvgPath: TEST_DATASET.eeWebTerminalSvgPath,
      webTerminalHelpPath: TEST_DATASET.eeWebTerminalHelpPath,
      webTerminalConfigHelpPath: TEST_DATASET.eeWebTerminalConfigHelpPath,
      webTerminalRunnersHelpPath: TEST_DATASET.eeWebTerminalRunnersHelpPath,
    });
  });

  it(`dispatches terminal/init on ${SET_BRANCH_WORKING_REFERENCE}`, () => {
    store.dispatch.mockReset();

    store.commit(SET_BRANCH_WORKING_REFERENCE);

    expect(store.dispatch).toHaveBeenCalledWith('terminal/init');
  });
});