view_spec.js 2.15 KB
Newer Older
1 2 3 4
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { TEST_HOST } from 'spec/test_constants';
import TerminalEmptyState from 'ee/ide/components/terminal/empty_state.vue';
5
import TerminalView from 'ee/ide/components/terminal/view.vue';
Paul Slaughter's avatar
Paul Slaughter committed
6
import TerminalSession from 'ee/ide/components/terminal/session.vue';
7

8
const TEST_HELP_PATH = `${TEST_HOST}/help`;
9 10 11 12 13
const TEST_SVG_PATH = `${TEST_HOST}/illustration.svg`;

const localVue = createLocalVue();
localVue.use(Vuex);

14 15 16 17 18 19
describe('EE IDE TerminalView', () => {
  let state;
  let actions;
  let getters;
  let wrapper;

20 21
  const factory = () => {
    const store = new Vuex.Store({
22 23 24 25 26 27 28
      modules: {
        terminal: {
          namespaced: true,
          state,
          actions,
          getters,
        },
29 30 31
      },
    });

Vitaly Slobodin's avatar
Vitaly Slobodin committed
32
    wrapper = shallowMount(TerminalView, { localVue, store });
33 34
  };

35 36 37 38 39 40 41 42 43 44
  beforeEach(() => {
    state = {
      isShowSplash: true,
      paths: {
        webTerminalHelpPath: TEST_HELP_PATH,
        webTerminalSvgPath: TEST_SVG_PATH,
      },
    };

    actions = {
Vitaly Slobodin's avatar
Vitaly Slobodin committed
45 46
      hideSplash: jest.fn().mockName('hideSplash'),
      startSession: jest.fn().mockName('startSession'),
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    };

    getters = {
      allCheck: () => ({
        isLoading: false,
        isValid: false,
        message: 'bad',
      }),
    };
  });

  afterEach(() => {
    wrapper.destroy();
  });

62
  it('renders empty state', () => {
63
    factory();
64 65

    expect(wrapper.find(TerminalEmptyState).props()).toEqual({
66
      helpPath: TEST_HELP_PATH,
67
      illustrationPath: TEST_SVG_PATH,
68
      ...getters.allCheck(),
69 70
    });
  });
71

Paul Slaughter's avatar
Paul Slaughter committed
72
  it('hides splash and starts, when started', () => {
73 74
    factory();

Paul Slaughter's avatar
Paul Slaughter committed
75
    expect(actions.startSession).not.toHaveBeenCalled();
76 77 78 79
    expect(actions.hideSplash).not.toHaveBeenCalled();

    wrapper.find(TerminalEmptyState).vm.$emit('start');

Paul Slaughter's avatar
Paul Slaughter committed
80
    expect(actions.startSession).toHaveBeenCalled();
81 82 83 84 85 86 87 88
    expect(actions.hideSplash).toHaveBeenCalled();
  });

  it('shows Web Terminal when started', () => {
    state.isShowSplash = false;
    factory();

    expect(wrapper.find(TerminalEmptyState).exists()).toBe(false);
Paul Slaughter's avatar
Paul Slaughter committed
89
    expect(wrapper.find(TerminalSession).exists()).toBe(true);
90
  });
91
});