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 }) => ...@@ -41,7 +41,7 @@ export const checkCommitStatus = ({ rootState }) =>
export const updateFilesAfterCommit = ( export const updateFilesAfterCommit = (
{ commit, dispatch, state, rootState, rootGetters }, { commit, dispatch, state, rootState, rootGetters },
{ data, branch }, { data },
) => { ) => {
const selectedProject = rootState.projects[rootState.currentProjectId]; const selectedProject = rootState.projects[rootState.currentProjectId];
const lastCommit = { const lastCommit = {
...@@ -82,9 +82,7 @@ export const updateFilesAfterCommit = ( ...@@ -82,9 +82,7 @@ export const updateFilesAfterCommit = (
commit(rootTypes.REMOVE_ALL_CHANGES_FILES, null, { root: true }); commit(rootTypes.REMOVE_ALL_CHANGES_FILES, null, { root: true });
if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH) { if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH) {
const fileUrl = rootGetters.activeFile.url.replace(rootState.currentBranchId, branch); router.push(`/project/${rootState.currentProjectId}/blob/branch/${rootGetters.activeFile.path}`);
router.push(`/project${fileUrl}`);
} }
window.scrollTo(0, 0); window.scrollTo(0, 0);
......
import Vue from 'vue'; import Vue from 'vue';
import * as urlUtils from '~/lib/utils/url_utility';
import store from '~/ide/stores'; import store from '~/ide/stores';
import service from '~/ide/services'; import service from '~/ide/services';
import repoCommitSection from '~/ide/components/repo_commit_section.vue'; import repoCommitSection from '~/ide/components/repo_commit_section.vue';
...@@ -76,8 +75,6 @@ describe('RepoCommitSection', () => { ...@@ -76,8 +75,6 @@ describe('RepoCommitSection', () => {
committedStateSvgPath: 'svg', committedStateSvgPath: 'svg',
}).$mount(); }).$mount();
// Vue.nextTick();
expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('No changes'); expect(vm.$el.querySelector('.js-empty-state').textContent.trim()).toContain('No changes');
expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('nochangessvg'); expect(vm.$el.querySelector('.js-empty-state img').getAttribute('src')).toBe('nochangessvg');
}); });
...@@ -98,62 +95,54 @@ describe('RepoCommitSection', () => { ...@@ -98,62 +95,54 @@ describe('RepoCommitSection', () => {
expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeNull(); expect(submitCommit.querySelector('.fa-spinner.fa-spin')).toBeNull();
}); });
describe('when submitting', () => { it('updates commitMessage in store on input', (done) => {
let changedFiles; const textarea = vm.$el.querySelector('textarea');
beforeEach(() => { textarea.value = 'testing commit message';
vm.commitMessage = 'testing';
changedFiles = JSON.parse(JSON.stringify(vm.$store.state.changedFiles));
spyOn(service, 'commit').and.returnValue(Promise.resolve({ textarea.dispatchEvent(new Event('input'));
data: {
short_id: '1', getSetTimeoutPromise()
stats: {}, .then(() => {
}, expect(vm.$store.state.commit.commitMessage).toBe('testing commit message');
})); })
}); .then(done)
.catch(done.fail);
});
it('allows you to submit', () => { describe('discard draft button', () => {
expect(vm.$el.querySelector('form .btn').disabled).toBeTruthy(); it('disabled when commitMessage is empty', () => {
expect(vm.$el.querySelector('.multi-file-commit-form .btn-default').getAttribute('disabled')).not.toBeNull();
}); });
it('submits commit', (done) => { it('resets commitMessage when clicking discard button', (done) => {
vm.makeCommit(); vm.$store.state.commitMessage = 'testinig commit message';
// Wait for the branch check to finish
getSetTimeoutPromise() getSetTimeoutPromise()
.then(() => Vue.nextTick())
.then(() => { .then(() => {
const args = service.commit.calls.allArgs()[0]; vm.$el.querySelector('.multi-file-commit-form .btn-default').click();
const { commit_message, actions, branch: payloadBranch } = args[1]; })
.then(Vue.nextTick)
expect(commit_message).toBe('testing'); .then(() => {
expect(actions.length).toEqual(2); expect(vm.$store.state.commit.commitMessage).not.toBe('testing commit message');
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');
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
});
it('redirects to MR creation page if start new MR checkbox checked', (done) => { describe('when submitting', () => {
spyOn(urlUtils, 'visitUrl'); beforeEach(() => {
vm.startNewMR = true; 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() Vue.nextTick()
.then(() => Vue.nextTick())
.then(() => { .then(() => {
expect(urlUtils.visitUrl).toHaveBeenCalled(); expect(vm.commitChanges).toHaveBeenCalled();
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
import { decorateData } from '~/ide/stores/utils'; import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state'; import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
export const resetStore = (store) => { export const resetStore = (store) => {
store.replaceState(state()); store.replaceState(state());
Object.assign(store.state, {
commit: commitState(),
});
}; };
export const file = (name = 'name', id = name, type = '') => decorateData({ 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