Commit f9935aab authored by Phil Hughes's avatar Phil Hughes

fixed repo_commit_section specs

parent 85ec068e
......@@ -41,7 +41,7 @@ export const checkCommitStatus = ({ rootState }) =>
export const updateFilesAfterCommit = (
{ commit, dispatch, state, rootState, rootGetters },
{ data, branch },
{ data },
) => {
const selectedProject = rootState.projects[rootState.currentProjectId];
const lastCommit = {
......@@ -82,9 +82,7 @@ export const updateFilesAfterCommit = (
commit(rootTypes.REMOVE_ALL_CHANGES_FILES, null, { root: true });
if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH) {
const fileUrl = rootGetters.activeFile.url.replace(rootState.currentBranchId, branch);
router.push(`/project${fileUrl}`);
router.push(`/project/${rootState.currentProjectId}/blob/branch/${rootGetters.activeFile.path}`);
}
window.scrollTo(0, 0);
......
import Vue from 'vue';
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';
......@@ -76,8 +75,6 @@ describe('RepoCommitSection', () => {
committedStateSvgPath: 'svg',
}).$mount();
// Vue.nextTick();
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('No changes');
expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('nochangessvg');
});
......@@ -98,62 +95,54 @@ describe('RepoCommitSection', () => {
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeNull();
});
describe('when submitting', () => {
let changedFiles;
it('updates commitMessage in store on input', (done) => {
const textarea = vm.$el.querySelector('textarea');
beforeEach(() => {
vm.commitMessage = 'testing';
changedFiles = JSON.parse(JSON.stringify(vm.$store.state.changedFiles));
textarea.value = 'testing commit message';
spyOn(service, 'commit').and.returnValue(Promise.resolve({
data: {
short_id: '1',
stats: {},
},
}));
});
textarea.dispatchEvent(new Event('input'));
getSetTimeoutPromise()
.then(() => {
expect(vm.$store.state.commit.commitMessage).toBe('testing commit message');
})
.then(done)
.catch(done.fail);
});
it('allows you to submit', () => {
expect(vm.$el.querySelector('form .btn').disabled).toBeTruthy();
describe('discard draft button', () => {
it('disabled when commitMessage is empty', () => {
expect(vm.$el.querySelector('.multi-file-commit-form .btn-default').getAttribute('disabled')).not.toBeNull();
});
it('submits commit', (done) => {
vm.makeCommit();
it('resets commitMessage when clicking discard button', (done) => {
vm.$store.state.commitMessage = 'testinig commit message';
// 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);
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('All changes are committed');
expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('commitsvg');
vm.$el.querySelector('.multi-file-commit-form .btn-default').click();
})
.then(Vue.nextTick)
.then(() => {
expect(vm.$store.state.commit.commitMessage).not.toBe('testing commit message');
})
.then(done)
.catch(done.fail);
});
});
it('redirects to MR creation page if start new MR checkbox checked', (done) => {
spyOn(urlUtils, 'visitUrl');
vm.startNewMR = true;
describe('when submitting', () => {
beforeEach(() => {
vm.$store.state.commitMessage = 'testing';
});
vm.makeCommit();
it('calls store', (done) => {
spyOn(vm, 'commitChanges');
vm.$el.querySelector('.multi-file-commit-form .btn-success').click();
getSetTimeoutPromise()
.then(() => Vue.nextTick())
Vue.nextTick()
.then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalled();
expect(vm.commitChanges).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
......
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
export const resetStore = (store) => {
store.replaceState(state());
Object.assign(store.state, {
commit: commitState(),
});
};
export const file = (name = 'name', id = name, type = '') => decorateData({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment