fixed translate3d test

This commit is contained in:
Phil Hughes 2017-08-01 12:41:55 +01:00
parent 48ec70250c
commit 8de14be21e
No known key found for this signature in database
GPG Key ID: DB8CE4B3A3EE91AB
2 changed files with 6 additions and 6 deletions

View File

@ -18,7 +18,7 @@ export const showSubLevelItems = (el) => {
const top = calculateTop(boundingRect, $subitems.offsetHeight);
const isAbove = top < boundingRect.top;
$subitems.style.transform = `translate3d(0, ${top}px, 0)`;
$subitems.style.transform = `translate3d(0, ${Math.floor(top)}px, 0)`;
if (isAbove) {
$subitems.classList.add('is-above');

View File

@ -8,6 +8,7 @@ describe('Fly out sidebar navigation', () => {
let el;
beforeEach(() => {
el = document.createElement('div');
el.style.position = 'relative';
document.body.appendChild(el);
});
@ -89,7 +90,7 @@ describe('Fly out sidebar navigation', () => {
describe('showSubLevelItems', () => {
beforeEach(() => {
el.innerHTML = '<div class="sidebar-sub-level-items"></div>';
el.innerHTML = '<div class="sidebar-sub-level-items" style="position: absolute;"></div>';
});
it('adds is-over class to el', () => {
@ -111,18 +112,17 @@ describe('Fly out sidebar navigation', () => {
});
it('sets transform of sub-items', () => {
const subItems = el.querySelector('.sidebar-sub-level-items');
showSubLevelItems(el);
expect(
el.querySelector('.sidebar-sub-level-items').style.transform,
).toBe(`translate3d(0px, ${el.offsetTop}px, 0px)`);
subItems.style.transform,
).toBe(`translate3d(0px, ${el.getBoundingClientRect().top}px, 0px)`);
});
it('sets is-above when element is above', () => {
const subItems = el.querySelector('.sidebar-sub-level-items');
subItems.style.height = `${window.innerHeight + el.offsetHeight}px`;
subItems.style.position = 'absolute';
el.style.position = 'relative';
el.style.top = `${window.innerHeight - el.offsetHeight}px`;
spyOn(subItems.classList, 'add');