summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/components/repo_file_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/repo/components/repo_file_spec.js')
-rw-r--r--spec/javascripts/repo/components/repo_file_spec.js57
1 files changed, 17 insertions, 40 deletions
diff --git a/spec/javascripts/repo/components/repo_file_spec.js b/spec/javascripts/repo/components/repo_file_spec.js
index 8403df9be64..18ae461128e 100644
--- a/spec/javascripts/repo/components/repo_file_spec.js
+++ b/spec/javascripts/repo/components/repo_file_spec.js
@@ -1,32 +1,28 @@
import Vue from 'vue';
+import store from '~/repo/stores';
import repoFile from '~/repo/components/repo_file.vue';
-import RepoStore from '~/repo/stores/repo_store';
-import eventHub from '~/repo/event_hub';
-import { file } from '../mock_data';
+import { file, resetStore } from '../helpers';
describe('RepoFile', () => {
const updated = 'updated';
- const otherFile = {
- id: 'test',
- html: '<p class="file-content">html</p>',
- pageTitle: 'otherpageTitle',
- };
function createComponent(propsData) {
const RepoFile = Vue.extend(repoFile);
return new RepoFile({
+ store,
propsData,
}).$mount();
}
- beforeEach(() => {
- RepoStore.openedFiles = [];
+ afterEach(() => {
+ resetStore(vm.$store);
});
it('renders link, icon, name and last commit details', () => {
const RepoFile = Vue.extend(repoFile);
const vm = new RepoFile({
+ store,
propsData: {
file: file(),
},
@@ -54,12 +50,6 @@ describe('RepoFile', () => {
expect(vm.$el.querySelector('.fa-spin.fa-spinner')).toBeFalsy();
});
- it('sets the document title correctly', () => {
- RepoStore.setActiveFiles(otherFile);
-
- expect(document.title.trim()).toEqual(otherFile.pageTitle);
- });
-
it('renders a spinner if the file is loading', () => {
const f = file();
f.loading = true;
@@ -71,27 +61,30 @@ describe('RepoFile', () => {
expect(vm.$el.querySelector('.fa-spin.fa-spinner').style.marginLeft).toEqual(`${vm.file.level * 16}px`);
});
- it('does not render commit message and datetime if mini', () => {
- RepoStore.openedFiles.push(file());
-
+ it('does not render commit message and datetime if mini', (done) => {
const vm = createComponent({
file: file(),
});
+ vm.$store.state.openFiles.push(vm.file);
- expect(vm.$el.querySelector('.commit-message')).toBeFalsy();
- expect(vm.$el.querySelector('.commit-update')).toBeFalsy();
+ vm.$nextTick(() => {
+ expect(vm.$el.querySelector('.commit-message')).toBeFalsy();
+ expect(vm.$el.querySelector('.commit-update')).toBeFalsy();
+
+ done();
+ });
});
- it('fires linkClicked when the link is clicked', () => {
+ it('fires clickedTreeRow when the link is clicked', () => {
const vm = createComponent({
file: file(),
});
- spyOn(vm, 'linkClicked');
+ spyOn(vm, 'clickedTreeRow');
vm.$el.click();
- expect(vm.linkClicked).toHaveBeenCalledWith(vm.file);
+ expect(vm.clickedTreeRow).toHaveBeenCalledWith(vm.file);
});
describe('submodule', () => {
@@ -119,20 +112,4 @@ describe('RepoFile', () => {
expect(vm.$el.querySelector('td').textContent.replace(/\s+/g, ' ')).toContain('submodule name @ 12345678');
});
});
-
- describe('methods', () => {
- describe('linkClicked', () => {
- it('$emits fileNameClicked with file obj', () => {
- spyOn(eventHub, '$emit');
-
- const vm = createComponent({
- file: file(),
- });
-
- vm.linkClicked(vm.file);
-
- expect(eventHub.$emit).toHaveBeenCalledWith('fileNameClicked', vm.file);
- });
- });
- });
});