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
|
import { GlLoadingIcon, GlEmptyState } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { organizations } from '~/organizations/mock_data';
import OrganizationsView from '~/organizations/index/components/organizations_view.vue';
import OrganizationsList from '~/organizations/index/components/organizations_list.vue';
import { MOCK_NEW_ORG_URL, MOCK_ORG_EMPTY_STATE_SVG } from '../mock_data';
describe('OrganizationsView', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = shallowMount(OrganizationsView, {
propsData: {
...props,
},
provide: {
newOrganizationUrl: MOCK_NEW_ORG_URL,
organizationsEmptyStateSvgPath: MOCK_ORG_EMPTY_STATE_SVG,
},
});
};
const findGlLoading = () => wrapper.findComponent(GlLoadingIcon);
const findOrganizationsList = () => wrapper.findComponent(OrganizationsList);
const findGlEmptyState = () => wrapper.findComponent(GlEmptyState);
describe.each`
description | loading | orgsData | emptyStateSvg | emptyStateUrl
${'when loading'} | ${true} | ${[]} | ${false} | ${false}
${'when not loading and has organizations'} | ${false} | ${organizations} | ${false} | ${false}
${'when not loading and has no organizations'} | ${false} | ${[]} | ${MOCK_ORG_EMPTY_STATE_SVG} | ${MOCK_NEW_ORG_URL}
`('$description', ({ loading, orgsData, emptyStateSvg, emptyStateUrl }) => {
beforeEach(() => {
createComponent({ loading, organizations: orgsData });
});
it(`does ${loading ? '' : 'not '}render loading icon`, () => {
expect(findGlLoading().exists()).toBe(loading);
});
it(`does ${orgsData.length ? '' : 'not '}render organizations list`, () => {
expect(findOrganizationsList().exists()).toBe(Boolean(orgsData.length));
});
it(`does ${emptyStateSvg ? '' : 'not '}render empty state with SVG`, () => {
expect(findGlEmptyState().exists() && findGlEmptyState().attributes('svgpath')).toBe(
emptyStateSvg,
);
});
it(`does ${emptyStateUrl ? '' : 'not '}render empty state with URL`, () => {
expect(
findGlEmptyState().exists() && findGlEmptyState().attributes('primarybuttonlink'),
).toBe(emptyStateUrl);
});
});
});
|