// FILE: _St/IG_StYellow/test_ext_ui_compact_v282.js | ROLE: v282 MAIN 통합 진단·SIDE 1부터 버튼 회귀 검사
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = __dirname;
const read = (name) => fs.readFileSync(path.join(root, name), 'utf8');
const manifest = JSON.parse(read('manifest.json'));
const content = read('content_instagram.js');
const side = read('side.js');
const html = read('side.html');

assert.strictEqual(manifest.version, '2.3.8.3190');
assert.strictEqual(manifest.version_name, '2.3.8.319');
assert.ok(manifest.description.includes('v282'));

for (const token of [
  "control.id = 'igblue_main_diag_control'",
  "toggle.id = 'igblue_main_diag_toggle'",
  "minimize.id = 'igblue_main_diag_minimize'",
  "detail.id = 'igblue_main_diag_expand'",
  "refresh.id = 'igblue_main_diag_refresh'",
  "copy.id = 'igblue_main_diag_copy'",
  "toggle.textContent = 'CDP:? · 탭 0 · OWNER 없음'",
  "return `CDP:${cdp} · 탭 ${count} · OWNER tab ${igblueTabIdTail(owner)}`",
  "toggle.title = '클릭: 전체 진단 복사'",
  "user-select:text",
  "IGBLUE/main_diag_collapsed_v282",
]) assert.ok(content.includes(token), `missing compact MAIN token: ${token}`);
assert.ok(content.includes('html body #IGBLUE_NoTop > .igblue-eye-toggle') && content.includes('html body #IGBLUE_NoTop > .igblue-dom-copy'), 'legacy eye/DOM copy buttons must be hidden');
assert.ok(content.includes("['IGBLUE_MainPanelEye','IGBLUE_DomDiagnosticCopy']"), 'legacy controls need inline important hiding after MAIN style insertion');
assert.ok(!content.includes('window.setInterval(igblueRefreshMainDiag, 700)'), '700ms panel rewrite must be removed');
const applyStart = content.indexOf('function igblueApplyTabControlState(value)');
const applyEnd = content.indexOf('function igblueRequestTabControlState', applyStart);
const applyBlock = content.slice(applyStart, applyEnd);
assert.ok(!applyBlock.includes('toggle.textContent ='), 'unchanged polling must not rewrite selectable compact text');
assert.ok(content.includes("if (text) text.textContent = igblueMainDiagText();"), 'detail panel must render only on explicit snapshot refresh');

assert.ok(html.includes('id="igblue_account_queue_start_one"'));
assert.ok(html.includes('>1부터</button>'));
assert.ok(html.includes('class="igblue-account-start-one"'));
for (const token of [
  'const startOne = document.getElementById("igblue_account_queue_start_one")',
  'const canStartOne = !disabled && urls.length > 0 && uiIndex === 0 && !teAutoPyRunning && !teAutoPyStopping;',
  'startOne.disabled = !canStartOne;',
  'teAutoPySetAccountQueueIndex(1);',
  'ev.stopPropagation();',
  '수집계정 목록 1번부터 시작하도록 설정했습니다.',
]) assert.ok(side.includes(token), `missing 1부터 token: ${token}`);

console.log('OK test_ext_ui_compact_v282');
