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

spec fixes

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