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
|
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlSkeletonLoader } from '@gitlab/ui';
import createState from '~/static_site_editor/store/state';
import StaticSiteEditor from '~/static_site_editor/components/static_site_editor.vue';
import EditArea from '~/static_site_editor/components/edit_area.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('StaticSiteEditor', () => {
let wrapper;
let store;
let loadContentActionMock;
const buildStore = ({ initialState, getters } = {}) => {
loadContentActionMock = jest.fn();
store = new Vuex.Store({
state: createState(initialState),
getters: {
isContentLoaded: () => false,
...getters,
},
actions: {
loadContent: loadContentActionMock,
},
});
};
const buildWrapper = () => {
wrapper = shallowMount(StaticSiteEditor, {
localVue,
store,
});
};
const findEditArea = () => wrapper.find(EditArea);
beforeEach(() => {
buildStore();
buildWrapper();
});
afterEach(() => {
wrapper.destroy();
});
describe('when content is not loaded', () => {
it('does not render edit area', () => {
expect(findEditArea().exists()).toBe(false);
});
});
describe('when content is loaded', () => {
const content = 'edit area content';
beforeEach(() => {
buildStore({ initialState: { content }, getters: { isContentLoaded: () => true } });
buildWrapper();
});
it('renders the edit area', () => {
expect(findEditArea().exists()).toBe(true);
});
it('passes page content to edit area', () => {
expect(findEditArea().props('value')).toBe(content);
});
});
it('displays skeleton loader while loading content', () => {
buildStore({ initialState: { isLoadingContent: true } });
buildWrapper();
expect(wrapper.find(GlSkeletonLoader).exists()).toBe(true);
});
it('dispatches load content action', () => {
expect(loadContentActionMock).toHaveBeenCalled();
});
});
|