debian-mirror-gitlab/spec/javascripts/repo/components/repo_commit_section_spec.js

141 lines
4 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import * as urlUtils from '~/lib/utils/url_utility';
import store from '~/ide/stores';
import service from '~/ide/services';
import repoCommitSection from '~/ide/components/repo_commit_section.vue';
import getSetTimeoutPromise from '../../helpers/set_timeout_promise_helper';
import { file, resetStore } from '../helpers';
2017-09-10 17:25:29 +05:30
describe('RepoCommitSection', () => {
2018-03-17 18:26:18 +05:30
let vm;
function createComponent() {
2017-09-10 17:25:29 +05:30
const RepoCommitSection = Vue.extend(repoCommitSection);
2018-03-17 18:26:18 +05:30
const comp = new RepoCommitSection({
store,
}).$mount();
comp.$store.state.currentProjectId = 'abcproject';
comp.$store.state.currentBranchId = 'master';
comp.$store.state.projects.abcproject = {
web_url: '',
branches: {
master: {
workingReference: '1',
},
},
};
comp.$store.state.rightPanelCollapsed = false;
comp.$store.state.currentBranch = 'master';
comp.$store.state.openFiles = [file('file1'), file('file2')];
comp.$store.state.openFiles.forEach(f => Object.assign(f, {
changed: true,
content: 'testing',
}));
return comp.$mount();
2017-09-10 17:25:29 +05:30
}
2018-03-17 18:26:18 +05:30
beforeEach((done) => {
vm = createComponent();
spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({
headers: {
'page-title': 'test',
},
json: () => Promise.resolve({
last_commit_path: 'last_commit_path',
parent_tree_url: 'parent_tree_url',
path: '/',
trees: [{ name: 'tree' }],
blobs: [{ name: 'blob' }],
submodules: [{ name: 'submodule' }],
}),
}));
Vue.nextTick(done);
});
afterEach(() => {
vm.$destroy();
resetStore(vm.$store);
});
2017-09-10 17:25:29 +05:30
it('renders a commit section', () => {
2018-03-17 18:26:18 +05:30
const changedFileElements = [...vm.$el.querySelectorAll('.multi-file-commit-list li')];
const submitCommit = vm.$el.querySelector('form .btn');
expect(vm.$el.querySelector('.multi-file-commit-form')).not.toBeNull();
2017-09-10 17:25:29 +05:30
expect(changedFileElements.length).toEqual(2);
changedFileElements.forEach((changedFile, i) => {
2018-03-17 18:26:18 +05:30
expect(changedFile.textContent.trim()).toEqual(vm.$store.getters.changedFiles[i].path);
2017-09-10 17:25:29 +05:30
});
expect(submitCommit.disabled).toBeTruthy();
2018-03-17 18:26:18 +05:30
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeNull();
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
describe('when submitting', () => {
let changedFiles;
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
beforeEach(() => {
vm.commitMessage = 'testing';
changedFiles = JSON.parse(JSON.stringify(vm.$store.getters.changedFiles));
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
spyOn(service, 'commit').and.returnValue(Promise.resolve({
data: {
short_id: '1',
stats: {},
},
}));
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
it('allows you to submit', () => {
expect(vm.$el.querySelector('form .btn').disabled).toBeTruthy();
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
it('submits commit', (done) => {
vm.makeCommit();
// Wait for the branch check to finish
getSetTimeoutPromise()
.then(() => Vue.nextTick())
.then(() => {
const args = service.commit.calls.allArgs()[0];
const { commit_message, actions, branch: payloadBranch } = args[1];
expect(commit_message).toBe('testing');
expect(actions.length).toEqual(2);
expect(payloadBranch).toEqual('master');
expect(actions[0].action).toEqual('update');
expect(actions[1].action).toEqual('update');
expect(actions[0].content).toEqual(changedFiles[0].content);
expect(actions[1].content).toEqual(changedFiles[1].content);
expect(actions[0].file_path).toEqual(changedFiles[0].path);
expect(actions[1].file_path).toEqual(changedFiles[1].path);
})
.then(done)
.catch(done.fail);
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
it('redirects to MR creation page if start new MR checkbox checked', (done) => {
spyOn(urlUtils, 'visitUrl');
vm.startNewMR = true;
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
vm.makeCommit();
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
getSetTimeoutPromise()
.then(() => Vue.nextTick())
.then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
2017-09-10 17:25:29 +05:30
});
});
});