summaryrefslogtreecommitdiff
path: root/spec/javascripts/merge_request_tabs_spec.js
diff options
context:
space:
mode:
authorSam Bigelow <sbigelow@gitlab.com>2018-11-27 18:05:16 +0000
committerPhil Hughes <me@iamphill.com>2018-11-27 18:05:16 +0000
commit153dddefed226e3716a41f177d8722a5a6fd48b8 (patch)
treeab2eec7193de8345e2ff9d0acfa485fb72216c86 /spec/javascripts/merge_request_tabs_spec.js
parenta99f342b4231659d39b9a145acc3652f3de3bce8 (diff)
downloadgitlab-ce-153dddefed226e3716a41f177d8722a5a6fd48b8.tar.gz
Resolve "Jump to top in merge request"
Diffstat (limited to 'spec/javascripts/merge_request_tabs_spec.js')
-rw-r--r--spec/javascripts/merge_request_tabs_spec.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/javascripts/merge_request_tabs_spec.js b/spec/javascripts/merge_request_tabs_spec.js
index 7714197c821..c8df05eccf5 100644
--- a/spec/javascripts/merge_request_tabs_spec.js
+++ b/spec/javascripts/merge_request_tabs_spec.js
@@ -239,4 +239,38 @@ describe('MergeRequestTabs', function() {
expect($('.content-wrapper')).toContainElement('.container-limited');
});
});
+
+ describe('tabShown', function() {
+ const mainContent = document.createElement('div');
+ const tabContent = document.createElement('div');
+
+ beforeEach(function() {
+ spyOn(mainContent, 'getBoundingClientRect').and.returnValue({ top: 10 });
+ spyOn(tabContent, 'getBoundingClientRect').and.returnValue({ top: 100 });
+ spyOn(document, 'querySelector').and.callFake(function(selector) {
+ return selector === '.content-wrapper' ? mainContent : tabContent;
+ });
+ this.class.currentAction = 'commits';
+ });
+
+ it('calls window scrollTo with options if document has scrollBehavior', function() {
+ document.documentElement.style.scrollBehavior = '';
+
+ spyOn(window, 'scrollTo');
+
+ this.class.tabShown('commits', 'foobar');
+
+ expect(window.scrollTo.calls.first().args[0]).toEqual({ top: 39, behavior: 'smooth' });
+ });
+
+ it('calls window scrollTo with two args if document does not have scrollBehavior', function() {
+ spyOnProperty(document.documentElement, 'style', 'get').and.returnValue({});
+
+ spyOn(window, 'scrollTo');
+
+ this.class.tabShown('commits', 'foobar');
+
+ expect(window.scrollTo.calls.first().args).toEqual([0, 39]);
+ });
+ });
});