debian-mirror-gitlab/spec/frontend/groups/members/index_spec.js
2021-02-22 17:27:13 +05:30

113 lines
2.9 KiB
JavaScript

import { createWrapper } from '@vue/test-utils';
import { initGroupMembersApp } from '~/groups/members';
import GroupMembersApp from '~/groups/members/components/app.vue';
import { membersJsonString, membersParsed } from './mock_data';
describe('initGroupMembersApp', () => {
let el;
let vm;
let wrapper;
const setup = () => {
vm = initGroupMembersApp(el, {
tableFields: ['account'],
tableAttrs: { table: { 'data-qa-selector': 'members_list' } },
tableSortableFields: ['account'],
requestFormatter: () => ({}),
filteredSearchBar: { show: false },
});
wrapper = createWrapper(vm);
};
beforeEach(() => {
el = document.createElement('div');
el.setAttribute('data-members', membersJsonString);
el.setAttribute('data-group-id', '234');
el.setAttribute('data-can-manage-members', 'true');
el.setAttribute('data-member-path', '/groups/foo-bar/-/group_members/:id');
window.gon = { current_user_id: 123 };
});
afterEach(() => {
el = null;
wrapper.destroy();
wrapper = null;
});
it('renders `GroupMembersApp`', () => {
setup();
expect(wrapper.find(GroupMembersApp).exists()).toBe(true);
});
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();
});
});
it('parses and sets `data-group-id` as `sourceId` in Vuex store', () => {
setup();
expect(vm.$store.state.sourceId).toBe(234);
});
it('parses and sets `data-can-manage-members` as `canManageMembers` in Vuex store', () => {
setup();
expect(vm.$store.state.canManageMembers).toBe(true);
});
it('parses and sets `members` in Vuex store', () => {
setup();
expect(vm.$store.state.members).toEqual(membersParsed);
});
it('sets `tableFields` in Vuex store', () => {
setup();
expect(vm.$store.state.tableFields).toEqual(['account']);
});
it('sets `tableAttrs` in Vuex store', () => {
setup();
expect(vm.$store.state.tableAttrs).toEqual({ table: { 'data-qa-selector': 'members_list' } });
});
it('sets `tableSortableFields` in Vuex store', () => {
setup();
expect(vm.$store.state.tableSortableFields).toEqual(['account']);
});
it('sets `requestFormatter` in Vuex store', () => {
setup();
expect(vm.$store.state.requestFormatter()).toEqual({});
});
it('sets `filteredSearchBar` in Vuex store', () => {
setup();
expect(vm.$store.state.filteredSearchBar).toEqual({ show: false });
});
it('sets `memberPath` in Vuex store', () => {
setup();
expect(vm.$store.state.memberPath).toBe('/groups/foo-bar/-/group_members/:id');
});
});