1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/app-desktop/gui/ResizableLayout/utils/useLayoutItemSizes.test.ts

90 lines
2.2 KiB
TypeScript
Raw Normal View History

import useLayoutItemSizes, { itemSize } from './useLayoutItemSizes';
import { LayoutItem, LayoutItemDirection } from './types';
import { renderHook } from '@testing-library/react-hooks';
import validateLayout from './validateLayout';
describe('useLayoutItemSizes', () => {
test('should validate the layout', () => {
const layout: LayoutItem = validateLayout({
key: 'root',
width: 200,
height: 100,
direction: LayoutItemDirection.Row,
children: [
{ key: 'col1' },
{ key: 'col2' },
],
});
expect(layout.isRoot).toBe(true);
});
test('should give item sizes', () => {
const layout: LayoutItem = validateLayout({
key: 'root',
width: 200,
height: 100,
direction: LayoutItemDirection.Row,
children: [
{
key: 'col1',
width: 50,
},
{
key: 'col2',
},
],
});
const { result } = renderHook(() => useLayoutItemSizes(layout));
const sizes = result.current;
expect(sizes.root).toEqual({ width: 200, height: 100 });
expect(sizes.col1).toEqual({ width: 50, height: 100 });
expect(sizes.col2).toEqual({ width: 150, height: 100 });
});
test('should leave room for the resizer controls', () => {
const layout: LayoutItem = validateLayout({
key: 'root',
width: 200,
height: 100,
direction: LayoutItemDirection.Row,
children: [
{
key: 'col1',
resizableRight: true,
direction: LayoutItemDirection.Column,
children: [
{ key: 'row1', resizableBottom: true },
{ key: 'row2' },
],
},
{
key: 'col2',
},
],
});
const { result } = renderHook(() => useLayoutItemSizes(layout));
const sizes = result.current;
expect(sizes).toEqual({
root: { width: 200, height: 100 },
col1: { width: 100, height: 100 },
col2: { width: 100, height: 100 },
row1: { width: 100, height: 50 },
row2: { width: 100, height: 50 },
});
expect(itemSize(layout.children[0], layout, sizes, true)).toEqual({ width: 100, height: 100 });
const parent = layout.children[0];
expect(itemSize(parent.children[0], parent, sizes, false)).toEqual({ width: 95, height: 45 });
expect(itemSize(parent.children[1], parent, sizes, false)).toEqual({ width: 95, height: 50 });
});
});