const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const test = require('node:test'); const assert = require('node:assert/strict'); test('table pagination cards skip the minimum height for short content', () => { const cardStyle = { properties: {}, setProperty(name, value) { this.properties[name] = String(value); }, removeProperty(name) { delete this.properties[name]; } }; const card = { style: cardStyle, scrollHeight: 200, getBoundingClientRect() { return { top: 100 }; } }; const bodyClassList = { toggled: null, toggle(name, value) { this.toggled = { name, value }; } }; const sandbox = { document: { body: { classList: bodyClassList }, querySelector(selector) { return selector === '[data-table-pagination-card]' ? card : null; }, querySelectorAll(selector) { return selector === '[data-table-pagination-card]' ? [card] : []; } }, window: null, URL, console, setTimeout, clearTimeout }; sandbox.window = Object.assign(sandbox, { innerHeight: 280, addEventListener() {}, clearTimeout, setTimeout, requestAnimationFrame(callback) { callback(); } }); const scriptPath = path.join(__dirname, '..', 'src', 'web', 'public', 'js', 'table', 'table-search.js'); const script = fs.readFileSync(scriptPath, 'utf8'); vm.runInNewContext(script, sandbox, { filename: scriptPath }); assert.equal(cardStyle.properties['--table-pagination-card-min-height'], undefined); assert.equal(cardStyle.properties['--table-pagination-card-max-height'], '320px'); assert.deepEqual(bodyClassList.toggled, { name: 'table-pagination-page', value: true }); }); test('table pagination cards keep the minimum height for tall content', () => { const cardStyle = { properties: {}, setProperty(name, value) { this.properties[name] = String(value); }, removeProperty(name) { delete this.properties[name]; } }; const card = { style: cardStyle, scrollHeight: 640, getBoundingClientRect() { return { top: 100 }; } }; const bodyClassList = { toggled: null, toggle(name, value) { this.toggled = { name, value }; } }; const sandbox = { document: { body: { classList: bodyClassList }, querySelector(selector) { return selector === '[data-table-pagination-card]' ? card : null; }, querySelectorAll(selector) { return selector === '[data-table-pagination-card]' ? [card] : []; } }, window: null, URL, console, setTimeout, clearTimeout }; sandbox.window = Object.assign(sandbox, { innerHeight: 280, addEventListener() {}, clearTimeout, setTimeout, requestAnimationFrame(callback) { callback(); } }); const scriptPath = path.join(__dirname, '..', 'src', 'web', 'public', 'js', 'table', 'table-search.js'); const script = fs.readFileSync(scriptPath, 'utf8'); vm.runInNewContext(script, sandbox, { filename: scriptPath }); assert.equal(cardStyle.properties['--table-pagination-card-min-height'], '320px'); assert.equal(cardStyle.properties['--table-pagination-card-max-height'], '320px'); assert.deepEqual(bodyClassList.toggled, { name: 'table-pagination-page', value: true }); });