diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-10-02 15:02:52 +0200 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2017-10-04 17:27:56 +0200 |
commit | 1429e5b57df2107746d8550abebb423107b5399a (patch) | |
tree | 9c8a425616e2d7a03d0f56c1c5c301aac2ad5fa3 | |
parent | 45b8266bcd97c1132a5012ca4df578df4999c6ac (diff) | |
download | gitlab-ce-1429e5b57df2107746d8550abebb423107b5399a.tar.gz |
Added Test for Back Button Behaviour
-rw-r--r-- | spec/javascripts/repo/components/repo_sidebar_spec.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js index db9911c7a2c..9959d23a07d 100644 --- a/spec/javascripts/repo/components/repo_sidebar_spec.js +++ b/spec/javascripts/repo/components/repo_sidebar_spec.js @@ -121,5 +121,37 @@ describe('RepoSidebar', () => { expect(RepoService.url).toEqual(prevUrl); }); }); + + describe('back button', () => { + const file1 = { + id: 1, + url: 'file1', + }; + const file2 = { + id: 2, + url: 'file2', + }; + RepoStore.files = [file1, file2]; + RepoStore.openedFiles = [file1, file2]; + RepoStore.isRoot = true; + + const vm = createComponent(); + vm.fileClicked(file1); + + it('render previous file when using back button', () => { + spyOn(Helper, 'getContent').and.callThrough(); + vm.fileClicked(file2); + expect(Helper.getContent).toHaveBeenCalledWith(file2); + + history.pushState({ + key: Math.random(), + }, '', file1.url); + const popEvent = document.createEvent('Event'); + popEvent.initEvent('popstate', true, true); + window.dispatchEvent(popEvent); + + expect(Helper.getContent).toHaveBeenCalledWith(file1); + }); + }); }); }); |