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