debian-mirror-gitlab/spec/javascripts/repo/components/repo_file_spec.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import store from '~/ide/stores';
import repoFile from '~/ide/components/repo_file.vue';
import { file, resetStore } from '../helpers';
2017-09-10 17:25:29 +05:30
describe('RepoFile', () => {
const updated = 'updated';
2018-03-17 18:26:18 +05:30
let vm;
2017-09-10 17:25:29 +05:30
function createComponent(propsData) {
const RepoFile = Vue.extend(repoFile);
return new RepoFile({
2018-03-17 18:26:18 +05:30
store,
2017-09-10 17:25:29 +05:30
propsData,
}).$mount();
}
2018-03-17 18:26:18 +05:30
afterEach(() => {
resetStore(vm.$store);
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
it('renders link, icon and name', () => {
const RepoFile = Vue.extend(repoFile);
vm = new RepoFile({
store,
propsData: {
file: file('t4'),
},
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
spyOn(vm, 'timeFormated').and.returnValue(updated);
vm.$mount();
2017-09-10 17:25:29 +05:30
const name = vm.$el.querySelector('.repo-file-name');
2018-03-17 18:26:18 +05:30
expect(name.href).toMatch('');
expect(name.textContent.trim()).toEqual(vm.file.name);
2017-09-10 17:25:29 +05:30
});
it('does render if hasFiles is true and is loading tree', () => {
2018-03-17 18:26:18 +05:30
vm = createComponent({
file: file('t1'),
2017-09-10 17:25:29 +05:30
});
expect(vm.$el.querySelector('.fa-spin.fa-spinner')).toBeFalsy();
});
2018-03-17 18:26:18 +05:30
it('does not render commit message and datetime if mini', (done) => {
vm = createComponent({
file: file('t2'),
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
vm.$store.state.openFiles.push(vm.file);
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
vm.$nextTick(() => {
expect(vm.$el.querySelector('.commit-message')).toBeFalsy();
expect(vm.$el.querySelector('.commit-update')).toBeFalsy();
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
done();
2017-09-10 17:25:29 +05:30
});
});
2018-03-17 18:26:18 +05:30
it('fires clickFile when the link is clicked', () => {
vm = createComponent({
file: file('t3'),
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
spyOn(vm, 'clickFile');
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
vm.$el.click();
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.clickFile).toHaveBeenCalledWith(vm.file);
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
describe('submodule', () => {
let f;
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
beforeEach(() => {
f = file('submodule name', '123456789');
f.type = 'submodule';
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
vm = createComponent({
file: f,
});
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
afterEach(() => {
vm.$destroy();
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
it('renders submodule short ID', () => {
expect(vm.$el.querySelector('.commit-sha').textContent.trim()).toBe('12345678');
});
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
it('renders ID next to submodule name', () => {
expect(vm.$el.querySelector('td').textContent.replace(/\s+/g, ' ')).toContain('submodule name @ 12345678');
2017-09-10 17:25:29 +05:30
});
});
});