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';
|
|
|
|
import { initMembersApp } from '~/members/index';
|
|
|
|
import { membersJsonString, members } 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-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');
|
|
|
|
el.setAttribute('data-members', membersJsonString);
|
2021-03-11 19:13:27 +05:30
|
|
|
el.setAttribute('data-source-id', '234');
|
2021-02-22 17:27:13 +05:30
|
|
|
el.setAttribute('data-can-manage-members', 'true');
|
2021-01-03 14:25:43 +05:30
|
|
|
el.setAttribute('data-member-path', '/groups/foo-bar/-/group_members/:id');
|
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('sets `currentUserId` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.currentUserId).toBe(123);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `gon.current_user_id` is not set (user is not logged in)', () => {
|
|
|
|
it('sets `currentUserId` as `null` in Vuex store', () => {
|
|
|
|
window.gon = {};
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.currentUserId).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('parses and sets `data-source-id` as `sourceId` in Vuex store', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.sourceId).toBe(234);
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('parses and sets `data-can-manage-members` as `canManageMembers` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.canManageMembers).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('parses and sets `members` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(vm.$store.state.members).toEqual(members);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it('sets `tableFields` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.tableFields).toEqual(['account']);
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('sets `tableAttrs` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.tableAttrs).toEqual({ table: { 'data-qa-selector': 'members_list' } });
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('sets `tableSortableFields` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.tableSortableFields).toEqual(['account']);
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('sets `requestFormatter` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.requestFormatter()).toEqual({});
|
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('sets `filteredSearchBar` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.filteredSearchBar).toEqual({ show: false });
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('sets `memberPath` in Vuex store', () => {
|
|
|
|
setup();
|
|
|
|
|
|
|
|
expect(vm.$store.state.memberPath).toBe('/groups/foo-bar/-/group_members/:id');
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|