const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const { normalizeIcloudForwardMailProvider, normalizeIcloudTargetMailboxType, } = require('../mail-provider-utils'); const sidepanelSource = fs.readFileSync('sidepanel/sidepanel.js', 'utf8'); const sidepanelHtml = fs.readFileSync('sidepanel/sidepanel.html', 'utf8'); function extractFunction(name) { const markers = [`async function ${name}(`, `function ${name}(`]; const start = markers .map((marker) => sidepanelSource.indexOf(marker)) .find((index) => index >= 0); if (start < 0) { throw new Error(`missing function ${name}`); } let parenDepth = 0; let signatureEnded = false; let braceStart = -1; for (let i = start; i < sidepanelSource.length; i += 1) { const ch = sidepanelSource[i]; if (ch === '(') { parenDepth += 1; } else if (ch === ')') { parenDepth -= 1; if (parenDepth === 0) { signatureEnded = true; } } else if (ch === '{' && signatureEnded) { braceStart = i; break; } } let depth = 0; let end = braceStart; for (; end < sidepanelSource.length; end += 1) { const ch = sidepanelSource[end]; if (ch === '{') depth += 1; if (ch === '}') { depth -= 1; if (depth === 0) { end += 1; break; } } } return sidepanelSource.slice(start, end); } test('sidepanel html exposes phone verification toggle and multi-provider SMS rows', () => { const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8'); assert.match(html, /id="row-phone-verification-enabled"/); assert.match(html, /id="btn-toggle-phone-verification-section"/); assert.match(html, /id="row-phone-verification-fold"/); assert.match(html, /id="input-phone-verification-enabled"/); assert.match(html, /id="row-signup-method"/); assert.match(html, /id="row-signup-phone"/); assert.match(html, /id="input-signup-phone"/); assert.ok( html.indexOf('id="row-signup-phone"') > html.indexOf('id="phone-verification-section"'), 'signup phone runtime row should live inside the phone verification card' ); assert.ok( html.indexOf('id="row-signup-phone"') > html.indexOf('id="row-hero-sms-runtime-pair"'), 'signup phone runtime row should sit below the SMS order runtime row' ); assert.ok( html.indexOf('id="row-signup-phone"') > html.indexOf('hero-sms-runtime-grid'), 'signup phone runtime row should not be embedded in the SMS order runtime grid' ); assert.match(html, /data-signup-method="email"/); assert.match(html, /data-signup-method="phone"/); assert.match(html, /id="row-phone-sms-provider"/); assert.match(html, /id="select-phone-sms-provider"/); assert.match(html, /id="row-phone-sms-provider-order"/); assert.match(html, /id="select-phone-sms-provider-order"[^>]*multiple/); assert.match(html, /id="btn-phone-sms-provider-order-menu"/); assert.match(html, /id="row-phone-sms-provider-order-actions"/); assert.match(html, /id="btn-phone-sms-provider-order-reset"/); assert.match(html, /id="row-hero-sms-platform"/); assert.match(html, /id="select-phone-sms-provider"/); assert.match(html, /\.\.\/phone-sms\/providers\/hero-sms\.js/); assert.match(html, /\.\.\/phone-sms\/providers\/five-sim\.js/); assert.match(html, /\.\.\/phone-sms\/providers\/registry\.js/); assert.match(html, /