Commit 02e7ac9b authored by Phil Hughes's avatar Phil Hughes

fixed up the component specs

parent b1fd4ac3
...@@ -123,7 +123,7 @@ export default { ...@@ -123,7 +123,7 @@ export default {
> >
<div <div
v-if="shouldHideEditor" v-if="shouldHideEditor"
v-html="activeFile.html" v-html="file.html"
> >
</div> </div>
<div <div
......
<script> <script>
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import timeAgoMixin from '~/vue_shared/mixins/timeago';
import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue'; import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue';
import fileIcon from '~/vue_shared/components/file_icon.vue'; import fileIcon from '~/vue_shared/components/file_icon.vue';
import router from '../ide_router';
import newDropdown from './new_dropdown/index.vue'; import newDropdown from './new_dropdown/index.vue';
import fileStatusIcon from './repo_file_status_icon.vue'; import fileStatusIcon from './repo_file_status_icon.vue';
import changedFileIcon from './changed_file_icon.vue'; import changedFileIcon from './changed_file_icon.vue';
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
fileIcon, fileIcon,
changedFileIcon, changedFileIcon,
}, },
mixins: [
timeAgoMixin,
],
props: { props: {
file: { file: {
type: Object, type: Object,
...@@ -63,7 +60,7 @@ ...@@ -63,7 +60,7 @@
if (this.isTree && this.$router.currentRoute.path === `/project${this.file.url}`) { if (this.isTree && this.$router.currentRoute.path === `/project${this.file.url}`) {
this.toggleTreeOpen(this.file.path); this.toggleTreeOpen(this.file.path);
} }
this.$router.push(`/project${this.file.url}`); router.push(`/project${this.file.url}`);
}, },
}, },
}; };
......
...@@ -33,42 +33,5 @@ describe('Multi-file editor right context bar', () => { ...@@ -33,42 +33,5 @@ describe('Multi-file editor right context bar', () => {
it('adds collapsed class', () => { it('adds collapsed class', () => {
expect(vm.$el.querySelector('.is-collapsed')).not.toBeNull(); expect(vm.$el.querySelector('.is-collapsed')).not.toBeNull();
}); });
it('shows correct icon', () => {
expect(vm.currentIcon).toBe('angle-double-left');
});
it('clicking sidebar collapses the bar', () => {
spyOn(vm, 'setPanelCollapsedStatus').and.returnValue(Promise.resolve());
vm.$el.querySelector('.multi-file-commit-panel-section').click();
expect(vm.setPanelCollapsedStatus).toHaveBeenCalledWith({
side: 'right',
collapsed: false,
});
});
});
it('clicking toggle collapse button collapses the bar', () => {
spyOn(vm, 'setPanelCollapsedStatus').and.returnValue(Promise.resolve());
vm.$el.querySelector('.multi-file-commit-panel-collapse-btn').click();
expect(vm.setPanelCollapsedStatus).toHaveBeenCalledWith({
side: 'right',
collapsed: true,
});
});
it('when expanded clicking the main sidebar is not collapsing the bar', () => {
spyOn(vm, 'setPanelCollapsedStatus').and.returnValue(Promise.resolve());
vm.$el.querySelector('.multi-file-commit-panel-section').click();
expect(vm.setPanelCollapsedStatus).not.toHaveBeenCalledWith({
side: 'right',
collapsed: false,
});
}); });
}); });
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/ide/stores';
import ideRepoTree from 'ee/ide/components/ide_repo_tree.vue'; import ideRepoTree from 'ee/ide/components/ide_repo_tree.vue';
import { file, resetStore } from '../helpers'; import createComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
describe('IdeRepoTree', () => { describe('IdeRepoTree', () => {
let vm; let vm;
let tree;
beforeEach(() => { beforeEach(() => {
const IdeRepoTree = Vue.extend(ideRepoTree); const IdeRepoTree = Vue.extend(ideRepoTree);
vm = new IdeRepoTree({ tree = {
store,
propsData: {
treeId: 'abcproject/mybranch',
},
});
vm.$store.state.currentBranch = 'master';
vm.$store.state.trees['abcproject/mybranch'] = {
tree: [file()], tree: [file()],
loading: false,
}; };
vm.$mount(); vm = createComponent(IdeRepoTree, {
tree,
});
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
resetStore(vm.$store);
}); });
it('renders a sidebar', () => { it('renders a sidebar', () => {
expect(vm.$el.classList.contains('sidebar-mini')).toBeFalsy(); expect(vm.$el.querySelector('.loading-file')).toBeNull();
expect(vm.$el.querySelector('.repo-file-options')).toBeFalsy(); expect(vm.$el.querySelector('.file')).not.toBeNull();
expect(vm.$el.querySelector('.loading-file')).toBeFalsy();
expect(vm.$el.querySelector('.file')).toBeTruthy();
}); });
it('renders 3 loading files if tree is loading', (done) => { it('renders 3 loading files if tree is loading', (done) => {
vm.$store.state.trees['123'] = { tree.loading = true;
tree: [],
loading: true,
};
vm.treeId = '123';
Vue.nextTick(() => { vm.$nextTick(() => {
expect(vm.$el.querySelectorAll('.multi-file-loading-container').length).toEqual(3); expect(vm.$el.querySelectorAll('.multi-file-loading-container').length).toEqual(3);
done(); done();
......
...@@ -11,8 +11,6 @@ describe('IdeSidebar', () => { ...@@ -11,8 +11,6 @@ describe('IdeSidebar', () => {
const Component = Vue.extend(ideSidebar); const Component = Vue.extend(ideSidebar);
vm = createComponentWithStore(Component, store).$mount(); vm = createComponentWithStore(Component, store).$mount();
vm.$store.state.leftPanelCollapsed = false;
}); });
afterEach(() => { afterEach(() => {
...@@ -25,19 +23,14 @@ describe('IdeSidebar', () => { ...@@ -25,19 +23,14 @@ describe('IdeSidebar', () => {
expect(vm.$el.querySelector('.multi-file-commit-panel-inner')).not.toBeNull(); expect(vm.$el.querySelector('.multi-file-commit-panel-inner')).not.toBeNull();
}); });
describe('collapsed', () => { it('renders loading icon component', (done) => {
beforeEach((done) => { vm.$store.state.loading = true;
vm.$store.state.leftPanelCollapsed = true;
Vue.nextTick(done);
});
it('adds collapsed class', () => { vm.$nextTick(() => {
expect(vm.$el.classList).toContain('is-collapsed'); expect(vm.$el.querySelector('.multi-file-loading-container')).not.toBeNull();
}); expect(vm.$el.querySelectorAll('.multi-file-loading-container').length).toBe(3);
it('shows correct icon', () => { done();
expect(vm.currentIcon).toBe('angle-double-right');
}); });
}); });
}); });
...@@ -2,7 +2,7 @@ import Vue from 'vue'; ...@@ -2,7 +2,7 @@ import Vue from 'vue';
import store from 'ee/ide/stores'; import store from 'ee/ide/stores';
import newDropdown from 'ee/ide/components/new_dropdown/index.vue'; import newDropdown from 'ee/ide/components/new_dropdown/index.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../../helpers'; import { file, resetStore } from '../../helpers';
describe('new dropdown component', () => { describe('new dropdown component', () => {
let vm; let vm;
...@@ -17,6 +17,9 @@ describe('new dropdown component', () => { ...@@ -17,6 +17,9 @@ describe('new dropdown component', () => {
vm.$store.state.currentProjectId = 'abcproject'; vm.$store.state.currentProjectId = 'abcproject';
vm.$store.state.path = ''; vm.$store.state.path = '';
vm.$store.state.trees['abcproject/mybranch'] = {
tree: [],
};
vm.$mount(); vm.$mount();
}); });
...@@ -74,4 +77,123 @@ describe('new dropdown component', () => { ...@@ -74,4 +77,123 @@ describe('new dropdown component', () => {
.catch(done.fail); .catch(done.fail);
}); });
}); });
// TODO: move all this to the action spec
describe('createTempEntry', () => {
['tree', 'blob'].forEach((type) => {
if (type === 'blob') {
it('creates new file', (done) => {
vm.createTempEntry({
branchId: 'mybranch',
name: 'testing',
type,
}).then(() => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('blob');
expect(baseTree[0].tempFile).toBeTruthy();
done();
})
.catch(done.fail);
});
it('does not create temp file when file already exists', (done) => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(file('testing', '1', type));
vm.createTempEntry({
branchId: 'mybranch',
name: 'testing',
type,
})
.then(() => {
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('blob');
expect(baseTree[0].tempFile).toBeFalsy();
done();
})
.catch(done.fail);
});
} else {
it('creates new tree', (done) => {
vm.createTempEntry({
branchId: 'mybranch',
name: 'testing',
type,
})
.then(() => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('tree');
expect(baseTree[0].tempFile).toBeTruthy();
done();
})
.catch(done.fail);
});
it('creates multiple trees when entryName has slashes', (done) => {
vm.createTempEntry({
branchId: 'mybranch',
name: 'app/test',
type,
})
.then(() => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('app');
done();
})
.catch(done.fail);
});
it('creates tree in existing tree', (done) => {
const f = file('app', '1', 'tree');
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(f);
vm.$store.state.entries[f.path] = f;
vm.entryName = 'app/test';
vm.createTempEntry({
branchId: 'mybranch',
name: 'app/test',
type,
}).then(() => {
expect(baseTree.length).toBe(1);
// console.log(baseTree[0].tree);
expect(baseTree[0].name).toBe('app');
expect(baseTree[0].tempFile).toBeFalsy();
expect(baseTree[0].tree[0].tempFile).toBeTruthy();
expect(baseTree[0].tree[0].name).toBe('test');
done();
}).catch(done.fail);
});
it('does not create new tree when already exists', (done) => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(file('app', '1', 'tree'));
vm.createTempEntry({
branchId: 'mybranch',
name: 'app',
type,
}).then(() => {
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('app');
expect(baseTree[0].tempFile).toBeFalsy();
expect(baseTree[0].tree.length).toBe(0);
done();
}).catch(done.fail);
});
}
});
});
}); });
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/ide/stores';
import service from 'ee/ide/services';
import modal from 'ee/ide/components/new_dropdown/modal.vue'; import modal from 'ee/ide/components/new_dropdown/modal.vue';
import router from 'ee/ide/ide_router'; import createComponent from 'spec/helpers/vue_mount_component_helper';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file, resetStore } from '../../helpers';
describe('new file modal component', () => { describe('new file modal component', () => {
const Component = Vue.extend(modal); const Component = Vue.extend(modal);
let vm; let vm;
let projectTree;
beforeEach(() => {
spyOn(service, 'getProjectData').and.returnValue(Promise.resolve({
data: {
id: '123',
},
}));
spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({
data: {
commit: {
id: '123branch',
},
},
}));
spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({
headers: {
'page-title': 'test',
},
json: () => Promise.resolve({
last_commit_path: 'last_commit_path',
parent_tree_url: 'parent_tree_url',
path: '/',
trees: [{ name: 'tree' }],
blobs: [{ name: 'blob' }],
submodules: [{ name: 'submodule' }],
}),
}));
spyOn(router, 'push');
});
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
resetStore(vm.$store);
}); });
['tree', 'blob'].forEach((type) => { ['tree', 'blob'].forEach((type) => {
describe(type, () => { describe(type, () => {
beforeEach(() => { beforeEach(() => {
store.state.projects.abcproject = { vm = createComponent(Component, {
web_url: '',
};
store.state.trees = [];
store.state.trees['abcproject/mybranch'] = {
tree: [],
};
projectTree = store.state.trees['abcproject/mybranch'];
store.state.currentProjectId = 'abcproject';
vm = createComponentWithStore(Component, store, {
type, type,
branchId: 'master', branchId: 'master',
path: '', path: '',
parent: projectTree,
}); });
vm.entryName = 'testing'; vm.entryName = 'testing';
vm.$mount();
}); });
it(`sets modal title as ${type}`, () => { it(`sets modal title as ${type}`, () => {
...@@ -93,122 +41,17 @@ describe('new file modal component', () => { ...@@ -93,122 +41,17 @@ describe('new file modal component', () => {
}); });
describe('createEntryInStore', () => { describe('createEntryInStore', () => {
it('calls createTempEntry', () => { it('$emits create', () => {
spyOn(vm, 'createTempEntry'); spyOn(vm, '$emit');
vm.createEntryInStore(); vm.createEntryInStore();
expect(vm.createTempEntry).toHaveBeenCalledWith({ expect(vm.$emit).toHaveBeenCalledWith('create', {
projectId: 'abcproject',
branchId: 'master', branchId: 'master',
parent: projectTree,
name: 'testing', name: 'testing',
type, type,
}); });
}); });
it('sets editMode to true', (done) => {
vm.createEntryInStore();
setTimeout(() => {
expect(vm.$store.state.editMode).toBeTruthy();
done();
});
});
it('opens newly created file', (done) => {
if (type === 'blob') {
vm.createEntryInStore();
setTimeout(() => {
expect(vm.$store.state.openFiles.length).toBe(1);
expect(vm.$store.state.openFiles[0].name).toBe(type === 'blob' ? 'testing' : '.gitkeep');
done();
});
} else {
done();
}
});
if (type === 'blob') {
it('creates new file', (done) => {
vm.createEntryInStore();
setTimeout(() => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('blob');
expect(baseTree[0].tempFile).toBeTruthy();
done();
});
});
it('does not create temp file when file already exists', (done) => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(file('testing', '1', type));
vm.createEntryInStore();
setTimeout(() => {
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('blob');
expect(baseTree[0].tempFile).toBeFalsy();
done();
});
});
} else {
it('creates new tree', () => {
vm.createEntryInStore();
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('testing');
expect(baseTree[0].type).toBe('tree');
expect(baseTree[0].tempFile).toBeTruthy();
});
it('creates multiple trees when entryName has slashes', () => {
vm.entryName = 'app/test';
vm.createEntryInStore();
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('app');
});
it('creates tree in existing tree', () => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(file('app', '1', 'tree'));
vm.entryName = 'app/test';
vm.createEntryInStore();
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('app');
expect(baseTree[0].tempFile).toBeFalsy();
expect(baseTree[0].tree[0].tempFile).toBeTruthy();
expect(baseTree[0].tree[0].name).toBe('test');
});
it('does not create new tree when already exists', () => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
baseTree.push(file('app', '1', 'tree'));
vm.entryName = 'app';
vm.createEntryInStore();
expect(baseTree.length).toBe(1);
expect(baseTree[0].name).toBe('app');
expect(baseTree[0].tempFile).toBeFalsy();
expect(baseTree[0].tree.length).toBe(0);
});
}
}); });
}); });
}); });
...@@ -216,12 +59,11 @@ describe('new file modal component', () => { ...@@ -216,12 +59,11 @@ describe('new file modal component', () => {
it('focuses field on mount', () => { it('focuses field on mount', () => {
document.body.innerHTML += '<div class="js-test"></div>'; document.body.innerHTML += '<div class="js-test"></div>';
vm = createComponentWithStore(Component, store, { vm = createComponent(Component, {
type: 'tree', type: 'tree',
projectId: 'abcproject',
branchId: 'master', branchId: 'master',
path: '', path: '',
}).$mount('.js-test'); }, '.js-test');
expect(document.activeElement).toBe(vm.$refs.fieldName); expect(document.activeElement).toBe(vm.$refs.fieldName);
......
import Vue from 'vue'; import Vue from 'vue';
import upload from 'ee/ide/components/new_dropdown/upload.vue'; import upload from 'ee/ide/components/new_dropdown/upload.vue';
import store from 'ee/ide/stores'; import createComponent from 'spec/helpers/vue_mount_component_helper';
import service from 'ee/ide/services';
import router from 'ee/ide/ide_router';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../../helpers';
describe('new dropdown upload', () => { describe('new dropdown upload', () => {
let vm; let vm;
let projectTree;
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectData').and.returnValue(Promise.resolve({
data: {
id: '123',
},
}));
spyOn(service, 'getBranchData').and.returnValue(Promise.resolve({
data: {
commit: {
id: '123branch',
},
},
}));
spyOn(service, 'getTreeData').and.returnValue(Promise.resolve({
headers: {
'page-title': 'test',
},
json: () => Promise.resolve({
last_commit_path: 'last_commit_path',
parent_tree_url: 'parent_tree_url',
path: '/',
trees: [{ name: 'tree' }],
blobs: [{ name: 'blob' }],
submodules: [{ name: 'submodule' }],
}),
}));
spyOn(router, 'push');
const Component = Vue.extend(upload); const Component = Vue.extend(upload);
store.state.projects.abcproject = { vm = createComponent(Component, {
web_url: '',
};
store.state.currentProjectId = 'abcproject';
store.state.trees = [];
store.state.trees['abcproject/mybranch'] = {
tree: [],
};
projectTree = store.state.trees['abcproject/mybranch'];
vm = createComponentWithStore(Component, store, {
branchId: 'master', branchId: 'master',
path: '', path: '',
parent: projectTree,
}); });
vm.entryName = 'testing'; vm.entryName = 'testing';
vm.$mount(); spyOn(vm, '$emit');
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
resetStore(vm.$store);
}); });
describe('readFile', () => { describe('readFile', () => {
...@@ -108,53 +60,27 @@ describe('new dropdown upload', () => { ...@@ -108,53 +60,27 @@ describe('new dropdown upload', () => {
name: 'file', name: 'file',
}; };
it('creates new file', (done) => { it('creates new file', () => {
vm.createFile(target, file, true); vm.createFile(target, file, true);
vm.$nextTick(() => { expect(vm.$emit).toHaveBeenCalledWith('create', {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; name: file.name,
expect(baseTree.length).toBe(1); branchId: 'master',
expect(baseTree[0].name).toBe(file.name); type: 'blob',
expect(baseTree[0].content).toBe(target.result); content: target.result,
base64: false,
done();
}); });
}); });
it('creates new file in path', (done) => { it('splits content on base64 if binary', () => {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree;
const tree = {
type: 'tree',
name: 'testing',
path: 'testing',
tree: [],
};
baseTree.push(tree);
vm.parent = tree;
vm.createFile(target, file, true);
vm.$nextTick(() => {
expect(baseTree.length).toBe(1);
expect(baseTree[0].tree[0].name).toBe(file.name);
expect(baseTree[0].tree[0].content).toBe(target.result);
expect(baseTree[0].tree[0].path).toBe(`testing/${file.name}`);
done();
});
});
it('splits content on base64 if binary', (done) => {
vm.createFile(binaryTarget, file, false); vm.createFile(binaryTarget, file, false);
vm.$nextTick(() => { expect(vm.$emit).toHaveBeenCalledWith('create', {
const baseTree = vm.$store.state.trees['abcproject/mybranch'].tree; name: file.name,
expect(baseTree.length).toBe(1); branchId: 'master',
expect(baseTree[0].name).toBe(file.name); type: 'blob',
expect(baseTree[0].content).toBe(binaryTarget.result.split('base64,')[1]); content: binaryTarget.result.split('base64,')[1],
expect(baseTree[0].base64).toBe(true); base64: true,
done();
}); });
}); });
}); });
......
...@@ -3,6 +3,7 @@ import store from 'ee/ide/stores'; ...@@ -3,6 +3,7 @@ import store from 'ee/ide/stores';
import repoEditor from 'ee/ide/components/repo_editor.vue'; import repoEditor from 'ee/ide/components/repo_editor.vue';
import monacoLoader from 'ee/ide/monaco_loader'; import monacoLoader from 'ee/ide/monaco_loader';
import Editor from 'ee/ide/lib/editor'; import Editor from 'ee/ide/lib/editor';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { file, resetStore } from '../helpers'; import { file, resetStore } from '../helpers';
describe('RepoEditor', () => { describe('RepoEditor', () => {
...@@ -12,14 +13,15 @@ describe('RepoEditor', () => { ...@@ -12,14 +13,15 @@ describe('RepoEditor', () => {
const f = file(); const f = file();
const RepoEditor = Vue.extend(repoEditor); const RepoEditor = Vue.extend(repoEditor);
vm = new RepoEditor({ vm = createComponentWithStore(RepoEditor, store, {
store, file: f,
}); });
f.active = true; f.active = true;
f.tempFile = true; f.tempFile = true;
f.html = 'testing';
vm.$store.state.openFiles.push(f); vm.$store.state.openFiles.push(f);
vm.$store.getters.activeFile.html = 'testing'; vm.$store.state.entries[f.path] = f;
vm.monaco = true; vm.monaco = true;
vm.$mount(); vm.$mount();
...@@ -47,9 +49,9 @@ describe('RepoEditor', () => { ...@@ -47,9 +49,9 @@ describe('RepoEditor', () => {
describe('when open file is binary and not raw', () => { describe('when open file is binary and not raw', () => {
beforeEach((done) => { beforeEach((done) => {
vm.$store.getters.activeFile.binary = true; vm.file.binary = true;
Vue.nextTick(done); vm.$nextTick(done);
}); });
it('does not render the IDE', () => { it('does not render the IDE', () => {
...@@ -69,7 +71,7 @@ describe('RepoEditor', () => { ...@@ -69,7 +71,7 @@ describe('RepoEditor', () => {
vm.setupEditor(); vm.setupEditor();
expect(vm.editor.createModel).toHaveBeenCalledWith(vm.$store.getters.activeFile); expect(vm.editor.createModel).toHaveBeenCalledWith(vm.file);
expect(vm.model).not.toBeNull(); expect(vm.model).not.toBeNull();
}); });
...@@ -98,7 +100,7 @@ describe('RepoEditor', () => { ...@@ -98,7 +100,7 @@ describe('RepoEditor', () => {
vm.model.setValue('testing 123'); vm.model.setValue('testing 123');
setTimeout(() => { setTimeout(() => {
expect(vm.$store.getters.activeFile.content).toBe('testing 123'); expect(vm.file.content).toBe('testing 123');
done(); done();
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/ide/stores';
import repoFileButtons from 'ee/ide/components/repo_file_buttons.vue'; import repoFileButtons from 'ee/ide/components/repo_file_buttons.vue';
import { file, resetStore } from '../helpers'; import createVueComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
describe('RepoFileButtons', () => { describe('RepoFileButtons', () => {
const activeFile = file(); const activeFile = file();
...@@ -13,18 +13,14 @@ describe('RepoFileButtons', () => { ...@@ -13,18 +13,14 @@ describe('RepoFileButtons', () => {
activeFile.rawPath = 'test'; activeFile.rawPath = 'test';
activeFile.blamePath = 'test'; activeFile.blamePath = 'test';
activeFile.commitsPath = 'test'; activeFile.commitsPath = 'test';
activeFile.active = true;
store.state.openFiles.push(activeFile);
return new RepoFileButtons({ return createVueComponent(RepoFileButtons, {
store, file: activeFile,
}).$mount(); });
} }
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
resetStore(vm.$store);
}); });
it('renders Raw, Blame, History, Permalink and Preview toggle', (done) => { it('renders Raw, Blame, History, Permalink and Preview toggle', (done) => {
......
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/ide/stores'; import store from 'ee/ide/stores';
import repoFile from 'ee/ide/components/repo_file.vue'; import repoFile from 'ee/ide/components/repo_file.vue';
import { file, resetStore } from '../helpers'; import router from 'ee/ide/ide_router';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
describe('RepoFile', () => { describe('RepoFile', () => {
const updated = 'updated';
let vm; let vm;
function createComponent(propsData) { function createComponent(propsData) {
const RepoFile = Vue.extend(repoFile); const RepoFile = Vue.extend(repoFile);
return new RepoFile({ vm = createComponentWithStore(RepoFile, store, propsData);
store,
propsData, vm.$mount();
}).$mount();
} }
afterEach(() => { afterEach(() => {
resetStore(vm.$store); vm.$destroy();
}); });
it('renders link, icon and name', () => { it('renders link, icon and name', () => {
const RepoFile = Vue.extend(repoFile); createComponent({
vm = new RepoFile({ file: file('t4'),
store, level: 0,
propsData: {
file: file('t4'),
},
}); });
spyOn(vm, 'timeFormated').and.returnValue(updated);
vm.$mount();
const name = vm.$el.querySelector('.ide-file-name'); const name = vm.$el.querySelector('.ide-file-name');
...@@ -37,59 +32,16 @@ describe('RepoFile', () => { ...@@ -37,59 +32,16 @@ describe('RepoFile', () => {
expect(name.textContent.trim()).toEqual(vm.file.name); expect(name.textContent.trim()).toEqual(vm.file.name);
}); });
it('does render if hasFiles is true and is loading tree', () => {
vm = createComponent({
file: file('t1'),
});
expect(vm.$el.querySelector('.fa-spin.fa-spinner')).toBeFalsy();
});
it('does not render commit message and datetime if mini', (done) => {
vm = createComponent({
file: file('t2'),
});
vm.$store.state.openFiles.push(vm.file);
vm.$nextTick(() => {
expect(vm.$el.querySelector('.commit-message')).toBeFalsy();
expect(vm.$el.querySelector('.commit-update')).toBeFalsy();
done();
});
});
it('fires clickFile when the link is clicked', () => { it('fires clickFile when the link is clicked', () => {
vm = createComponent({ spyOn(router, 'push');
createComponent({
file: file('t3'), file: file('t3'),
level: 0,
}); });
spyOn(vm, 'clickFile');
vm.$el.querySelector('.file-name').click(); vm.$el.querySelector('.file-name').click();
expect(vm.clickFile).toHaveBeenCalledWith(vm.file); expect(router.push).toHaveBeenCalledWith(`/project${vm.file.url}`);
});
describe('submodule', () => {
let f;
beforeEach(() => {
f = file('submodule name', '123456789');
f.type = 'submodule';
vm = createComponent({
file: f,
});
});
afterEach(() => {
vm.$destroy();
});
it('renders submodule short ID', () => {
expect(vm.$el.querySelector('.commit-sha').textContent.trim()).toBe('12345678');
});
}); });
describe('locked file', () => { describe('locked file', () => {
...@@ -104,15 +56,12 @@ describe('RepoFile', () => { ...@@ -104,15 +56,12 @@ describe('RepoFile', () => {
}, },
}; };
vm = createComponent({ createComponent({
file: f, file: f,
level: 0,
}); });
}); });
afterEach(() => {
vm.$destroy();
});
it('renders lock icon', () => { it('renders lock icon', () => {
expect(vm.$el.querySelector('.file-status-icon')).not.toBeNull(); expect(vm.$el.querySelector('.file-status-icon')).not.toBeNull();
}); });
......
...@@ -21,6 +21,8 @@ describe('RepoTab', () => { ...@@ -21,6 +21,8 @@ describe('RepoTab', () => {
}); });
afterEach(() => { afterEach(() => {
vm.$destroy();
resetStore(vm.$store); resetStore(vm.$store);
}); });
...@@ -57,7 +59,7 @@ describe('RepoTab', () => { ...@@ -57,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); expect(vm.closeFile).toHaveBeenCalledWith(vm.tab.path);
}); });
it('changes icon on hover', (done) => { it('changes icon on hover', (done) => {
...@@ -125,7 +127,8 @@ describe('RepoTab', () => { ...@@ -125,7 +127,8 @@ describe('RepoTab', () => {
}); });
vm.$store.state.openFiles.push(tab); vm.$store.state.openFiles.push(tab);
vm.$store.state.changedFiles.push(tab); vm.$store.state.changedFiles.push(tab);
vm.$store.dispatch('setFileActive', tab); vm.$store.state.entries[tab.path] = tab;
vm.$store.dispatch('setFileActive', tab.path);
vm.$el.querySelector('.multi-file-tab-close').click(); vm.$el.querySelector('.multi-file-tab-close').click();
...@@ -144,7 +147,8 @@ describe('RepoTab', () => { ...@@ -144,7 +147,8 @@ describe('RepoTab', () => {
tab, tab,
}); });
vm.$store.state.openFiles.push(tab); vm.$store.state.openFiles.push(tab);
vm.$store.dispatch('setFileActive', tab); vm.$store.state.entries[tab.path] = tab;
vm.$store.dispatch('setFileActive', tab.path);
vm.$el.querySelector('.multi-file-tab-close').click(); vm.$el.querySelector('.multi-file-tab-close').click();
......
import Vue from 'vue'; import Vue from 'vue';
import store from 'ee/ide/stores';
import repoTabs from 'ee/ide/components/repo_tabs.vue'; import repoTabs from 'ee/ide/components/repo_tabs.vue';
import { file, resetStore } from '../helpers'; import createComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';
describe('RepoTabs', () => { describe('RepoTabs', () => {
const openedFiles = [file('open1'), file('open2')]; const openedFiles = [file('open1'), file('open2')];
const RepoTabs = Vue.extend(repoTabs);
let vm; let vm;
function createComponent() {
const RepoTabs = Vue.extend(repoTabs);
return new RepoTabs({
store,
}).$mount();
}
afterEach(() => { afterEach(() => {
resetStore(vm.$store); vm.$destroy();
}); });
it('renders a list of tabs', (done) => { it('renders a list of tabs', (done) => {
vm = createComponent(); vm = createComponent(RepoTabs, {
files: openedFiles,
});
openedFiles[0].active = true; openedFiles[0].active = true;
vm.$store.state.openFiles = openedFiles;
vm.$nextTick(() => { vm.$nextTick(() => {
const tabs = [...vm.$el.querySelectorAll('.multi-file-tab')]; const tabs = [...vm.$el.querySelectorAll('.multi-file-tab')];
expect(tabs.length).toEqual(2); expect(tabs.length).toEqual(2);
expect(tabs[0].classList.contains('active')).toBeTruthy(); expect(tabs[0].classList.contains('active')).toEqual(true);
expect(tabs[1].classList.contains('active')).toBeFalsy(); expect(tabs[1].classList.contains('active')).toEqual(false);
done(); done();
}); });
......
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