diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/frontend/members/components/app_spec.js | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/frontend/members/components/app_spec.js')
-rw-r--r-- | spec/frontend/members/components/app_spec.js | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/frontend/members/components/app_spec.js b/spec/frontend/members/components/app_spec.js new file mode 100644 index 00000000000..a1329c3ee9f --- /dev/null +++ b/spec/frontend/members/components/app_spec.js @@ -0,0 +1,95 @@ +import { GlAlert } from '@gitlab/ui'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import Vuex from 'vuex'; +import * as commonUtils from '~/lib/utils/common_utils'; +import MembersApp from '~/members/components/app.vue'; +import FilterSortContainer from '~/members/components/filter_sort/filter_sort_container.vue'; +import { RECEIVE_MEMBER_ROLE_ERROR, HIDE_ERROR } from '~/members/store/mutation_types'; +import mutations from '~/members/store/mutations'; + +describe('MembersApp', () => { + const localVue = createLocalVue(); + localVue.use(Vuex); + + let wrapper; + let store; + + const createComponent = (state = {}, options = {}) => { + store = new Vuex.Store({ + state: { + showError: true, + errorMessage: 'Something went wrong, please try again.', + ...state, + }, + mutations, + }); + + wrapper = shallowMount(MembersApp, { + localVue, + store, + ...options, + }); + }; + + const findAlert = () => wrapper.find(GlAlert); + const findFilterSortContainer = () => wrapper.find(FilterSortContainer); + + 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: '' }); + + store.commit(RECEIVE_MEMBER_ROLE_ERROR, { error: new Error('Network Error') }); + + 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); + }); + }); + + it('renders `FilterSortContainer`', () => { + createComponent(); + + expect(findFilterSortContainer().exists()).toBe(true); + }); +}); |