From 619e0828afdb56f8e925c2c67c91130384b6ec45 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 16 Jul 2018 16:07:04 +0300 Subject: [PATCH] fix(polyfill) scrollIntoViewIfNeeded in firefox --- client/modules/polyfill.js | 4 +++- client/modules/polyfill.spec.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 client/modules/polyfill.spec.js diff --git a/client/modules/polyfill.js b/client/modules/polyfill.js index fb0997a2..8d9c121e 100644 --- a/client/modules/polyfill.js +++ b/client/modules/polyfill.js @@ -5,5 +5,7 @@ require('domtokenlist-shim'); const scrollIntoViewIfNeeded = require('scroll-into-view-if-needed').default; -DOM.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded; +DOM.scrollIntoViewIfNeeded = (el) => scrollIntoViewIfNeeded(el, { + block: 'nearest' +}); diff --git a/client/modules/polyfill.spec.js b/client/modules/polyfill.spec.js new file mode 100644 index 00000000..607b0cb2 --- /dev/null +++ b/client/modules/polyfill.spec.js @@ -0,0 +1,32 @@ +'use stric'; + +const test = require('tape'); +const mockRequire = require('mock-require'); +const diff = require('sinon-called-with-diff'); +const sinon = diff(require('sinon')); + +test('cloudcmd: client: polyfill: scrollIntoViewIfNeaded', (t) => { + const {DOM} = global; + const scroll = sinon.stub(); + const el = {}; + + global.DOM = {}; + + mockRequire('scroll-into-view-if-needed', { + default: scroll + }); + + mockRequire.reRequire('./polyfill'); + + global.DOM.scrollIntoViewIfNeeded(el); + mockRequire.stop('scroll-into-view-if-neaded'); + global.DOM = DOM; + + const args = [ + el, { + block: 'nearest', + }]; + + t.ok(scroll.calledWith(...args), 'should call scrollIntoViewIfNeaded'); + t.end(); +});