'use strict'; import LayoutManager from '../../src/manager/layout-manager'; import { Layout, LayoutType, LayoutDensityType, DerivedColumnOptions, DerivedRowOptions, RowSelection, ValueTextAlignmentType, ValueTextPositionType, ColumnType } from '../../src/public-api/interfaces'; import { LayoutInputConfig, LayoutState } from '../../src/globals/helpers/helpers'; let layoutConf: Layout = { type: LayoutType.Row, density: LayoutDensityType.Compact, autoheight: true }, cardLayout: Layout = { type: LayoutType.Card, numcards: 4, cardtemplate: function(params){return"
"} }, selectionConfig: RowSelection = { enable: true, enableselectioncheckbox: true }, rowConf: DerivedRowOptions = { pxRowHeight: 40, pxHeaderRowHeight: 50 }, containerDim = { height: 500, width: 1000 }, columnsConfig: Array = [{ pxWidth: 100, pxMinWidth: 80, pxMaxWidth: 150, minContent: 'test', maxContent: 'hello Test how are you?' }, { pxWidth: 100.5, pxMinWidth: 80, pxMaxWidth: 200, minContent: '1234', maxContent: '12344567788' }, { pxWidth: 2500.5, pxMinWidth: 280, pxMaxWidth: 400, minContent: '12/22/2019', maxContent: '12/30/2019' }], rowLayoutInpConfig: LayoutInputConfig = { columnsConfig, rowOptionsConfig: rowConf, layoutConfig: layoutConf, selectionConfig, domContainerDim: containerDim, stores: {}, defaultColumnOptions: {}, groupLevel: 0 }, cardlayoutInputConfig: LayoutInputConfig = { columnsConfig, rowOptionsConfig: rowConf, layoutConfig: cardLayout, domContainerDim: containerDim, stores: {}, defaultColumnOptions: {}, groupLevel: 0 }; describe('LayoutManager unit tests with different input variations for row layout', () => { let layoutManager: LayoutManager, layoutState: LayoutState; beforeAll(() => { layoutManager = new LayoutManager(rowLayoutInpConfig); layoutManager.getStores().vizRecordDomain.set({start: 0, end: 2}); layoutManager.calculatelayout(); }); it('header dimention check', (done) => { layoutState = layoutManager.getLayoutState(); layoutState.rowLayout && expect(layoutState.rowLayout.headerDimState.height).toBe(66); done(); }); it('cell dimention check', (done) => { layoutState = layoutManager.getLayoutState(); if (layoutState.rowLayout) { // space allocated for selection expect(layoutState.rowLayout.headerDimState.cell[0].left).toBe(0); expect(layoutState.rowLayout.headerDimState.cell[0].width).toBe(48); expect(layoutState.rowLayout.headerDimState.cell[1].left).toBe(48); expect(layoutState.rowLayout.headerDimState.cell[1].width).toBe(100); expect(layoutState.rowLayout.headerDimState.cell[2].left).toBe(148); expect(layoutState.rowLayout.headerDimState.cell[2].width).toBe(100.5); } done(); }); it('TC_FG_126 TC_FG_267 TC_FG_268 row dimention check, selectionConfig, rowoptions must be set properly', (done) => { layoutState = layoutManager.getLayoutState(); if (layoutState.rowLayout) { // as no data present expect(layoutState.rowLayout.headerDimState.height).toBe(66); expect(layoutState.rowLayout.rowDimState[0].top).toBe(0); expect(layoutState.rowLayout.rowDimState[0].height).toBe(56); } done(); }); it('TC_FG_086 Verify that a user is able to set the layout type of a grid', (done) => { expect(layoutManager.getCurrentLayoutType()).toBe(LayoutType.Row); done(); }); // TO-DO: yet to write card support test cases when card is included it('TC_FG_088 Verify that a user is able to set the density of a grid', (done) => { expect(layoutManager.getDensity()!).toBe('compact'); done(); }); it('TC_FG_098 , autoheight should be set if provided', (done) => { layoutManager.getStores().autoHeight.subscribe((val: any) =>{ expect(layoutManager.getLayout().autoheight).toBe(true); }); done(); }); }); describe('LayoutManager unit tests with different input variations for card layout', () => { let layoutManager: LayoutManager, layoutState; beforeAll(() => { layoutManager = new LayoutManager(cardlayoutInputConfig); layoutManager.calculatelayout(); }); it(`TC_FG_100 Verify that, for card layouts, the user is able to set the number of cards displayed in a row by 4 and TC_FG_102 Verify that numCards value set by a user will be applied for any viewport of a grid which with card layout.`, (done) => { layoutState = layoutManager.getLayoutState(); if (layoutState.cardLayout) { expect(layoutState.cardLayout.numCards).toBe(4); expect(layoutState.cardLayout.width).toBe(223.75); } expect(layoutManager.getCurrentLayoutType()).toBe(LayoutType.Card); done(); }); it('TC_FG_086 layouttype set card through config', (done)=>{ expect(layoutManager.getCurrentLayoutType()).toBe(LayoutType.Card); done(); }); it('TC_FG_094 tempplate set by user must be considered',(done) => { expect(layoutManager.getCardTemplate().toString()).toBe('function (params) { return \"
\"; }'); done(); }); }); describe('API tests', () => { let layoutManager: LayoutManager, layoutState: LayoutState; beforeAll(() => { layoutManager = new LayoutManager(rowLayoutInpConfig); layoutManager.getStores().vizRecordDomain.set({start: 0, end: 2}); layoutManager.calculatelayout(); }); it('TC_FG_093 density set must be honoured, setDensity API test',(done)=>{ layoutManager.setDensity(LayoutDensityType.Comfortable); expect(layoutManager.getDensity()).toBe(LayoutDensityType.Comfortable); done(); }); it('TC_FG_147 getLayout API must return layoutstate', (done) => { layoutState = layoutManager.getLayoutState(); expect(layoutState.rowLayout).toBeDefined(); done(); }); it('TC_FG_166 TC_FG_167 TC_FG_169 TC_FG_172 sizecolumnstofit api', (done) => { layoutManager.sizeColumnsToFit(0, 3, containerDim.width); expect(layoutManager.getLayoutState().rowLayout!.headerDimState.cell[1].width).toBe(150); expect(layoutManager.getLayoutState().rowLayout!.headerDimState.cell[2].width).toBe(200); expect(layoutManager.getLayoutState().rowLayout!.headerDimState.cell[3].width).toBe(400); done(); }); it('calculateRowHeight api must return rowheight added with density mapped px value', (done) => { expect(layoutManager.calculateRowHeight(10)).toBe(34); expect(layoutManager.getDensity()).toBe(LayoutDensityType.Comfortable); done(); }); it('TC_FG_261 TC_FG_263 TC_FG_266 row height need to not to be updated when same rowheight value set,densed row height must be set while setting rowheight', (done) => { layoutManager.setRowHeight(10); layoutManager.calculatelayout(); layoutState = layoutManager.getLayoutState(); expect(layoutManager.getRowHeight()).toBe(10); expect(layoutState.rowLayout!.rowDimState[0].height).toBe(34); expect(layoutState.rowLayout!.rowDimState[1].height).toBe(34); done(); }); });