blob: e4fb09b70a4fa24c2e5649d665480b296d51a8d2 (
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
|
import { GlLoadingIcon } from '@gitlab/ui';
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import LoadingIndicator from '~/content_editor/components/loading_indicator.vue';
import EditorStateObserver from '~/content_editor/components/editor_state_observer.vue';
import {
LOADING_CONTENT_EVENT,
LOADING_SUCCESS_EVENT,
LOADING_ERROR_EVENT,
} from '~/content_editor/constants';
describe('content_editor/components/loading_indicator', () => {
let wrapper;
const findEditorStateObserver = () => wrapper.findComponent(EditorStateObserver);
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const createWrapper = () => {
wrapper = shallowMountExtended(LoadingIndicator);
};
afterEach(() => {
wrapper.destroy();
});
describe('when loading content', () => {
beforeEach(async () => {
createWrapper();
findEditorStateObserver().vm.$emit(LOADING_CONTENT_EVENT);
await nextTick();
});
it('displays loading indicator', () => {
expect(findLoadingIcon().exists()).toBe(true);
});
});
describe('when loading content succeeds', () => {
beforeEach(async () => {
createWrapper();
findEditorStateObserver().vm.$emit(LOADING_CONTENT_EVENT);
await nextTick();
findEditorStateObserver().vm.$emit(LOADING_SUCCESS_EVENT);
await nextTick();
});
it('hides loading indicator', () => {
expect(findLoadingIcon().exists()).toBe(false);
});
});
describe('when loading content fails', () => {
const error = 'error';
beforeEach(async () => {
createWrapper();
findEditorStateObserver().vm.$emit(LOADING_CONTENT_EVENT);
await nextTick();
findEditorStateObserver().vm.$emit(LOADING_ERROR_EVENT, error);
await nextTick();
});
it('hides loading indicator', () => {
expect(findLoadingIcon().exists()).toBe(false);
});
});
});
|