diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-06 17:43:10 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-06 17:43:10 +0300 |
commit | b4d167a8f78509e241639e560ee1fed545d2dbc1 (patch) | |
tree | ad31164a4fe19d7c3dbc7d9e9f1d3ee6e3e65637 /spec/javascripts/repo/components/repo_file_spec.js | |
parent | c5377b97968ba9edefe7766dac77cc9fbbaa4e2c (diff) | |
parent | d4ceec9d47a7da5fa17cb6e161ac491e13fcb8bd (diff) |
Merge branch 'master' into feature/sm/3691-expose-per-project-pipeline-idfeature/sm/3691-expose-per-project-pipeline-id
Diffstat (limited to 'spec/javascripts/repo/components/repo_file_spec.js')
-rw-r--r-- | spec/javascripts/repo/components/repo_file_spec.js | 143 |
1 files changed, 61 insertions, 82 deletions
diff --git a/spec/javascripts/repo/components/repo_file_spec.js b/spec/javascripts/repo/components/repo_file_spec.js index 518a2d25ecf..c45f8a18d1f 100644 --- a/spec/javascripts/repo/components/repo_file_spec.js +++ b/spec/javascripts/repo/components/repo_file_spec.js @@ -1,136 +1,115 @@ import Vue from 'vue'; +import store from '~/repo/stores'; import repoFile from '~/repo/components/repo_file.vue'; +import { file, resetStore } from '../helpers'; describe('RepoFile', () => { const updated = 'updated'; - const file = { - icon: 'icon', - url: 'url', - name: 'name', - lastCommitMessage: 'message', - lastCommitUpdate: Date.now(), - level: 10, - }; - const activeFile = { - url: 'url', - }; + let vm; function createComponent(propsData) { const RepoFile = Vue.extend(repoFile); return new RepoFile({ + store, propsData, }).$mount(); } - beforeEach(() => { - spyOn(repoFile.mixins[0].methods, 'timeFormated').and.returnValue(updated); + afterEach(() => { + resetStore(vm.$store); }); it('renders link, icon, name and last commit details', () => { - const vm = createComponent({ - file, - activeFile, + const RepoFile = Vue.extend(repoFile); + vm = new RepoFile({ + store, + propsData: { + file: file(), + }, }); + spyOn(vm, 'timeFormated').and.returnValue(updated); + vm.$mount(); + 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, + vm = createComponent({ + file: file(), }); - expect(vm.$el.innerHTML).toBeTruthy(); expect(vm.$el.querySelector('.fa-spin.fa-spinner')).toBeFalsy(); }); it('renders a spinner if the file is loading', () => { - file.loading = true; - const vm = createComponent({ - file, - activeFile, - loading: { - tree: true, - }, - hasFiles: true, + const f = file(); + f.loading = true; + vm = createComponent({ + file: f, }); - expect(vm.$el.innerHTML).toBeTruthy(); - expect(vm.$el.querySelector('.fa-spin.fa-spinner').style.marginLeft).toEqual(`${file.level * 10}px`); + 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 if loading tree', () => { - const vm = createComponent({ - file, - activeFile, - loading: { - tree: true, - }, + it('does not render commit message and datetime if mini', (done) => { + vm = createComponent({ + file: file(), }); + vm.$store.state.openFiles.push(vm.file); - expect(vm.$el.innerHTML).toBeFalsy(); - }); + vm.$nextTick(() => { + expect(vm.$el.querySelector('.commit-message')).toBeFalsy(); + expect(vm.$el.querySelector('.commit-update')).toBeFalsy(); - it('does not render commit message and datetime if mini', () => { - const vm = createComponent({ - file, - activeFile, - isMini: true, + done(); }); - - 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', () => { - const vm = createComponent({ - file, - activeFile: {}, + it('fires clickedTreeRow when the link is clicked', () => { + vm = createComponent({ + file: file(), }); - expect(vm.$el.classList.contains('active')).toBeFalsy(); - }); + spyOn(vm, 'clickedTreeRow'); - it('fires linkClicked when the link is clicked', () => { - const vm = createComponent({ - file, - activeFile, - }); + vm.$el.click(); - spyOn(vm, 'linkClicked'); + expect(vm.clickedTreeRow).toHaveBeenCalledWith(vm.file); + }); - vm.$el.querySelector('.repo-file-name').click(); + describe('submodule', () => { + let f; - expect(vm.linkClicked).toHaveBeenCalledWith(file); - }); + beforeEach(() => { + f = file('submodule name', '123456789'); + f.type = 'submodule'; - describe('methods', () => { - describe('linkClicked', () => { - const vm = jasmine.createSpyObj('vm', ['$emit']); + vm = createComponent({ + file: f, + }); + }); - it('$emits linkclicked with file obj', () => { - const theFile = {}; + afterEach(() => { + vm.$destroy(); + }); - repoFile.methods.linkClicked.call(vm, theFile); + it('renders submodule short ID', () => { + expect(vm.$el.querySelector('.commit-sha').textContent.trim()).toBe('12345678'); + }); - expect(vm.$emit).toHaveBeenCalledWith('linkclicked', theFile); - }); + it('renders ID next to submodule name', () => { + expect(vm.$el.querySelector('td').textContent.replace(/\s+/g, ' ')).toContain('submodule name @ 12345678'); }); }); }); |