From fbc68b7bf283afb58691c8a6dab219fd7d894173 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Tue, 30 Jul 2019 16:21:29 +0100 Subject: [PATCH] Add tests for viewports < 769px wide Elements should not stick unless the viewport is 768px wide or larger. --- .../stick-to-window-when-scrolling.test.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/javascripts/stick-to-window-when-scrolling.test.js b/tests/javascripts/stick-to-window-when-scrolling.test.js index b7d80b5b9..ce2a8ffb0 100644 --- a/tests/javascripts/stick-to-window-when-scrolling.test.js +++ b/tests/javascripts/stick-to-window-when-scrolling.test.js @@ -157,6 +157,23 @@ describe("Stick to top/bottom of window when scrolling", () => { }); + test("if the window is 768px or less wide and the top of the viewport is below top of element on load, the element should not be marked as sticky", () => { + + screenMock.window.resizeTo({ + height: windowHeight, + width: 768 + }); + + // scroll past top of form + screenMock.scrollTo(inputForm.offsetTop + 10); + + window.GOVUK.stickAtTopWhenScrolling.init(); + + expect(inputForm.classList.contains('content-fixed')).toBe(false); + expect(inputForm.classList.contains('content-fixed-onload')).toBe(false); // check the class for onload isn't applied + + }); + describe("if top of viewport is below top of element but still in the scroll area on load", () => { beforeEach(() => { @@ -745,6 +762,25 @@ describe("Stick to top/bottom of window when scrolling", () => { }); + test("if the window is 768px or less wide and the bottom of the viewport is above bottom of element on load, the element should not be marked as sticky", () => { + + const pageFooterBottom = getScreenItemBottomPosition(pageFooter); + + screenMock.window.resizeTo({ + height: windowHeight, + width: 768 + }); + + // scroll past top of form + screenMock.scrollTo(pageFooterBottom - 10); + + window.GOVUK.stickAtTopWhenScrolling.init(); + + expect(pageFooter.classList.contains('content-fixed')).toBe(false); + expect(pageFooter.classList.contains('content-fixed-onload')).toBe(false); // check the class for onload isn't applied + + }); + describe("if bottom of viewport is above bottom of element on load", () => { beforeEach(() => {