diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2017-08-10 21:50:59 +0300 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2017-08-14 19:03:36 +0300 |
commit | f1e1113bf4d107c0ecf3f989f6110b00a83cef2d (patch) | |
tree | add40de38bdd1b810e1dc4e4cdb0fdb6f2a1781b /spec | |
parent | 06c330954e030e30e9e8284110907c53b206e447 (diff) |
Split out linkClicked and add tests
Fix
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37143174
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/repo/components/repo_sidebar_spec.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js index 0d216c9c026..e8bc8a62240 100644 --- a/spec/javascripts/repo/components/repo_sidebar_spec.js +++ b/spec/javascripts/repo/components/repo_sidebar_spec.js @@ -1,4 +1,6 @@ import Vue from 'vue'; +import Helper from '~/repo/helpers/repo_helper'; +import RepoService from '~/repo/services/repo_service'; import RepoStore from '~/repo/stores/repo_store'; import repoSidebar from '~/repo/components/repo_sidebar.vue'; @@ -58,4 +60,50 @@ describe('RepoSidebar', () => { expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy(); }); + + describe('methods', () => { + describe('fileClicked', () => { + it('should fetch data for new file', () => { + spyOn(Helper, 'getContent'); + const file1 = { + id: 0, + }; + RepoStore.files = [file1]; + RepoStore.isRoot = true; + const vm = createComponent(); + + vm.fileClicked(file1); + + expect(Helper.getContent).toHaveBeenCalledWith(file1, jasmine.any(Function)); + }); + + it('should hide files in directory if already open', () => { + spyOn(RepoStore, 'removeChildFilesOfTree').and.callThrough(); + const file1 = { + id: 0, + type: 'tree', + url: '', + opened: true, + }; + RepoStore.files = [file1]; + RepoStore.isRoot = true; + const vm = createComponent(); + + vm.fileClicked(file1); + + expect(RepoStore.removeChildFilesOfTree).toHaveBeenCalledWith(file1); + }); + }); + + describe('goToPreviousDirectoryClicked', () => { + it('should hide files in directory if already open', () => { + const prevUrl = 'foo/bar'; + const vm = createComponent(); + + vm.goToPreviousDirectoryClicked(prevUrl); + + expect(RepoService.url).toEqual(prevUrl); + }); + }); + }); }); |