@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
79 lines (78 loc) • 2.51 kB
JavaScript
;
require("@testing-library/jest-dom");
describe('useScroll', function () {
describe('Rounding target scroll position', function () {
beforeEach(function () {
jest.resetModules(); // important! clears cached modules
});
test('should round target position upwards when target is bigger than current position', function () {
jest.doMock('@enact/core/platform', function () {
return {
__esModule: true,
platform: {
chrome: 132
}
};
});
var _require = require('../useScroll'),
roundTarget = _require.roundTarget;
var currentPosition = {
scrollPos: {
left: 100,
top: 100
}
};
var _roundTarget = roundTarget(currentPosition, 120.5, 120.4),
roundedTargetX = _roundTarget.roundedTargetX,
roundedTargetY = _roundTarget.roundedTargetY;
expect(roundedTargetX).toEqual(121);
expect(roundedTargetY).toEqual(121);
});
test('should round target position downwards when target is bigger than current position', function () {
jest.doMock('@enact/core/platform', function () {
return {
__esModule: true,
platform: {
chrome: 132
}
};
});
var _require2 = require('../useScroll'),
roundTarget = _require2.roundTarget;
var currentPosition = {
scrollPos: {
left: 100,
top: 100
}
};
var _roundTarget2 = roundTarget(currentPosition, 90.4, 80.8),
roundedTargetX = _roundTarget2.roundedTargetX,
roundedTargetY = _roundTarget2.roundedTargetY;
expect(roundedTargetX).toEqual(90);
expect(roundedTargetY).toEqual(80);
});
test('should not round target position when chrome <= 120', function () {
jest.doMock('@enact/core/platform', function () {
return {
__esModule: true,
platform: {
chrome: 119
}
};
});
var _require3 = require('../useScroll'),
roundTarget = _require3.roundTarget;
var currentPosition = {
scrollPos: {
left: 100,
top: 100
}
};
var _roundTarget3 = roundTarget(currentPosition, 90.4, 80.8),
roundedTargetX = _roundTarget3.roundedTargetX,
roundedTargetY = _roundTarget3.roundedTargetY;
expect(roundedTargetX).toEqual(90.4);
expect(roundedTargetY).toEqual(80.8);
});
});
});