summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/components
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 21:08:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 21:08:00 +0000
commitbe59dd1d43332496def276c8d3e78fc82e94273a (patch)
tree19c25e5a7e7f88a0ac4bd797bf70ac48603656cc /spec/frontend/ide/components
parent855bf0533bc5d5df2821e9a5951fae4f153f7492 (diff)
downloadgitlab-ce-be59dd1d43332496def276c8d3e78fc82e94273a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide/components')
-rw-r--r--spec/frontend/ide/components/commit_sidebar/editor_header_spec.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/spec/frontend/ide/components/commit_sidebar/editor_header_spec.js b/spec/frontend/ide/components/commit_sidebar/editor_header_spec.js
new file mode 100644
index 00000000000..ad69984fd35
--- /dev/null
+++ b/spec/frontend/ide/components/commit_sidebar/editor_header_spec.js
@@ -0,0 +1,83 @@
+import Vuex from 'vuex';
+import { mount, createLocalVue } from '@vue/test-utils';
+import { createStore } from '~/ide/stores';
+import EditorHeader from '~/ide/components/commit_sidebar/editor_header.vue';
+import { file } from '../../helpers';
+
+const localVue = createLocalVue();
+localVue.use(Vuex);
+
+describe('IDE commit editor header', () => {
+ let wrapper;
+ let f;
+ let store;
+
+ const findDiscardModal = () => wrapper.find({ ref: 'discardModal' });
+ const findDiscardButton = () => wrapper.find({ ref: 'discardButton' });
+ const findActionButton = () => wrapper.find({ ref: 'actionButton' });
+
+ beforeEach(() => {
+ f = file('file');
+ store = createStore();
+
+ wrapper = mount(EditorHeader, {
+ store,
+ localVue,
+ sync: false,
+ propsData: {
+ activeFile: f,
+ },
+ });
+
+ jest.spyOn(wrapper.vm, 'stageChange').mockImplementation();
+ jest.spyOn(wrapper.vm, 'unstageChange').mockImplementation();
+ jest.spyOn(wrapper.vm, 'discardFileChanges').mockImplementation();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ it('renders button to discard & stage', () => {
+ expect(wrapper.vm.$el.querySelectorAll('.btn').length).toBe(2);
+ });
+
+ describe('discard button', () => {
+ let modal;
+
+ beforeEach(() => {
+ modal = findDiscardModal();
+
+ jest.spyOn(modal.vm, 'show');
+
+ findDiscardButton().trigger('click');
+ });
+
+ it('opens a dialog confirming discard', () => {
+ expect(modal.vm.show).toHaveBeenCalled();
+ });
+
+ it('calls discardFileChanges if dialog result is confirmed', () => {
+ modal.vm.$emit('ok');
+
+ expect(wrapper.vm.discardFileChanges).toHaveBeenCalledWith(f.path);
+ });
+ });
+
+ describe('stage/unstage button', () => {
+ it('unstages the file if it was already staged', () => {
+ f.staged = true;
+
+ findActionButton().trigger('click');
+
+ expect(wrapper.vm.unstageChange).toHaveBeenCalledWith(f.path);
+ });
+
+ it('stages the file if it was not staged', () => {
+ findActionButton().trigger('click');
+
+ expect(wrapper.vm.stageChange).toHaveBeenCalledWith(f.path);
+ });
+ });
+});