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.js125
1 files changed, 56 insertions, 69 deletions
diff --git a/spec/javascripts/repo/components/repo_file_spec.js b/spec/javascripts/repo/components/repo_file_spec.js
index 620b604f404..107f6797f8a 100644
--- a/spec/javascripts/repo/components/repo_file_spec.js
+++ b/spec/javascripts/repo/components/repo_file_spec.js
@@ -1,21 +1,11 @@
import Vue from 'vue';
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';
describe('RepoFile', () => {
const updated = 'updated';
- const file = {
- icon: 'icon',
- url: 'url',
- name: 'name',
- lastCommitMessage: 'message',
- lastCommitUpdate: Date.now(),
- level: 10,
- };
- const activeFile = {
- pageTitle: 'pageTitle',
- url: 'url',
- };
const otherFile = {
html: '<p class="file-content">html</p>',
pageTitle: 'otherpageTitle',
@@ -29,12 +19,15 @@ describe('RepoFile', () => {
}).$mount();
}
+ beforeEach(() => {
+ RepoStore.openedFiles = [];
+ });
+
it('renders link, icon, name and last commit details', () => {
const RepoFile = Vue.extend(repoFile);
const vm = new RepoFile({
propsData: {
- file,
- activeFile,
+ file: file(),
},
});
spyOn(vm, 'timeFormated').and.returnValue(updated);
@@ -43,28 +36,20 @@ describe('RepoFile', () => {
const name = vm.$el.querySelector('.repo-file-name');
const fileIcon = vm.$el.querySelector('.file-icon');
- expect(vm.$el.classList.contains('active')).toBeTruthy();
- expect(vm.$el.querySelector(`.${file.icon}`).style.marginLeft).toEqual('100px');
- expect(name.title).toEqual(file.url);
- expect(name.href).toMatch(`/${file.url}`);
- expect(name.textContent.trim()).toEqual(file.name);
- expect(vm.$el.querySelector('.commit-message').textContent.trim()).toBe(file.lastCommitMessage);
+ expect(vm.$el.querySelector(`.${vm.file.icon}`).style.marginLeft).toEqual('0px');
+ expect(name.href).toMatch(`/${vm.file.url}`);
+ expect(name.textContent.trim()).toEqual(vm.file.name);
+ expect(vm.$el.querySelector('.commit-message').textContent.trim()).toBe(vm.file.lastCommit.message);
expect(vm.$el.querySelector('.commit-update').textContent.trim()).toBe(updated);
- expect(fileIcon.classList.contains(file.icon)).toBeTruthy();
- expect(fileIcon.style.marginLeft).toEqual(`${file.level * 10}px`);
+ expect(fileIcon.classList.contains(vm.file.icon)).toBeTruthy();
+ expect(fileIcon.style.marginLeft).toEqual(`${vm.file.level * 10}px`);
});
it('does render if hasFiles is true and is loading tree', () => {
const vm = createComponent({
- file,
- activeFile,
- loading: {
- tree: true,
- },
- hasFiles: true,
+ file: file(),
});
- expect(vm.$el.innerHTML).toBeTruthy();
expect(vm.$el.querySelector('.fa-spin.fa-spinner')).toBeFalsy();
});
@@ -75,75 +60,77 @@ describe('RepoFile', () => {
});
it('renders a spinner if the file is loading', () => {
- file.loading = true;
+ const f = file();
+ f.loading = true;
const vm = createComponent({
- file,
- activeFile,
- loading: {
- tree: true,
- },
- hasFiles: true,
+ file: f,
});
- expect(vm.$el.innerHTML).toBeTruthy();
- expect(vm.$el.querySelector('.fa-spin.fa-spinner').style.marginLeft).toEqual(`${file.level * 10}px`);
- });
-
- it('does not render if loading tree', () => {
- const vm = createComponent({
- file,
- activeFile,
- loading: {
- tree: true,
- },
- });
-
- expect(vm.$el.innerHTML).toBeFalsy();
+ expect(vm.$el.querySelector('.fa-spin.fa-spinner')).not.toBeNull();
+ 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());
+
const vm = createComponent({
- file,
- activeFile,
- isMini: true,
+ file: file(),
});
expect(vm.$el.querySelector('.commit-message')).toBeFalsy();
expect(vm.$el.querySelector('.commit-update')).toBeFalsy();
});
- it('does not set active class if file is active file', () => {
+ it('fires linkClicked when the link is clicked', () => {
const vm = createComponent({
- file,
- activeFile: {},
+ file: file(),
});
- expect(vm.$el.classList.contains('active')).toBeFalsy();
+ spyOn(vm, 'linkClicked');
+
+ vm.$el.click();
+
+ expect(vm.linkClicked).toHaveBeenCalledWith(vm.file);
});
- it('fires linkClicked when the link is clicked', () => {
- const vm = createComponent({
- file,
- activeFile,
+ describe('submodule', () => {
+ let f;
+ let vm;
+
+ beforeEach(() => {
+ f = file('submodule name', '123456789');
+ f.type = 'submodule';
+
+ vm = createComponent({
+ file: f,
+ });
});
- spyOn(vm, 'linkClicked');
+ afterEach(() => {
+ vm.$destroy();
+ });
- vm.$el.querySelector('.repo-file-name').click();
+ it('renders submodule short ID', () => {
+ expect(vm.$el.querySelector('.commit-sha').textContent.trim()).toBe('12345678');
+ });
- expect(vm.linkClicked).toHaveBeenCalledWith(file);
+ it('renders ID next to submodule name', () => {
+ expect(vm.$el.querySelector('td').textContent.replace(/\s+/g, ' ')).toContain('submodule name @ 12345678');
+ });
});
describe('methods', () => {
describe('linkClicked', () => {
- const vm = jasmine.createSpyObj('vm', ['$emit']);
+ it('$emits fileNameClicked with file obj', () => {
+ spyOn(eventHub, '$emit');
- it('$emits linkclicked with file obj', () => {
- const theFile = {};
+ const vm = createComponent({
+ file: file(),
+ });
- repoFile.methods.linkClicked.call(vm, theFile);
+ vm.linkClicked(vm.file);
- expect(vm.$emit).toHaveBeenCalledWith('linkclicked', theFile);
+ expect(eventHub.$emit).toHaveBeenCalledWith('fileNameClicked', vm.file);
});
});
});