summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/components/terminal/empty_state_spec.js
blob: b62470f67b60d5081f8fddfbec912b50c5598a39 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon, GlButton, GlAlert } from '@gitlab/ui';
import { TEST_HOST } from 'spec/test_constants';
import TerminalEmptyState from '~/ide/components/terminal/empty_state.vue';

const TEST_HELP_PATH = `${TEST_HOST}/help/test`;
const TEST_PATH = `${TEST_HOST}/home.png`;
const TEST_HTML_MESSAGE = 'lorem <strong>ipsum</strong>';

describe('IDE TerminalEmptyState', () => {
  let wrapper;

  const factory = (options = {}) => {
    wrapper = shallowMount(TerminalEmptyState, {
      ...options,
    });
  };

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

  it('does not show illustration, if no path specified', () => {
    factory();

    expect(wrapper.find('.svg-content').exists()).toBe(false);
  });

  it('shows illustration with path', () => {
    factory({
      propsData: {
        illustrationPath: TEST_PATH,
      },
    });

    const img = wrapper.find('.svg-content img');

    expect(img.exists()).toBe(true);
    expect(img.attributes('src')).toBe(TEST_PATH);
  });

  it('when loading, shows loading icon', () => {
    factory({
      propsData: {
        isLoading: true,
      },
    });

    expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
  });

  it('when not loading, does not show loading icon', () => {
    factory({
      propsData: {
        isLoading: false,
      },
    });

    expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
  });

  describe('when valid', () => {
    let button;

    beforeEach(() => {
      factory({
        propsData: {
          isLoading: false,
          isValid: true,
          helpPath: TEST_HELP_PATH,
        },
      });

      button = wrapper.find(GlButton);
    });

    it('shows button', () => {
      expect(button.text()).toBe('Start Web Terminal');
      expect(button.props('disabled')).toBe(false);
    });

    it('emits start when button is clicked', () => {
      expect(wrapper.emitted().start).toBeUndefined();
      button.vm.$emit('click');

      expect(wrapper.emitted().start).toHaveLength(1);
    });

    it('shows help path link', () => {
      expect(wrapper.find('a').attributes('href')).toBe(TEST_HELP_PATH);
    });
  });

  it('when not valid, shows disabled button and message', () => {
    factory({
      propsData: {
        isLoading: false,
        isValid: false,
        message: TEST_HTML_MESSAGE,
      },
    });

    expect(wrapper.find(GlButton).props('disabled')).toBe(true);
    expect(wrapper.find(GlAlert).html()).toContain(TEST_HTML_MESSAGE);
  });
});