1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/app-desktop/gui/ResizableLayout/utils/persist.test.ts
2020-11-13 17:09:28 +00:00

78 lines
1.7 KiB
TypeScript

import { loadLayout, saveLayout } from './persist';
import { LayoutItem, LayoutItemDirection } from './types';
import validateLayout from './validateLayout';
describe('persist', () => {
test('should save layout and filter out non-user properties', () => {
const layout: LayoutItem = validateLayout({
key: 'root',
width: 100,
height: 100,
direction: LayoutItemDirection.Row,
children: [
{
key: 'col1',
width: 50,
},
{
key: 'col2',
direction: LayoutItemDirection.Column,
children: [
{ key: 'item1', height: 20 },
{ key: 'item2' },
],
},
{
key: 'col3',
},
],
});
const toSave = saveLayout(layout);
expect(toSave.key).toBe('root');
expect(toSave.width).toBeUndefined();
expect(toSave.height).toBeUndefined();
expect(toSave.direction).toBeUndefined();
expect(toSave.children.length).toBe(3);
expect(toSave.children[1].key).toBe('col2');
expect(toSave.children[1].direction).toBeUndefined();
});
test('should load a layout', () => {
const layout: any = {
key: 'root',
children: [
{
key: 'col1',
width: 50,
},
{
key: 'col2',
children: [
{ key: 'item1', height: 20 },
{ key: 'item2' },
],
},
{
key: 'col3',
},
],
};
const loaded = loadLayout(layout, null, { width: 100, height: 200 });
expect(loaded.key).toBe('root');
expect(loaded.width).toBe(100);
expect(loaded.height).toBe(200);
expect(loaded.direction).toBe(LayoutItemDirection.Row);
expect(loaded.children.length).toBe(3);
expect(loaded.children[1].key).toBe('col2');
expect(loaded.children[1].direction).toBe(LayoutItemDirection.Column);
});
});