29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { splitTableActions, runTableAction } from './tableActions.ts'
|
|
|
|
test('shows up to three permitted actions and folds only when there are more', () => {
|
|
const actions = Array.from({ length: 5 }, (_, index) => ({ key: String(index), label: String(index), run() {} }))
|
|
for (const count of [0, 1, 2, 3]) {
|
|
const result = splitTableActions(actions.slice(0, count))
|
|
assert.equal(result.visible.length, count)
|
|
assert.equal(result.overflow.length, 0)
|
|
}
|
|
for (const count of [4, 5]) {
|
|
const result = splitTableActions(actions.slice(0, count))
|
|
assert.deepEqual(result.visible, actions.slice(0, 2))
|
|
assert.deepEqual(result.overflow, actions.slice(2, count))
|
|
}
|
|
})
|
|
|
|
test('disabled and loading actions cannot execute or disappear from the layout', () => {
|
|
let count = 0
|
|
const action = { key: 'edit', label: '编辑', run() { count++ } }
|
|
runTableAction({ ...action, disabled: true })
|
|
runTableAction({ ...action, loading: true })
|
|
assert.equal(count, 0)
|
|
runTableAction(action)
|
|
assert.equal(count, 1)
|
|
assert.equal(splitTableActions([{ ...action, disabled: true }]).visible.length, 1)
|
|
})
|