debian-mirror-gitlab/spec/frontend/ide/components/terminal/empty_state_spec.js

107 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { GlLoadingIcon, GlButton, GlAlert } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-06-23 00:09:42 +05:30
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);
2021-01-29 00:20:46 +05:30
expect(img.attributes('src')).toBe(TEST_PATH);
2020-06-23 00:09:42 +05:30
});
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,
},
});
2021-01-29 00:20:46 +05:30
button = wrapper.find(GlButton);
2020-06-23 00:09:42 +05:30
});
it('shows button', () => {
2021-01-29 00:20:46 +05:30
expect(button.text()).toBe('Start Web Terminal');
expect(button.props('disabled')).toBe(false);
2020-06-23 00:09:42 +05:30
});
it('emits start when button is clicked', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.emitted().start).toBeUndefined();
button.vm.$emit('click');
2020-06-23 00:09:42 +05:30
expect(wrapper.emitted().start).toHaveLength(1);
});
it('shows help path link', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.find('a').attributes('href')).toBe(TEST_HELP_PATH);
2020-06-23 00:09:42 +05:30
});
});
it('when not valid, shows disabled button and message', () => {
factory({
propsData: {
isLoading: false,
isValid: false,
message: TEST_HTML_MESSAGE,
},
});
2021-01-29 00:20:46 +05:30
expect(wrapper.find(GlButton).props('disabled')).toBe(true);
expect(wrapper.find(GlAlert).html()).toContain(TEST_HTML_MESSAGE);
2020-06-23 00:09:42 +05:30
});
});