import { isFixedBottom, getMarginBottom } from 'utils/fixed' import { RunnerPartialObject } from 'utils/variableHeight/types' const makeItem = ( y: number = 20, height = 20, type = 'section' ): RunnerPartialObject => { return { id: '2', type, attributes: { name: 'Rectangle 1', height, width: 100, x: 0, y, adjustedY: y, deviceVisibility: { mobile: true, tablet: true, desktop: true }, }, children: [], variableHeight: false, newHeight: height, newY: y, pushGraph: { nodeIds: [], edges: [] }, height, width: 100, } } const component = makeItem(0, 800, 'component') describe('isFixedBottom', () => { test('Returns false if component is far from bottom', () => { const item = makeItem() const result = isFixedBottom(item, component) expect(result).toBeFalsy() }) test('Returns true if the component is along bottom', () => { const item = makeItem(780) const result = isFixedBottom(item, component) expect(result).toBeTruthy() }) test('Returns true if component is close to bottom', () => { const item = makeItem(760) const result = isFixedBottom(item, component) expect(result).toBeTruthy() }) }) describe('getMarginBottom', () => { test('Returns current value if given item is not along bottom of screen', () => { const item = makeItem() const currentValue = 5 const result = getMarginBottom(currentValue, item, component) expect(result).toEqual(currentValue) }) test('Returns current value if given item is along bottom of screen but shorter than current value', () => { const item = makeItem(780) const currentValue = 80 const result = getMarginBottom(currentValue, item, component) expect(result).toEqual(currentValue) }) test('Returns current value if given item is along bottom of screen and top of screen', () => { const item = makeItem(20, 780) const currentValue = 80 const result = getMarginBottom(currentValue, item, component) expect(result).toEqual(currentValue) }) test('Returns item height if given item is along bottom of screen and taller than current value', () => { const item = makeItem(780) const currentValue = 5 const result = getMarginBottom(currentValue, item, component) expect(result).toEqual(item.attributes.height) }) })