Commit 4a4caa01 authored by Phil Hughes's avatar Phil Hughes

spec fixes

parent ba63bda9
...@@ -142,7 +142,10 @@ export const discardFileChanges = ({ state, commit }, path) => { ...@@ -142,7 +142,10 @@ export const discardFileChanges = ({ state, commit }, path) => {
commit(types.TOGGLE_FILE_OPEN, path); commit(types.TOGGLE_FILE_OPEN, path);
} }
eventHub.$emit(`editor.update.model.content.${file.path}`, file.raw); eventHub.$emit(`editor.update.model.content.${path}`, {
content: file.raw,
changed: false,
});
}; };
export const stageChange = ({ commit }, path) => { export const stageChange = ({ commit }, path) => {
......
...@@ -13,7 +13,7 @@ describe('IDE stage file button', () => { ...@@ -13,7 +13,7 @@ describe('IDE stage file button', () => {
f = file(); f = file();
vm = createComponentWithStore(Component, store, { vm = createComponentWithStore(Component, store, {
file: f, path: f.path,
}); });
spyOn(vm, 'stageChange'); spyOn(vm, 'stageChange');
...@@ -35,12 +35,12 @@ describe('IDE stage file button', () => { ...@@ -35,12 +35,12 @@ describe('IDE stage file button', () => {
it('calls store with stage button', () => { it('calls store with stage button', () => {
vm.$el.querySelectorAll('.btn')[0].click(); vm.$el.querySelectorAll('.btn')[0].click();
expect(vm.stageChange).toHaveBeenCalledWith(f); expect(vm.stageChange).toHaveBeenCalledWith(f.path);
}); });
it('calls store with discard button', () => { it('calls store with discard button', () => {
vm.$el.querySelectorAll('.btn')[1].click(); vm.$el.querySelectorAll('.btn')[1].click();
expect(vm.discardFileChanges).toHaveBeenCalledWith(f); expect(vm.discardFileChanges).toHaveBeenCalledWith(f.path);
}); });
}); });
...@@ -13,7 +13,7 @@ describe('IDE unstage file button', () => { ...@@ -13,7 +13,7 @@ describe('IDE unstage file button', () => {
f = file(); f = file();
vm = createComponentWithStore(Component, store, { vm = createComponentWithStore(Component, store, {
file: f, path: f.path,
}); });
spyOn(vm, 'unstageChange'); spyOn(vm, 'unstageChange');
...@@ -34,6 +34,6 @@ describe('IDE unstage file button', () => { ...@@ -34,6 +34,6 @@ describe('IDE unstage file button', () => {
it('calls store with unnstage button', () => { it('calls store with unnstage button', () => {
vm.$el.querySelector('.btn').click(); vm.$el.querySelector('.btn').click();
expect(vm.unstageChange).toHaveBeenCalledWith(f); expect(vm.unstageChange).toHaveBeenCalledWith(f.path);
}); });
}); });
...@@ -52,6 +52,10 @@ describe('RepoCommitSection', () => { ...@@ -52,6 +52,10 @@ describe('RepoCommitSection', () => {
}), }),
); );
vm.$store.state.changedFiles.forEach(f => {
vm.$store.state.entries[f.path] = f;
});
return vm.$mount(); return vm.$mount();
} }
......
...@@ -298,6 +298,10 @@ describe('Multi-file store actions', () => { ...@@ -298,6 +298,10 @@ describe('Multi-file store actions', () => {
store.state.changedFiles.push(f); store.state.changedFiles.push(f);
store.state.changedFiles.push(file('new')); store.state.changedFiles.push(file('new'));
store.state.changedFiles.forEach(localFile => {
store.state.entries[localFile.path] = localFile;
});
store store
.dispatch('stageAllChanges') .dispatch('stageAllChanges')
.then(() => { .then(() => {
...@@ -308,23 +312,6 @@ describe('Multi-file store actions', () => { ...@@ -308,23 +312,6 @@ describe('Multi-file store actions', () => {
}) })
.catch(done.fail); .catch(done.fail);
}); });
it('sets all files from changedFiles as staged after adding to stagedFiles', done => {
store.state.changedFiles.push(file());
store.state.changedFiles.push(file('new'));
store
.dispatch('stageAllChanges')
.then(() => {
expect(store.state.changedFiles.length).toBe(2);
store.state.changedFiles.forEach(f => {
expect(f.staged).toBeTruthy();
});
done();
})
.catch(done.fail);
});
}); });
describe('unstageAllChanges', () => { describe('unstageAllChanges', () => {
...@@ -340,20 +327,10 @@ describe('Multi-file store actions', () => { ...@@ -340,20 +327,10 @@ describe('Multi-file store actions', () => {
store.state.changedFiles.push({ store.state.changedFiles.push({
...f, ...f,
}); });
});
it('sets staged to false in changedFiles when unstaging', done => {
store.state.stagedFiles.push(f);
store
.dispatch('unstageAllChanges')
.then(() => {
expect(store.state.stagedFiles.length).toBe(0);
expect(store.state.changedFiles[0].staged).toBeFalsy();
done(); store.state.changedFiles.forEach(localFile => {
}) store.state.entries[localFile.path] = localFile;
.catch(done.fail); });
}); });
it('removes all files from stagedFiles after unstaging', done => { it('removes all files from stagedFiles after unstaging', done => {
......
...@@ -212,14 +212,14 @@ describe('IDE commit module actions', () => { ...@@ -212,14 +212,14 @@ describe('IDE commit module actions', () => {
}, },
}, },
}; };
store.state.changedFiles.push(f, { store.state.stagedFiles.push(f, {
...file('changedFile2'), ...file('changedFile2'),
changed: true, changed: true,
}); });
store.state.openFiles = store.state.changedFiles; store.state.openFiles = store.state.stagedFiles;
store.state.changedFiles.forEach(changedFile => { store.state.stagedFiles.forEach(stagedFile => {
store.state.entries[changedFile.path] = changedFile; store.state.entries[stagedFile.path] = stagedFile;
}); });
}); });
...@@ -253,19 +253,6 @@ describe('IDE commit module actions', () => { ...@@ -253,19 +253,6 @@ describe('IDE commit module actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('removes all changed files', done => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
expect(store.state.changedFiles.length).toBe(0);
})
.then(done)
.catch(done.fail);
});
it('sets files commit data', done => { it('sets files commit data', done => {
store store
.dispatch('commit/updateFilesAfterCommit', { .dispatch('commit/updateFilesAfterCommit', {
...@@ -301,7 +288,7 @@ describe('IDE commit module actions', () => { ...@@ -301,7 +288,7 @@ describe('IDE commit module actions', () => {
.then(() => { .then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith(
`editor.update.model.content.${f.path}`, `editor.update.model.content.${f.path}`,
f.content, { content: f.content, changed: false },
); );
}) })
.then(done) .then(done)
...@@ -485,6 +472,16 @@ describe('IDE commit module actions', () => { ...@@ -485,6 +472,16 @@ describe('IDE commit module actions', () => {
}) })
.catch(done.fail); .catch(done.fail);
}); });
it('removes all staged files', done => {
store
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.stagedFiles.length).toBe(0);
})
.then(done)
.catch(done.fail);
});
}); });
describe('failed', () => { describe('failed', () => {
......
...@@ -34,17 +34,17 @@ describe('IDE commit module getters', () => { ...@@ -34,17 +34,17 @@ describe('IDE commit module getters', () => {
discardDraftButtonDisabled: false, discardDraftButtonDisabled: false,
}; };
const rootState = { const rootState = {
changedFiles: ['a'], stagedFiles: ['a'],
}; };
it('returns false when discardDraftButtonDisabled is false & changedFiles is not empty', () => { it('returns false when discardDraftButtonDisabled is false & stagedFiles is not empty', () => {
expect( expect(
getters.commitButtonDisabled(state, localGetters, rootState), getters.commitButtonDisabled(state, localGetters, rootState),
).toBeFalsy(); ).toBeFalsy();
}); });
it('returns true when discardDraftButtonDisabled is false & changedFiles is empty', () => { it('returns true when discardDraftButtonDisabled is false & stagedFiles is empty', () => {
rootState.changedFiles.length = 0; rootState.stagedFiles.length = 0;
expect( expect(
getters.commitButtonDisabled(state, localGetters, rootState), getters.commitButtonDisabled(state, localGetters, rootState),
...@@ -61,7 +61,7 @@ describe('IDE commit module getters', () => { ...@@ -61,7 +61,7 @@ describe('IDE commit module getters', () => {
it('returns true when discardDraftButtonDisabled is false & changedFiles is not empty', () => { it('returns true when discardDraftButtonDisabled is false & changedFiles is not empty', () => {
localGetters.discardDraftButtonDisabled = false; localGetters.discardDraftButtonDisabled = false;
rootState.changedFiles.length = 0; rootState.stagedFiles.length = 0;
expect( expect(
getters.commitButtonDisabled(state, localGetters, rootState), getters.commitButtonDisabled(state, localGetters, rootState),
......
...@@ -8,7 +8,10 @@ describe('Multi-file store file mutations', () => { ...@@ -8,7 +8,10 @@ describe('Multi-file store file mutations', () => {
beforeEach(() => { beforeEach(() => {
localState = state(); localState = state();
localFile = file(); localFile = {
...file(),
type: 'blob',
};
localState.entries[localFile.path] = localFile; localState.entries[localFile.path] = localFile;
}); });
...@@ -146,37 +149,18 @@ describe('Multi-file store file mutations', () => { ...@@ -146,37 +149,18 @@ describe('Multi-file store file mutations', () => {
describe('STAGE_CHANGE', () => { describe('STAGE_CHANGE', () => {
it('adds file into stagedFiles array', () => { it('adds file into stagedFiles array', () => {
const f = file(); mutations.STAGE_CHANGE(localState, localFile.path);
mutations.STAGE_CHANGE(localState, f);
expect(localState.stagedFiles.length).toBe(1); expect(localState.stagedFiles.length).toBe(1);
expect(localState.stagedFiles[0]).toEqual(f); expect(localState.stagedFiles[0]).toEqual(localFile);
});
it('updates changedFiles file to staged', () => {
const f = {
...file(),
type: 'blob',
staged: false,
};
localState.changedFiles.push(f);
mutations.STAGE_CHANGE(localState, f);
expect(localState.changedFiles[0].staged).toBeTruthy();
}); });
it('updates stagedFile if it is already staged', () => { it('updates stagedFile if it is already staged', () => {
const f = file(); mutations.STAGE_CHANGE(localState, localFile.path);
f.type = 'blob';
mutations.STAGE_CHANGE(localState, f); localFile.raw = 'testing 123';
f.raw = 'testing 123'; mutations.STAGE_CHANGE(localState, localFile.path);
mutations.STAGE_CHANGE(localState, f);
expect(localState.stagedFiles.length).toBe(1); expect(localState.stagedFiles.length).toBe(1);
expect(localState.stagedFiles[0].raw).toEqual('testing 123'); expect(localState.stagedFiles[0].raw).toEqual('testing 123');
...@@ -195,18 +179,14 @@ describe('Multi-file store file mutations', () => { ...@@ -195,18 +179,14 @@ describe('Multi-file store file mutations', () => {
localState.stagedFiles.push(f); localState.stagedFiles.push(f);
localState.changedFiles.push(f); localState.changedFiles.push(f);
localState.entries[f.path] = f;
}); });
it('removes from stagedFiles array', () => { it('removes from stagedFiles array', () => {
mutations.UNSTAGE_CHANGE(localState, f); mutations.UNSTAGE_CHANGE(localState, f.path);
expect(localState.stagedFiles.length).toBe(0); expect(localState.stagedFiles.length).toBe(0);
}); expect(localState.changedFiles.length).toBe(1);
it('updates changedFiles array file to unstaged', () => {
mutations.UNSTAGE_CHANGE(localState, f);
expect(localState.changedFiles[0].staged).toBeFalsy();
}); });
}); });
......
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