Commit 8de14be2 authored by Phil Hughes's avatar Phil Hughes

fixed translate3d test

parent 48ec7025
...@@ -18,7 +18,7 @@ export const showSubLevelItems = (el) => { ...@@ -18,7 +18,7 @@ export const showSubLevelItems = (el) => {
const top = calculateTop(boundingRect, $subitems.offsetHeight); const top = calculateTop(boundingRect, $subitems.offsetHeight);
const isAbove = top < boundingRect.top; 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) { if (isAbove) {
$subitems.classList.add('is-above'); $subitems.classList.add('is-above');
......
...@@ -8,6 +8,7 @@ describe('Fly out sidebar navigation', () => { ...@@ -8,6 +8,7 @@ describe('Fly out sidebar navigation', () => {
let el; let el;
beforeEach(() => { beforeEach(() => {
el = document.createElement('div'); el = document.createElement('div');
el.style.position = 'relative';
document.body.appendChild(el); document.body.appendChild(el);
}); });
...@@ -89,7 +90,7 @@ describe('Fly out sidebar navigation', () => { ...@@ -89,7 +90,7 @@ describe('Fly out sidebar navigation', () => {
describe('showSubLevelItems', () => { describe('showSubLevelItems', () => {
beforeEach(() => { 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', () => { it('adds is-over class to el', () => {
...@@ -111,18 +112,17 @@ describe('Fly out sidebar navigation', () => { ...@@ -111,18 +112,17 @@ describe('Fly out sidebar navigation', () => {
}); });
it('sets transform of sub-items', () => { it('sets transform of sub-items', () => {
const subItems = el.querySelector('.sidebar-sub-level-items');
showSubLevelItems(el); showSubLevelItems(el);
expect( expect(
el.querySelector('.sidebar-sub-level-items').style.transform, subItems.style.transform,
).toBe(`translate3d(0px, ${el.offsetTop}px, 0px)`); ).toBe(`translate3d(0px, ${el.getBoundingClientRect().top}px, 0px)`);
}); });
it('sets is-above when element is above', () => { it('sets is-above when element is above', () => {
const subItems = el.querySelector('.sidebar-sub-level-items'); const subItems = el.querySelector('.sidebar-sub-level-items');
subItems.style.height = `${window.innerHeight + el.offsetHeight}px`; subItems.style.height = `${window.innerHeight + el.offsetHeight}px`;
subItems.style.position = 'absolute';
el.style.position = 'relative';
el.style.top = `${window.innerHeight - el.offsetHeight}px`; el.style.top = `${window.innerHeight - el.offsetHeight}px`;
spyOn(subItems.classList, 'add'); spyOn(subItems.classList, 'add');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment