diff options
Diffstat (limited to 'spec/frontend/ide/components/commit_sidebar/stage_button_spec.js')
-rw-r--r-- | spec/frontend/ide/components/commit_sidebar/stage_button_spec.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/ide/components/commit_sidebar/stage_button_spec.js b/spec/frontend/ide/components/commit_sidebar/stage_button_spec.js new file mode 100644 index 00000000000..b59de4dac0e --- /dev/null +++ b/spec/frontend/ide/components/commit_sidebar/stage_button_spec.js @@ -0,0 +1,46 @@ +import Vue from 'vue'; +import store from '~/ide/stores'; +import stageButton from '~/ide/components/commit_sidebar/stage_button.vue'; +import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; +import { file, resetStore } from '../../helpers'; + +describe('IDE stage file button', () => { + let vm; + let f; + + beforeEach(() => { + const Component = Vue.extend(stageButton); + f = file(); + + vm = createComponentWithStore(Component, store, { + path: f.path, + }); + + jest.spyOn(vm, 'stageChange').mockImplementation(() => {}); + jest.spyOn(vm, 'discardFileChanges').mockImplementation(() => {}); + + vm.$mount(); + }); + + afterEach(() => { + vm.$destroy(); + + resetStore(vm.$store); + }); + + it('renders button to discard & stage', () => { + expect(vm.$el.querySelectorAll('.btn-blank').length).toBe(2); + }); + + it('calls store with stage button', () => { + vm.$el.querySelectorAll('.btn')[0].click(); + + expect(vm.stageChange).toHaveBeenCalledWith(f.path); + }); + + it('calls store with discard button', () => { + vm.$el.querySelector('.btn-danger').click(); + + expect(vm.discardFileChanges).toHaveBeenCalledWith(f.path); + }); +}); |