debian-mirror-gitlab/spec/frontend/members/components/app_spec.js

115 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlAlert } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2021-01-03 14:25:43 +05:30
import Vuex from 'vuex';
import * as commonUtils from '~/lib/utils/common_utils';
2021-03-11 19:13:27 +05:30
import MembersApp from '~/members/components/app.vue';
import FilterSortContainer from '~/members/components/filter_sort/filter_sort_container.vue';
2021-09-30 23:02:18 +05:30
import MembersTable from '~/members/components/table/members_table.vue';
import { MEMBER_TYPES, TAB_QUERY_PARAM_VALUES } from '~/members/constants';
2021-02-22 17:27:13 +05:30
import { RECEIVE_MEMBER_ROLE_ERROR, HIDE_ERROR } from '~/members/store/mutation_types';
import mutations from '~/members/store/mutations';
2021-01-03 14:25:43 +05:30
2021-03-11 19:13:27 +05:30
describe('MembersApp', () => {
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2021-01-03 14:25:43 +05:30
let wrapper;
let store;
2021-02-22 17:27:13 +05:30
const createComponent = (state = {}, options = {}) => {
2021-01-03 14:25:43 +05:30
store = new Vuex.Store({
2021-04-29 21:17:54 +05:30
modules: {
2021-09-30 23:02:18 +05:30
[MEMBER_TYPES.group]: {
2021-04-29 21:17:54 +05:30
namespaced: true,
state: {
showError: true,
errorMessage: 'Something went wrong, please try again.',
...state,
},
mutations,
},
2021-01-03 14:25:43 +05:30
},
});
2021-03-11 19:13:27 +05:30
wrapper = shallowMount(MembersApp, {
2021-09-04 01:27:46 +05:30
propsData: {
2021-09-30 23:02:18 +05:30
namespace: MEMBER_TYPES.group,
tabQueryParamValue: TAB_QUERY_PARAM_VALUES.group,
2021-04-29 21:17:54 +05:30
},
2021-01-03 14:25:43 +05:30
store,
2021-02-22 17:27:13 +05:30
...options,
2021-01-03 14:25:43 +05:30
});
};
2022-08-27 11:52:29 +05:30
const findAlert = () => wrapper.findComponent(GlAlert);
const findFilterSortContainer = () => wrapper.findComponent(FilterSortContainer);
2021-01-03 14:25:43 +05:30
beforeEach(() => {
commonUtils.scrollToElement = jest.fn();
});
afterEach(() => {
store = null;
});
describe('when `showError` is changed to `true`', () => {
it('renders and scrolls to error alert', async () => {
createComponent({ showError: false, errorMessage: '' });
2021-09-30 23:02:18 +05:30
store.commit(`${MEMBER_TYPES.group}/${RECEIVE_MEMBER_ROLE_ERROR}`, {
2021-04-29 21:17:54 +05:30
error: new Error('Network Error'),
});
2021-01-03 14:25:43 +05:30
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-09-30 23:02:18 +05:30
store.commit(`${MEMBER_TYPES.group}/${HIDE_ERROR}`);
2021-01-03 14:25:43 +05:30
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);
});
});
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
it('renders `FilterSortContainer`', () => {
createComponent();
expect(findFilterSortContainer().exists()).toBe(true);
});
2021-09-30 23:02:18 +05:30
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);
});
2021-01-03 14:25:43 +05:30
});