// FILE: _St/Analyze8780/test_analyze8780_ui.js | ROLE: Analyze8780 검색 와일드카드·차트·페이징 UI 회귀 테스트
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const vm = require('vm');

const html = fs.readFileSync(path.join(__dirname, 'web', 'index.html'), 'utf8');
const match = html.match(/function matchAccountQuery\(username,rawPattern\)\{[^\n]+\}/);
assert.ok(match, 'matchAccountQuery helper missing');
const context = {};
vm.runInNewContext(`${match[0]};this.matchAccountQuery=matchAccountQuery;`, context);
const search = context.matchAccountQuery;

assert.strictEqual(search('abc', 'abc'), true);
assert.strictEqual(search('xabc', 'abc'), false, 'bare text must be exact, not contains');
assert.strictEqual(search('abcdef', 'abc%'), true);
assert.strictEqual(search('xabc', 'abc%'), false);
assert.strictEqual(search('xabc', '%abc'), true);
assert.strictEqual(search('abcx', '%abc'), false);
assert.strictEqual(search('xabcx', '%abc%'), true);
assert.strictEqual(search('xyz', '%abc%'), false);
assert.strictEqual(search('abc', '@abc'), true);

assert.ok(!html.includes('id="accountPager"'));
assert.ok(html.includes('const ACCOUNT_PAGE_SIZE=10000'));
assert.ok(html.includes('<option value="10000">10000</option>'));
assert.ok(html.includes('/api/database/open'));
assert.ok(html.includes('https://cdn.jsdelivr.net/npm/apexcharts'));
assert.ok(html.includes('stats?limit=${CHART_HISTORY_LIMIT}'));
assert.ok(html.includes('shared:true,intersect:false,followCursor:true'));
assert.ok(html.includes('object-fit:contain'));
console.log('OK test_analyze8780_ui');
