import { describe, expect, it } from 'vitest' import { applyKitActionColumn, KIT_ACTION_COLUMN_SIZE, kitColumnPinning, kitDataGridTableClassNames, kitDataGridTableLayout, } from './frame-data-grid' describe('kitDataGridTableLayout', () => { it('filtering-2 defaults: dense, headerBackground false, width fixed', () => { const layout = kitDataGridTableLayout() expect(layout.dense).toBe(true) expect(layout.headerBackground).toBe(false) expect(layout.width).toBe('fixed') expect(layout.headerSticky).toBe(false) expect('stripped' in layout ? layout.stripped : undefined).toBeUndefined() expect(layout.columnsPinnable).toBe(false) }) it('kit tableClassNames совпадает с filtering-2 edgeCell', () => { expect(kitDataGridTableClassNames.edgeCell).toBe('first:ps-3 last:pe-3') expect(kitDataGridTableClassNames.base).toBe( '[&_[data-pinned]]:bg-(--frame-panel-bg)', ) }) it('именованные opts: auto + pin', () => { const layout = kitDataGridTableLayout({ width: 'auto', columnsPinnable: true, }) expect(layout.width).toBe('auto') expect(layout.columnsPinnable).toBe(true) expect(layout.headerBackground).toBe(false) }) }) describe('applyKitActionColumn', () => { it('locks filtering-2 size on id=actions', () => { const [name, actions] = applyKitActionColumn([ { id: 'name', header: 'Name' }, { id: 'actions', header: () => null, cell: () => 'x' }, ]) expect(name?.id).toBe('name') expect(actions?.size).toBe(KIT_ACTION_COLUMN_SIZE) expect(actions?.minSize).toBe(KIT_ACTION_COLUMN_SIZE) expect(actions?.maxSize).toBe(KIT_ACTION_COLUMN_SIZE) expect(actions?.enableSorting).toBe(false) expect(actions?.enableResizing).toBe(false) }) it('keeps explicit size (data-grid-base-7 text button)', () => { const [actions] = applyKitActionColumn([ { id: 'actions', size: 104, cell: () => 'x' }, ]) expect(actions?.size).toBe(104) expect(actions?.minSize).toBe(104) expect(actions?.maxSize).toBe(104) }) it('does not rewrite a non-actions last column', () => { const [col] = applyKitActionColumn([{ id: 'name', header: 'Name' }]) expect(col?.size).toBeUndefined() expect(col?.enableResizing).toBeUndefined() }) it('applies DNA when pinLastColumn even without id=actions', () => { const [col] = applyKitActionColumn([{ id: 'other', cell: () => 'x' }], { pinLastColumn: true, }) expect(col?.size).toBe(KIT_ACTION_COLUMN_SIZE) expect(col?.maxSize).toBe(KIT_ACTION_COLUMN_SIZE) }) }) describe('kitColumnPinning', () => { it('does not end-pin without horizontalScroll', () => { const result = kitColumnPinning({ pinLastColumn: true, lastColId: 'actions', }) expect(result.enablePinning).toBe(false) expect(result.columnPinning.end).toEqual([]) }) it('end-pins only with horizontalScroll', () => { const result = kitColumnPinning({ pinLastColumn: true, horizontalScroll: true, lastColId: 'actions', }) expect(result.enablePinning).toBe(true) expect(result.columnPinning.end).toEqual(['actions']) }) })