const helpers = require('./support/helpers'); const PADDING_BETWEEN_STICKYS = 40; const PADDING_BEFORE_STOPPING_POINT = 10; function getScreenItemBottomPosition (screenItem) { return screenItem.offsetTop + screenItem.offsetHeight; }; function getCaretPosition (caretPosition, textarea) { return { top: textarea.offsetTop + caretPosition.top, bottom: textarea.offsetTop + caretPosition.top + caretPosition.height, height: caretPosition.height }; }; function getStickyGroupPosition (screenMock, opts) { const edgePosition = screenMock.window[opts.edge]; const height = opts.stickyEls .map(el => el.offsetHeight) .reduce((accumulator, height) => accumulator + height); if (opts.edge === 'top') { return { top: screenMock.window.top, bottom: edgePosition + height, height: height }; } else { return { top: edgePosition - height, bottom: screenMock.window.bottom, height: height } } }; class CaretCoordinates { constructor (data) { this.top = 5.5; this.left = 2; this.height = 19; } moveToLine (lineNumber) { const lineHeight = 30; const verticalPadding = 5.5; this.top = ((lineNumber - 1) * lineHeight) + verticalPadding; } } beforeAll(() => { require('../../app/assets/javascripts/stick-to-window-when-scrolling.js'); }); afterAll(() => { require('./support/teardown.js'); }); describe("Stick to top/bottom of window when scrolling", () => { let screenMock; describe("If intending to stick to the top", () => { let inputForm; let formFooter; let footer; let windowHeight; let getFurthestTopPoint; beforeEach(() => { document.body.innerHTML = `