fix: 兼容 HeroSMS 国家接口字典响应

This commit is contained in:
QLHazyCoder
2026-05-20 20:47:21 +08:00
parent 59b7d77b5d
commit 9a1c3fdce3
2 changed files with 60 additions and 2 deletions
@@ -160,9 +160,39 @@ test('sidepanel loads SMS country lists silently during startup fallback', () =>
assert.doesNotMatch(fiveSimLoader, /console\.(?:warn|error)\('加载 5sim 国家列表失败:'/);
assert.match(sidepanelSource, /loadHeroSmsCountries\(\{ silent: true, preferFallbackOnly: true \}\)/);
assert.match(sidepanelSource, /loadFiveSimCountries\(\{ silent: true, preferFallbackOnly: true \}\)/);
assert.match(sidepanelSource, /await loadHeroSmsCountries\(\{ silent: true \}\);/);
assert.doesNotMatch(sidepanelSource, /console\.error\('加载 (?:HeroSMS|5sim|NexSMS) 国家列表失败:'/);
});
test('HeroSMS country parser accepts keyed country maps from the live API', () => {
const api = new Function(`
${extractFunction('normalizeHeroSmsCountryPayloadEntries')}
${extractFunction('parseHeroSmsCountryPayload')}
return { parseHeroSmsCountryPayload };
`)();
const keyedPayload = {
52: { id: 52, eng: 'Thailand', chn: '泰国' },
6: { id: 6, eng: 'Indonesia', chn: '印度尼西亚' },
};
const ids = (payload) => api.parseHeroSmsCountryPayload(payload)
.map((entry) => entry.id)
.sort((left, right) => left - right);
assert.deepStrictEqual(
ids(keyedPayload),
[6, 52]
);
assert.deepStrictEqual(
ids({ value: keyedPayload }),
[6, 52]
);
assert.deepStrictEqual(
ids({ value: Object.values(keyedPayload) }),
[6, 52]
);
});
test('sidepanel source wires free reusable phone save and clear actions to runtime messages', () => {
assert.match(sidepanelSource, /const inputFreePhoneReuseEnabled = document\.getElementById\('input-free-phone-reuse-enabled'\);/);
assert.match(sidepanelSource, /const inputFreePhoneReuseAutoEnabled = document\.getElementById\('input-free-phone-reuse-auto-enabled'\);/);