scroll-padlock
Version:
Locks elements scroll handling scrollbar gaps and iOS Safari with CSS variables
77 lines (60 loc) • 2.33 kB
JavaScript
import 'jsdom-global/register.js';
import chai from 'chai';
import {
SCROLLBAR_WIDTH,
SCROLLBAR_HEIGHT,
OUTER_WIDTH,
INNER_WIDTH,
SCROLL_WIDTH,
OUTER_HEIGHT,
INNER_HEIGHT,
SCROLL_HEIGHT
} from '../../src/constants.js';
import getLayout from '../../src/get-layout-dimensions.js';
const { expect } = chai;
describe('get-layout-dimensions', () => {
it('should be able to retrieve html elements dimensions', () => {
const mockedDiv = {
clientWidth: 10,
clientHeight: 20,
scrollWidth: 50,
scrollHeight: 60,
getBoundingClientRect: () => ({
width: 30,
height: 40
})
};
expect(getLayout(mockedDiv, mockedDiv)).to.deep.equals({
[]: mockedDiv.getBoundingClientRect().width,
[]: mockedDiv.getBoundingClientRect().height,
[]: mockedDiv.clientWidth,
[]: mockedDiv.clientHeight,
[]: mockedDiv.scrollWidth,
[]: mockedDiv.scrollHeight,
[]: mockedDiv.getBoundingClientRect().width - mockedDiv.clientWidth,
[]: mockedDiv.getBoundingClientRect().height - mockedDiv.clientHeight
});
});
it('should be able to detect page dimensions', () => {
const mockedWindow = {
innerWidth: 30,
innerHeight: 40
};
const mockedDocumentElement = {
clientWidth: 10,
clientHeight: 20,
scrollWidth: 50,
scrollHeight: 60
};
expect(getLayout(mockedDocumentElement, mockedWindow)).to.deep.equals({
[]: mockedWindow.innerWidth,
[]: mockedWindow.innerHeight,
[]: mockedDocumentElement.clientWidth,
[]: mockedDocumentElement.clientHeight,
[]: mockedDocumentElement.scrollWidth,
[]: mockedDocumentElement.scrollHeight,
[]: mockedWindow.innerWidth - mockedDocumentElement.clientWidth,
[]: mockedWindow.innerHeight - mockedDocumentElement.clientHeight
});
});
});