diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:16 +0000 |
commit | 154b9bae142ba15fec753f44327654595094b879 (patch) | |
tree | 027f8ae024961778d5b00c77a72fe302f985d4f3 /spec/frontend | |
parent | 2c156e3c7bbade01c36eee18327f1ced6eebea79 (diff) | |
download | gitlab-ce-154b9bae142ba15fec753f44327654595094b879.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js | 28 | ||||
-rw-r--r-- | spec/frontend/ci_variable_list/stubs.js | 14 |
2 files changed, 34 insertions, 8 deletions
diff --git a/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js b/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js index 8db6626fca3..058aca16ea0 100644 --- a/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js +++ b/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js @@ -1,9 +1,10 @@ import Vuex from 'vuex'; import { createLocalVue, shallowMount } from '@vue/test-utils'; -import { GlModal } from '@gitlab/ui'; +import { GlButton } from '@gitlab/ui'; import CiVariableModal from '~/ci_variable_list/components/ci_variable_modal.vue'; import createStore from '~/ci_variable_list/store'; import mockData from '../services/mock_data'; +import ModalStub from '../stubs'; const localVue = createLocalVue(); localVue.use(Vuex); @@ -15,12 +16,23 @@ describe('Ci variable modal', () => { const createComponent = () => { store = createStore(); wrapper = shallowMount(CiVariableModal, { + stubs: { + GlModal: ModalStub, + }, localVue, store, }); }; - const findModal = () => wrapper.find(GlModal); + const findModal = () => wrapper.find(ModalStub); + const addOrUpdateButton = index => + findModal() + .findAll(GlButton) + .at(index); + const deleteVariableButton = () => + findModal() + .findAll(GlButton) + .at(1); beforeEach(() => { createComponent(); @@ -32,7 +44,7 @@ describe('Ci variable modal', () => { }); it('button is disabled when no key/value pair are present', () => { - expect(findModal().props('actionPrimary').attributes.disabled).toBeTruthy(); + expect(addOrUpdateButton(1).attributes('disabled')).toBeTruthy(); }); describe('Adding a new variable', () => { @@ -42,11 +54,11 @@ describe('Ci variable modal', () => { }); it('button is enabled when key/value pair are present', () => { - expect(findModal().props('actionPrimary').attributes.disabled).toBeFalsy(); + expect(addOrUpdateButton(1).attributes('disabled')).toBeFalsy(); }); it('Add variable button dispatches addVariable action', () => { - findModal().vm.$emit('ok'); + addOrUpdateButton(1).vm.$emit('click'); expect(store.dispatch).toHaveBeenCalledWith('addVariable'); }); @@ -63,11 +75,11 @@ describe('Ci variable modal', () => { }); it('button text is Update variable when updating', () => { - expect(wrapper.vm.modalActionText).toBe('Update variable'); + expect(addOrUpdateButton(2).text()).toBe('Update variable'); }); it('Update variable button dispatches updateVariable with correct variable', () => { - findModal().vm.$emit('ok'); + addOrUpdateButton(2).vm.$emit('click'); expect(store.dispatch).toHaveBeenCalledWith( 'updateVariable', store.state.variableBeingEdited, @@ -80,7 +92,7 @@ describe('Ci variable modal', () => { }); it('dispatches deleteVariable with correct variable to delete', () => { - findModal().vm.$emit('secondary'); + deleteVariableButton().vm.$emit('click'); expect(store.dispatch).toHaveBeenCalledWith('deleteVariable', mockData.mockVariables[0]); }); }); diff --git a/spec/frontend/ci_variable_list/stubs.js b/spec/frontend/ci_variable_list/stubs.js new file mode 100644 index 00000000000..5769d6190f6 --- /dev/null +++ b/spec/frontend/ci_variable_list/stubs.js @@ -0,0 +1,14 @@ +const ModalStub = { + name: 'glmodal-stub', + template: ` + <div> + <slot></slot> + <slot name="modal-footer"></slot> + </div> + `, + methods: { + hide: jest.fn(), + }, +}; + +export default ModalStub; |