2020-09-12 00:08:44 +00:00
|
|
|
import { createWrapper } from '@vue/test-utils';
|
2021-05-20 00:10:36 +00:00
|
|
|
import MembersTabs from '~/members/components/members_tabs.vue';
|
2021-04-13 21:11:25 +00:00
|
|
|
import { MEMBER_TYPES } from '~/members/constants';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { initMembersApp } from '~/members/index';
|
2021-05-11 18:10:36 +00:00
|
|
|
import { members, pagination, dataAttribute } from './mock_data';
|
2020-09-12 00:08:44 +00:00
|
|
|
|
2021-01-21 12:09:05 +00:00
|
|
|
describe('initMembersApp', () => {
|
2020-09-12 00:08:44 +00:00
|
|
|
let el;
|
2020-09-17 18:10:12 +00:00
|
|
|
let vm;
|
2020-09-12 00:08:44 +00:00
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const setup = () => {
|
2021-01-21 12:09:05 +00:00
|
|
|
vm = initMembersApp(el, {
|
2021-05-20 00:10:36 +00:00
|
|
|
[MEMBER_TYPES.user]: {
|
|
|
|
tableFields: ['account'],
|
|
|
|
tableAttrs: { table: { 'data-qa-selector': 'members_list' } },
|
|
|
|
tableSortableFields: ['account'],
|
|
|
|
requestFormatter: () => ({}),
|
|
|
|
filteredSearchBar: { show: false },
|
|
|
|
},
|
2020-11-29 09:09:27 +00:00
|
|
|
});
|
2020-09-12 00:08:44 +00:00
|
|
|
wrapper = createWrapper(vm);
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
el = document.createElement('div');
|
2021-05-11 18:10:36 +00:00
|
|
|
el.setAttribute('data-members-data', dataAttribute);
|
2020-09-12 00:08:44 +00:00
|
|
|
|
2020-09-17 18:10:12 +00:00
|
|
|
window.gon = { current_user_id: 123 };
|
2020-09-12 00:08:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
el = null;
|
|
|
|
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2021-05-20 00:10:36 +00:00
|
|
|
it('renders `MembersTabs`', () => {
|
2020-09-12 00:08:44 +00:00
|
|
|
setup();
|
|
|
|
|
2021-05-20 00:10:36 +00:00
|
|
|
expect(wrapper.find(MembersTabs).exists()).toBe(true);
|
2020-09-12 00:08:44 +00:00
|
|
|
});
|
2020-11-29 09:09:27 +00:00
|
|
|
|
2020-09-17 18:10:12 +00:00
|
|
|
it('parses and sets `members` in Vuex store', () => {
|
2020-09-12 00:08:44 +00:00
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].members).toEqual(members);
|
2020-09-12 00:08:44 +00:00
|
|
|
});
|
2020-09-22 15:09:37 +00:00
|
|
|
|
2021-04-22 12:09:49 +00:00
|
|
|
it('parses and sets `pagination` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].pagination).toEqual(pagination);
|
|
|
|
});
|
|
|
|
|
2020-09-22 15:09:37 +00:00
|
|
|
it('sets `tableFields` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].tableFields).toEqual(['account']);
|
2020-09-22 15:09:37 +00:00
|
|
|
});
|
2020-10-06 18:08:49 +00:00
|
|
|
|
2020-11-10 21:08:51 +00:00
|
|
|
it('sets `tableAttrs` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].tableAttrs).toEqual({
|
|
|
|
table: { 'data-qa-selector': 'members_list' },
|
|
|
|
});
|
2020-11-10 21:08:51 +00:00
|
|
|
});
|
|
|
|
|
2020-11-29 09:09:27 +00:00
|
|
|
it('sets `tableSortableFields` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].tableSortableFields).toEqual(['account']);
|
2020-11-29 09:09:27 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:08:47 +00:00
|
|
|
it('sets `requestFormatter` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].requestFormatter()).toEqual({});
|
2020-10-14 18:08:47 +00:00
|
|
|
});
|
|
|
|
|
2020-11-29 09:09:27 +00:00
|
|
|
it('sets `filteredSearchBar` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].filteredSearchBar).toEqual({ show: false });
|
2020-11-29 09:09:27 +00:00
|
|
|
});
|
|
|
|
|
2020-10-06 18:08:49 +00:00
|
|
|
it('sets `memberPath` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-04-13 21:11:25 +00:00
|
|
|
expect(vm.$store.state[MEMBER_TYPES.user].memberPath).toBe(
|
|
|
|
'/groups/foo-bar/-/group_members/:id',
|
|
|
|
);
|
2020-10-06 18:08:49 +00:00
|
|
|
});
|
2020-09-12 00:08:44 +00:00
|
|
|
});
|