import { LayoutUtil } from '@/core/utils/layout-util'; describe('getRowFlexStyle unit test', () => { test('row is flex layout', () => { const layoutOpts: any = { selfLayout: 'FLEX', dir: 'column', align: 'center', vAlign: 'center', } expect(LayoutUtil.getRowFlexStyle(layoutOpts)).toStrictEqual({ width: '100%', height: '100%', overflow: 'auto', display: 'flex', 'flex-direction': 'column', 'justify-content': 'center', 'align-items': 'center', }) }); test('row not flex layout', () => { const layoutOpts: any = { selfLayout: 'TABLE_24COL', } expect(LayoutUtil.getRowFlexStyle(layoutOpts)).toStrictEqual({}) }) }); describe('calcFlexStyleSize unit test', () => { test('size < 0', () => { const size = -12; expect(LayoutUtil.calcFlexStyleSize(size)).toBe(''); }); test('0 < size < 1', () => { const size = 0.5; expect(LayoutUtil.calcFlexStyleSize(size)).toBe('50%'); }); test('size > 1', () => { const size = 180; expect(LayoutUtil.calcFlexStyleSize(size)).toBe('180px'); }); }); describe('getColFlexStyle unit test', () => { test('col is flex layout', () => { const layoutOpts: any = { parentLayout: 'FLEX', grow: 1, width: 0.3, height: 250, } expect(LayoutUtil.getColFlexStyle(layoutOpts)).toStrictEqual({ width: '30%', height: '250px', 'flex-grow': 1, }) }); test('col not flex layout', () => { const layoutOpts: any = { parentLayout: 'TABLE_24COL', } expect(LayoutUtil.getColFlexStyle(layoutOpts)).toStrictEqual({}) }) }); describe('getGridOptions unit test', () => { test('parentLayout is TABLE_24COL', () => { const layoutOpts: any ={ parentLayout: 'TABLE_24COL', colLG: 8, colMD: 4, colSM: 2, colXS: 1, colLGOffset: 2, colMDOffset: 0, colSMOffset: 1, colXSOffset: 0, } expect(LayoutUtil.getGridOptions(layoutOpts)).toStrictEqual({ lg: { span: 8, offset: 2 }, md: { span: 4, offset: 0 }, sm: { span: 2, offset: 1 }, xs: { span: 1, offset: 0 }, }) }); test('parentLayout is TABLE_12COL', () => { const layoutOpts: any ={ parentLayout: 'TABLE_12COL', colLG: 8, colMD: 4, colSM: 2, colXS: 1, colLGOffset: 2, colMDOffset: 0, colSMOffset: 1, colXSOffset: 0, } expect(LayoutUtil.getGridOptions(layoutOpts)).toStrictEqual({ lg: { span: 16, offset: 4 }, md: { span: 8, offset: 0 }, sm: { span: 4, offset: 2 }, xs: { span: 2, offset: 0 }, }) }) }); describe('formatColSpan unit test', () => { test("span is null or undefined or ''", () => { const span1 = null; const span2 = undefined; const span3 = ''; const layoutMode = 'TABLE_24COL'; expect(LayoutUtil.formatColSpan(span1, layoutMode)).toBe(24); expect(LayoutUtil.formatColSpan(span2, layoutMode)).toBe(24); expect(LayoutUtil.formatColSpan(span3, layoutMode)).toBe(24); }); test('span < 0 or span > max', () => { const span1 = -12; const span2 = 25; const span3 = 13; const layoutMode1 = 'TABLE_24COL'; const layoutMode2 = 'TABLE_12COL'; expect(LayoutUtil.formatColSpan(span1, layoutMode1)).toBe(24); expect(LayoutUtil.formatColSpan(span2, layoutMode1)).toBe(24); expect(LayoutUtil.formatColSpan(span3, layoutMode2)).toBe(12); }); test('0 < span < max', () => { const span1 = 12; const span2 = 6; const layoutMode1 = 'TABLE_24COL'; const layoutMode2 = 'TABLE_12COL'; expect(LayoutUtil.formatColSpan(span1, layoutMode1)).toBe(12); expect(LayoutUtil.formatColSpan(span2, layoutMode2)).toBe(6); }); }); describe('getBoxSize unit test', () => { test('getBoxSize', () => { const mode = 'WIDTH'; const style = 'PX'; const value = 200; expect(LayoutUtil.getBoxSize(mode, style, value)).toStrictEqual({ width: '200px' }); }) }) describe('getItemSpacingStyle unit test', () => { test('getItemSpacingStyle', () => { const spacingType = 'OUTERSMALL'; const direction = 'top' expect(LayoutUtil.getItemSpacingStyle(spacingType, direction)).toStrictEqual({ 'margin-top': '8px' }) }) }) describe('getLayoutItemInstance unit test', () => { test('getLayoutItemInstance', () => { const layoutModelItem = { itemType: 'RAWITEM', renderMode: 'HEADING1', } const layoutInstance = LayoutUtil.getLayoutItemInstance(layoutModelItem, {}, {}); expect(layoutInstance.renderMode).toBe('HEADING1'); }) })