39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
// cards.js 纯函数测试:三栏降级布局(time 卡恒第一列、disabled 卡跳过、priority 升序分配)
|
|
// cards.js pure-function tests: three-column fallback layout
|
|
// (time always first column, disabled cards skipped, priority ascending)
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const { layout } = require('../app/src/main/assets/h5/js/cards/cards.js');
|
|
|
|
test('time card always in first column', () => {
|
|
const cols = layout([
|
|
{ id: 'time', priority: 0 },
|
|
{ id: 'media', priority: 1 },
|
|
{ id: 'weather', priority: 2 },
|
|
{ id: 'calendar', priority: 3 },
|
|
]);
|
|
assert.strictEqual(cols[0][0], 'time');
|
|
});
|
|
|
|
test('disabled card skipped', () => {
|
|
const cols = layout([
|
|
{ id: 'time', priority: 0 },
|
|
{ id: 'media', priority: 1, enabled: false },
|
|
{ id: 'weather', priority: 2 },
|
|
]);
|
|
assert.strictEqual(cols[1][0], 'weather');
|
|
});
|
|
|
|
test('priority ascending fills columns round-robin', () => {
|
|
const cols = layout([
|
|
{ id: 'c', priority: 3 },
|
|
{ id: 'a', priority: 1 },
|
|
{ id: 'b', priority: 2 },
|
|
]);
|
|
assert.deepStrictEqual(cols, [['a'], ['b'], ['c']]);
|
|
});
|
|
|
|
test('empty input yields three empty columns', () => {
|
|
assert.deepStrictEqual(layout([]), [[], [], []]);
|
|
});
|