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

96 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlAlert } from '@gitlab/ui';
2021-01-03 14:25:43 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue';
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-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', () => {
2021-01-03 14:25:43 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
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({
state: {
showError: true,
errorMessage: 'Something went wrong, please try again.',
...state,
},
mutations,
});
2021-03-11 19:13:27 +05:30
wrapper = shallowMount(MembersApp, {
2021-01-03 14:25:43 +05:30
localVue,
store,
2021-02-22 17:27:13 +05:30
...options,
2021-01-03 14:25:43 +05:30
});
};
const findAlert = () => wrapper.find(GlAlert);
2021-02-22 17:27:13 +05:30
const findFilterSortContainer = () => wrapper.find(FilterSortContainer);
2021-01-03 14:25:43 +05:30
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-03-11 19:13:27 +05:30
store.commit(RECEIVE_MEMBER_ROLE_ERROR, { 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();
store.commit(HIDE_ERROR);
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-01-03 14:25:43 +05:30
});