2021-02-14 13:09:20 -05:00
|
|
|
import { GlAlert } from '@gitlab/ui';
|
2020-10-14 14:08:47 -04:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import { nextTick } from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
2021-02-14 13:09:20 -05:00
|
|
|
import * as commonUtils from '~/lib/utils/common_utils';
|
2021-01-21 07:09:05 -05:00
|
|
|
import MembersApp from '~/members/components/app.vue';
|
2020-12-03 01:09:47 -05:00
|
|
|
import FilterSortContainer from '~/members/components/filter_sort/filter_sort_container.vue';
|
2021-06-22 23:07:43 -04:00
|
|
|
import MembersTable from '~/members/components/table/members_table.vue';
|
|
|
|
import { MEMBER_TYPES, TAB_QUERY_PARAM_VALUES } from '~/members/constants';
|
2020-11-19 07:09:26 -05:00
|
|
|
import { RECEIVE_MEMBER_ROLE_ERROR, HIDE_ERROR } from '~/members/store/mutation_types';
|
|
|
|
import mutations from '~/members/store/mutations';
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2021-01-21 07:09:05 -05:00
|
|
|
describe('MembersApp', () => {
|
2020-10-14 14:08:47 -04:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
2020-12-03 01:09:47 -05:00
|
|
|
const createComponent = (state = {}, options = {}) => {
|
2020-10-14 14:08:47 -04:00
|
|
|
store = new Vuex.Store({
|
2021-04-13 17:11:25 -04:00
|
|
|
modules: {
|
2021-06-22 23:07:43 -04:00
|
|
|
[MEMBER_TYPES.group]: {
|
2021-04-13 17:11:25 -04:00
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
showError: true,
|
|
|
|
errorMessage: 'Something went wrong, please try again.',
|
|
|
|
...state,
|
|
|
|
},
|
|
|
|
mutations,
|
|
|
|
},
|
2020-10-14 14:08:47 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-01-21 07:09:05 -05:00
|
|
|
wrapper = shallowMount(MembersApp, {
|
2020-10-14 14:08:47 -04:00
|
|
|
localVue,
|
2021-05-19 20:10:36 -04:00
|
|
|
propsData: {
|
2021-06-22 23:07:43 -04:00
|
|
|
namespace: MEMBER_TYPES.group,
|
|
|
|
tabQueryParamValue: TAB_QUERY_PARAM_VALUES.group,
|
2021-04-13 17:11:25 -04:00
|
|
|
},
|
2020-10-14 14:08:47 -04:00
|
|
|
store,
|
2020-12-03 01:09:47 -05:00
|
|
|
...options,
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findAlert = () => wrapper.find(GlAlert);
|
2020-12-03 01:09:47 -05:00
|
|
|
const findFilterSortContainer = () => wrapper.find(FilterSortContainer);
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
commonUtils.scrollToElement = jest.fn();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
store = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `showError` is changed to `true`', () => {
|
|
|
|
it('renders and scrolls to error alert', async () => {
|
|
|
|
createComponent({ showError: false, errorMessage: '' });
|
|
|
|
|
2021-06-22 23:07:43 -04:00
|
|
|
store.commit(`${MEMBER_TYPES.group}/${RECEIVE_MEMBER_ROLE_ERROR}`, {
|
2021-04-13 17:11:25 -04:00
|
|
|
error: new Error('Network Error'),
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
const alert = findAlert();
|
|
|
|
|
|
|
|
expect(alert.exists()).toBe(true);
|
|
|
|
expect(alert.text()).toBe(
|
|
|
|
"An error occurred while updating the member's role, please try again.",
|
|
|
|
);
|
|
|
|
expect(commonUtils.scrollToElement).toHaveBeenCalledWith(alert.element);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when `showError` is changed to `false`', () => {
|
|
|
|
it('does not render and scroll to error alert', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
2021-06-22 23:07:43 -04:00
|
|
|
store.commit(`${MEMBER_TYPES.group}/${HIDE_ERROR}`);
|
2020-10-14 14:08:47 -04:00
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findAlert().exists()).toBe(false);
|
|
|
|
expect(commonUtils.scrollToElement).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when alert is dismissed', () => {
|
|
|
|
it('hides alert', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
findAlert().vm.$emit('dismiss');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findAlert().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-12-03 01:09:47 -05:00
|
|
|
|
2021-01-13 04:10:52 -05:00
|
|
|
it('renders `FilterSortContainer`', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findFilterSortContainer().exists()).toBe(true);
|
|
|
|
});
|
2021-06-22 23:07:43 -04:00
|
|
|
|
|
|
|
it('renders `MembersTable` component and passes `tabQueryParamValue` prop', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
const membersTableComponent = wrapper.findComponent(MembersTable);
|
|
|
|
|
|
|
|
expect(membersTableComponent.exists()).toBe(true);
|
|
|
|
expect(membersTableComponent.props('tabQueryParamValue')).toBe(TAB_QUERY_PARAM_VALUES.group);
|
|
|
|
});
|
2020-10-14 14:08:47 -04:00
|
|
|
});
|