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
|
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import TerminalSyncStatus from '~/ide/components/terminal_sync/terminal_sync_status.vue';
import {
MSG_TERMINAL_SYNC_CONNECTING,
MSG_TERMINAL_SYNC_UPLOADING,
MSG_TERMINAL_SYNC_RUNNING,
} from '~/ide/stores/modules/terminal_sync/messages';
const TEST_MESSAGE = 'lorem ipsum dolar sit';
const START_LOADING = 'START_LOADING';
Vue.use(Vuex);
describe('ide/components/terminal_sync/terminal_sync_status', () => {
let moduleState;
let store;
let wrapper;
const createComponent = () => {
store = new Vuex.Store({
modules: {
terminalSync: {
namespaced: true,
state: moduleState,
mutations: {
[START_LOADING]: (state) => {
state.isLoading = true;
},
},
},
},
});
wrapper = shallowMount(TerminalSyncStatus, {
store,
});
};
beforeEach(() => {
moduleState = {
isLoading: false,
isStarted: false,
isError: false,
message: '',
};
});
describe('when doing nothing', () => {
it('shows nothing', () => {
createComponent();
expect(wrapper.html()).toBe('');
});
});
describe.each`
description | state | statusMessage | icon
${'when loading'} | ${{ isLoading: true }} | ${MSG_TERMINAL_SYNC_CONNECTING} | ${''}
${'when loading and started'} | ${{ isLoading: true, isStarted: true }} | ${MSG_TERMINAL_SYNC_UPLOADING} | ${''}
${'when error'} | ${{ isError: true, message: TEST_MESSAGE }} | ${TEST_MESSAGE} | ${'warning'}
${'when started'} | ${{ isStarted: true }} | ${MSG_TERMINAL_SYNC_RUNNING} | ${'mobile-issue-close'}
`('$description', ({ state, statusMessage, icon }) => {
beforeEach(() => {
Object.assign(moduleState, state);
createComponent();
});
it('shows message', () => {
expect(wrapper.attributes('title')).toContain(statusMessage);
});
if (!icon) {
it('does not render icon', () => {
expect(wrapper.findComponent(GlIcon).exists()).toBe(false);
});
it('renders loading icon', () => {
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
});
} else {
it('renders icon', () => {
expect(wrapper.findComponent(GlIcon).props('name')).toEqual(icon);
});
it('does not render loading icon', () => {
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
});
}
});
});
|