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
|
import { createLocalVue, mount } from '@vue/test-utils';
import { GlTable, GlLoadingIcon } from '@gitlab/ui';
import Clusters from '~/clusters_list/components/clusters.vue';
import Vuex from 'vuex';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Clusters', () => {
let wrapper;
const findTable = () => wrapper.find(GlTable);
const findLoader = () => wrapper.find(GlLoadingIcon);
const mountComponent = _state => {
const state = { clusters: [], endpoint: 'some/endpoint', ..._state };
const store = new Vuex.Store({
state,
});
wrapper = mount(Clusters, { localVue, store });
};
beforeEach(() => {
mountComponent({ loading: false });
});
describe('clusters table', () => {
it('displays a loader instead of the table while loading', () => {
mountComponent({ loading: true });
expect(findLoader().exists()).toBe(true);
expect(findTable().exists()).toBe(false);
});
it('displays a table component', () => {
expect(findTable().exists()).toBe(true);
expect(findTable().exists()).toBe(true);
});
it('renders the correct table headers', () => {
const tableHeaders = wrapper.vm.$options.fields;
const headers = findTable().findAll('th');
expect(headers.length).toBe(tableHeaders.length);
tableHeaders.forEach((headerText, i) =>
expect(headers.at(i).text()).toEqual(headerText.label),
);
});
it('should stack on smaller devices', () => {
expect(findTable().classes()).toContain('b-table-stacked-md');
});
});
});
|