Commit bead083c authored by Phil Hughes's avatar Phil Hughes

updated specs

parent bfdeee1d
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
this.updateViewer(viewer); this.updateViewer(viewer);
if (this.activeFile.pending) { if (this.activeFile.pending) {
this.removePendingTab(this.activeFile).then(() => { return this.removePendingTab(this.activeFile).then(() => {
router.push(`/project${this.activeFile.url}`); router.push(`/project${this.activeFile.url}`);
}); });
} }
......
...@@ -64,7 +64,7 @@ export default class Model { ...@@ -64,7 +64,7 @@ export default class Model {
onChange(cb) { onChange(cb) {
this.events.set( this.events.set(
this.key, this.path,
this.disposable.add(this.model.onDidChangeContent(e => cb(this, e))), this.disposable.add(this.model.onDidChangeContent(e => cb(this, e))),
); );
} }
......
...@@ -44,7 +44,7 @@ export default class DirtyDiffController { ...@@ -44,7 +44,7 @@ export default class DirtyDiffController {
computeDiff(model) { computeDiff(model) {
this.dirtyDiffWorker.postMessage({ this.dirtyDiffWorker.postMessage({
key: model.path, path: model.path,
originalContent: model.getOriginalModel().getValue(), originalContent: model.getOriginalModel().getValue(),
newContent: model.getModel().getValue(), newContent: model.getModel().getValue(),
}); });
...@@ -56,7 +56,7 @@ export default class DirtyDiffController { ...@@ -56,7 +56,7 @@ export default class DirtyDiffController {
decorate({ data }) { decorate({ data }) {
const decorations = data.changes.map(change => getDecorator(change)); const decorations = data.changes.map(change => getDecorator(change));
const model = this.modelManager.getModel(data.key); const model = this.modelManager.getModel(data.path);
this.decorationsController.addDecorations(model, 'dirtyDiff', decorations); this.decorationsController.addDecorations(model, 'dirtyDiff', decorations);
} }
......
...@@ -4,7 +4,7 @@ self.addEventListener('message', e => { ...@@ -4,7 +4,7 @@ self.addEventListener('message', e => {
const data = e.data; const data = e.data;
self.postMessage({ self.postMessage({
key: data.key, path: data.path,
changes: computeDiff(data.originalContent, data.newContent), changes: computeDiff(data.originalContent, data.newContent),
}); });
}); });
...@@ -21,7 +21,7 @@ export const discardAllChanges = ({ state, commit, dispatch }) => { ...@@ -21,7 +21,7 @@ export const discardAllChanges = ({ state, commit, dispatch }) => {
}; };
export const closeAllFiles = ({ state, dispatch }) => { export const closeAllFiles = ({ state, dispatch }) => {
state.openFiles.forEach(file => dispatch('closeFile', file.path)); state.openFiles.forEach(file => dispatch('closeFile', file));
}; };
export const setPanelCollapsedStatus = ({ commit }, { side, collapsed }) => { export const setPanelCollapsedStatus = ({ commit }, { side, collapsed }) => {
......
import Vue from 'vue'; import Vue from 'vue';
import listItem from '~/ide/components/commit_sidebar/list_item.vue'; import listItem from '~/ide/components/commit_sidebar/list_item.vue';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import store from '~/ide/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file } from '../../helpers'; import { file } from '../../helpers';
describe('Multi-file editor commit sidebar list item', () => { describe('Multi-file editor commit sidebar list item', () => {
...@@ -13,9 +14,9 @@ describe('Multi-file editor commit sidebar list item', () => { ...@@ -13,9 +14,9 @@ describe('Multi-file editor commit sidebar list item', () => {
f = file('test-file'); f = file('test-file');
vm = mountComponent(Component, { vm = createComponentWithStore(Component, store, {
file: f, file: f,
}); }).$mount();
}); });
afterEach(() => { afterEach(() => {
...@@ -36,20 +37,24 @@ describe('Multi-file editor commit sidebar list item', () => { ...@@ -36,20 +37,24 @@ describe('Multi-file editor commit sidebar list item', () => {
expect(vm.discardFileChanges).toHaveBeenCalled(); expect(vm.discardFileChanges).toHaveBeenCalled();
}); });
it('opens a closed file in the editor when clicking the file path', () => { it('opens a closed file in the editor when clicking the file path', done => {
spyOn(vm, 'openFileInEditor').and.callThrough(); spyOn(vm, 'openFileInEditor').and.callThrough();
spyOn(vm, 'updateViewer'); spyOn(vm, 'updateViewer').and.callThrough();
spyOn(router, 'push'); spyOn(router, 'push');
vm.$el.querySelector('.multi-file-commit-list-path').click(); vm.$el.querySelector('.multi-file-commit-list-path').click();
expect(vm.openFileInEditor).toHaveBeenCalled(); setTimeout(() => {
expect(router.push).toHaveBeenCalled(); expect(vm.openFileInEditor).toHaveBeenCalled();
expect(router.push).toHaveBeenCalled();
done();
});
}); });
it('calls updateViewer with diff when clicking file', () => { it('calls updateViewer with diff when clicking file', () => {
spyOn(vm, 'openFileInEditor').and.callThrough(); spyOn(vm, 'openFileInEditor').and.callThrough();
spyOn(vm, 'updateViewer'); spyOn(vm, 'updateViewer').and.callThrough();
spyOn(router, 'push'); spyOn(router, 'push');
vm.$el.querySelector('.multi-file-commit-list-path').click(); vm.$el.querySelector('.multi-file-commit-list-path').click();
......
...@@ -59,7 +59,7 @@ describe('RepoTab', () => { ...@@ -59,7 +59,7 @@ describe('RepoTab', () => {
vm.$el.querySelector('.multi-file-tab-close').click(); vm.$el.querySelector('.multi-file-tab-close').click();
expect(vm.closeFile).toHaveBeenCalledWith(vm.tab.path); expect(vm.closeFile).toHaveBeenCalledWith(vm.tab);
}); });
it('changes icon on hover', done => { it('changes icon on hover', done => {
......
...@@ -17,6 +17,7 @@ describe('RepoTabs', () => { ...@@ -17,6 +17,7 @@ describe('RepoTabs', () => {
files: openedFiles, files: openedFiles,
viewer: 'editor', viewer: 'editor',
hasChanges: false, hasChanges: false,
activeFile: file('activeFile'),
}); });
openedFiles[0].active = true; openedFiles[0].active = true;
...@@ -56,6 +57,7 @@ describe('RepoTabs', () => { ...@@ -56,6 +57,7 @@ describe('RepoTabs', () => {
files: [], files: [],
viewer: 'editor', viewer: 'editor',
hasChanges: false, hasChanges: false,
activeFile: file('activeFile'),
}, },
'#test-app', '#test-app',
); );
......
...@@ -27,9 +27,10 @@ describe('Multi-file editor library model manager', () => { ...@@ -27,9 +27,10 @@ describe('Multi-file editor library model manager', () => {
}); });
it('caches model by file path', () => { it('caches model by file path', () => {
instance.addModel(file('path-name')); const f = file('path-name');
instance.addModel(f);
expect(instance.models.keys().next().value).toBe('path-name'); expect(instance.models.keys().next().value).toBe(f.key);
}); });
it('adds model into disposable', () => { it('adds model into disposable', () => {
...@@ -56,7 +57,7 @@ describe('Multi-file editor library model manager', () => { ...@@ -56,7 +57,7 @@ describe('Multi-file editor library model manager', () => {
instance.addModel(f); instance.addModel(f);
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
`editor.update.model.dispose.${f.path}`, `editor.update.model.dispose.${f.key}`,
jasmine.anything(), jasmine.anything(),
); );
}); });
...@@ -68,9 +69,11 @@ describe('Multi-file editor library model manager', () => { ...@@ -68,9 +69,11 @@ describe('Multi-file editor library model manager', () => {
}); });
it('returns true when model exists', () => { it('returns true when model exists', () => {
instance.addModel(file('path-name')); const f = file('path-name');
instance.addModel(f);
expect(instance.hasCachedModel('path-name')).toBeTruthy(); expect(instance.hasCachedModel(f.key)).toBeTruthy();
}); });
}); });
...@@ -103,7 +106,7 @@ describe('Multi-file editor library model manager', () => { ...@@ -103,7 +106,7 @@ describe('Multi-file editor library model manager', () => {
instance.removeCachedModel(f); instance.removeCachedModel(f);
expect(eventHub.$off).toHaveBeenCalledWith( expect(eventHub.$off).toHaveBeenCalledWith(
`editor.update.model.dispose.${f.path}`, `editor.update.model.dispose.${f.key}`,
jasmine.anything(), jasmine.anything(),
); );
}); });
......
...@@ -28,14 +28,14 @@ describe('Multi-file editor library model', () => { ...@@ -28,14 +28,14 @@ describe('Multi-file editor library model', () => {
it('adds eventHub listener', () => { it('adds eventHub listener', () => {
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
`editor.update.model.dispose.${model.file.path}`, `editor.update.model.dispose.${model.file.key}`,
jasmine.anything(), jasmine.anything(),
); );
}); });
describe('path', () => { describe('path', () => {
it('returns file path', () => { it('returns file path', () => {
expect(model.path).toBe('path'); expect(model.path).toBe(model.file.key);
}); });
}); });
...@@ -64,7 +64,7 @@ describe('Multi-file editor library model', () => { ...@@ -64,7 +64,7 @@ describe('Multi-file editor library model', () => {
model.onChange(() => {}); model.onChange(() => {});
expect(model.events.size).toBe(1); expect(model.events.size).toBe(1);
expect(model.events.keys().next().value).toBe('path'); expect(model.events.keys().next().value).toBe(model.file.key);
}); });
it('calls callback on change', done => { it('calls callback on change', done => {
...@@ -105,7 +105,7 @@ describe('Multi-file editor library model', () => { ...@@ -105,7 +105,7 @@ describe('Multi-file editor library model', () => {
model.dispose(); model.dispose();
expect(eventHub.$off).toHaveBeenCalledWith( expect(eventHub.$off).toHaveBeenCalledWith(
`editor.update.model.dispose.${model.file.path}`, `editor.update.model.dispose.${model.file.key}`,
jasmine.anything(), jasmine.anything(),
); );
}); });
......
...@@ -131,7 +131,7 @@ describe('Multi-file editor library dirty diff controller', () => { ...@@ -131,7 +131,7 @@ describe('Multi-file editor library dirty diff controller', () => {
it('adds decorations into decorations controller', () => { it('adds decorations into decorations controller', () => {
spyOn(controller.decorationsController, 'addDecorations'); spyOn(controller.decorationsController, 'addDecorations');
controller.decorate({ data: { changes: [], path: 'path' } }); controller.decorate({ data: { changes: [], path: model.path } });
expect( expect(
controller.decorationsController.addDecorations, controller.decorationsController.addDecorations,
...@@ -145,7 +145,7 @@ describe('Multi-file editor library dirty diff controller', () => { ...@@ -145,7 +145,7 @@ describe('Multi-file editor library dirty diff controller', () => {
); );
controller.decorate({ controller.decorate({
data: { changes: computeDiff('123', '1234'), path: 'path' }, data: { changes: computeDiff('123', '1234'), path: model.path },
}); });
expect(spy).toHaveBeenCalledWith( expect(spy).toHaveBeenCalledWith(
......
...@@ -29,7 +29,7 @@ describe('Multi-file store file actions', () => { ...@@ -29,7 +29,7 @@ describe('Multi-file store file actions', () => {
it('closes open files', done => { it('closes open files', done => {
store store
.dispatch('closeFile', localFile.path) .dispatch('closeFile', localFile)
.then(() => { .then(() => {
expect(localFile.opened).toBeFalsy(); expect(localFile.opened).toBeFalsy();
expect(localFile.active).toBeFalsy(); expect(localFile.active).toBeFalsy();
...@@ -44,7 +44,7 @@ describe('Multi-file store file actions', () => { ...@@ -44,7 +44,7 @@ describe('Multi-file store file actions', () => {
store.state.changedFiles.push(localFile); store.state.changedFiles.push(localFile);
store store
.dispatch('closeFile', localFile.path) .dispatch('closeFile', localFile)
.then(Vue.nextTick) .then(Vue.nextTick)
.then(() => { .then(() => {
expect(store.state.openFiles.length).toBe(0); expect(store.state.openFiles.length).toBe(0);
...@@ -65,7 +65,7 @@ describe('Multi-file store file actions', () => { ...@@ -65,7 +65,7 @@ describe('Multi-file store file actions', () => {
store.state.entries[f.path] = f; store.state.entries[f.path] = f;
store store
.dispatch('closeFile', localFile.path) .dispatch('closeFile', localFile)
.then(Vue.nextTick) .then(Vue.nextTick)
.then(() => { .then(() => {
expect(router.push).toHaveBeenCalledWith(`/project${f.url}`); expect(router.push).toHaveBeenCalledWith(`/project${f.url}`);
......
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