Commit 99193d82 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Added scroll_helper tests

parent 929c66d6
...@@ -54,7 +54,7 @@ import RefSelectDropdown from './ref_select_dropdown'; ...@@ -54,7 +54,7 @@ import RefSelectDropdown from './ref_select_dropdown';
import GfmAutoComplete from './gfm_auto_complete'; import GfmAutoComplete from './gfm_auto_complete';
import ShortcutsBlob from './shortcuts_blob'; import ShortcutsBlob from './shortcuts_blob';
import initSettingsPanels from './settings_panels'; import initSettingsPanels from './settings_panels';
import { setScrollWidth } from './helpers/scroll_helper'; import ScrollHelper from './helpers/scroll_helper';
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -77,7 +77,7 @@ import { setScrollWidth } from './helpers/scroll_helper'; ...@@ -77,7 +77,7 @@ import { setScrollWidth } from './helpers/scroll_helper';
return false; return false;
} }
setScrollWidth(); ScrollHelper.setScrollWidth();
path = page.split(':'); path = page.split(':');
shortcut_handler = null; shortcut_handler = null;
......
function getScrollWidth() { import $ from 'jquery';
const $rulerContainer = $('<div>').css({
visibility: 'hidden',
width: 100,
overflow: 'scroll',
});
const $ruler = $('<div>').css({ const ScrollHelper = {
width: '100%', getScrollWidth() {
}); const $rulerContainer = $('<div>').css({
visibility: 'hidden',
width: 100,
overflow: 'scroll',
});
$ruler.appendTo($rulerContainer); const $ruler = $('<div>').css({
$rulerContainer.appendTo('body'); width: '100%',
});
const scrollWidth = $ruler.outerWidth(); $ruler.appendTo($rulerContainer);
$rulerContainer.appendTo('body');
$rulerContainer.remove(); const scrollWidth = $ruler.outerWidth();
return 100 - scrollWidth; $rulerContainer.remove();
}
function setScrollWidth() { return 100 - scrollWidth;
$('body').attr('data-scroll-width', getScrollWidth()); },
}
export { setScrollWidth() {
getScrollWidth, $('body').attr('data-scroll-width', ScrollHelper.getScrollWidth());
setScrollWidth, },
}; };
export default ScrollHelper;
import $ from 'jquery';
import ScrollHelper from '~/helpers/scroll_helper';
describe('ScrollHelper', () => {
describe('setScrollWidth', () => {
it('calls getScrollWidth and sets data-scroll-width', () => {
const width = 10;
spyOn($.fn, 'attr');
spyOn(ScrollHelper, 'getScrollWidth').and.returnValue(width);
ScrollHelper.setScrollWidth();
expect(ScrollHelper.getScrollWidth).toHaveBeenCalled();
expect($.fn.attr).toHaveBeenCalledWith('data-scroll-width', width);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment