import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import test from 'node:test' const root = dirname(fileURLToPath(import.meta.url)) const source = readFileSync( join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'), 'utf8', ) const styles = readFileSync(join(root, '../src/styles/customer/binding.css'), 'utf8') test('只有唯一绑定决策允许时才自动弹核对框', () => { assert.ok(source.includes('if (!bindingDecision?.canConfirmBinding) return')) assert.ok(source.includes('if (nextDecision?.canConfirmBinding) {')) assert.ok(!source.includes("bindingInfo.comparison.verdict === 'match'")) }) test('资料不一致时固定提供重新扫码换绑与上一步修改资料', () => { assert.ok(source.includes('decisionRequiresRebind || decisionCanRefreshQr')) assert.ok(source.includes('decisionCanEditProfile')) assert.ok(source.includes('重新扫码换绑')) assert.ok(source.includes('上一步修改资料')) assert.ok(source.includes('onClick={() => void openProfileEditor()}')) // 取消同步平台角色与直接使用原角色的快捷路径。 assert.ok(!source.includes('同步平台角色')) assert.ok(!source.includes('确认使用原角色')) assert.ok(styles.includes('.customer-binding-role-actions')) }) test('保存资料后只由单一自动绑定流程推进,不再并发轮询', () => { assert.ok(!source.includes('function reopenBindingConfirm(')) const saveStart = source.indexOf('async function handleSaveProfile()') assert.ok(saveStart > 0) const saveBody = source.slice(saveStart, saveStart + 1800) assert.ok(!saveBody.includes('pollCustomerBinding(')) assert.ok(source.includes("'资料已保存,正在重新核对平台角色'")) assert.ok(source.includes("'资料已保存,请继续登录虎牙账号'")) assert.ok(source.includes("!['query_binding', 'start_first_binding'].includes")) }) test('虎牙客户页固定先填写资料,再登录并绑定角色', () => { const stepsStart = source.indexOf('const HUYA_FLOW_STEPS') const stepsSource = source.slice(stepsStart, stepsStart + 260) assert.ok(stepsSource.includes("'填写游戏资料'")) assert.ok(stepsSource.includes("'登录虎牙账号'")) assert.ok(stepsSource.includes("'绑定游戏角色'")) assert.ok(source.includes('showHuyaProfileStage')) assert.ok(source.includes('(isWeibo || profileComplete) &&')) }) test('登录和绑定专用同步阶段暂停整单轮询', () => { assert.ok(source.includes('const dedicatedLoginPoll =')) assert.ok(source.includes('const dedicatedBindingPoll =')) assert.ok(source.includes('if (dedicatedLoginPoll || dedicatedBindingPoll) return')) assert.ok(source.includes('}, 10_000)')) }) test('虎牙绑定只在二维码或平台生效等待态轮询,过期二维码不再持续请求', () => { assert.ok(source.includes("'first_bind_qr_pending'")) assert.ok(source.includes("'rebind_qr_pending'")) assert.ok(source.includes("'rebind_effect_pending'")) const pollingStart = source.indexOf('const huyaBindingPolling') const pollingEnd = source.indexOf('const isWeibo', pollingStart) const pollingSource = source.slice(pollingStart, pollingEnd) assert.ok(!pollingSource.includes('bindingActions.has(')) }) test('角色名和区服一致才出现确认绑定,不一致时展示原因', () => { assert.ok(source.includes('确认绑定此角色')) assert.ok(source.includes('canConfirmDecision')) assert.ok(source.includes('两侧角色信息不一致,无法提交平台绑定')) assert.ok(source.includes('customer-binding-modal-error')) }) test('二维码区明确区分虎牙账号 UID 与游戏角色 UID', () => { assert.ok(source.includes('扫码后系统会核对待确认角色的名称与区服')) assert.ok(source.includes('不会用虎牙账号 UID')) assert.ok(source.includes('游戏角色 UID 与稍后登录的虎牙账号 UID 不是同一个编号')) assert.ok(source.includes('本次待确认角色')) assert.ok(source.includes('虎牙账号 UID')) assert.ok(!source.includes('平台已返回加密角色标识')) assert.ok(!source.includes('平台加密标识已识别')) assert.ok(!source.includes('const bindingPendingUid')) assert.ok(!source.includes('const huyaUid = String(selectedTask?.huyaUid')) }) test('换绑流程刷新二维码必须带 forceRebind,避免直接返回已有角色', () => { assert.ok(source.includes('function handleRefreshBindingQr()')) assert.ok(source.includes("bindingDecision?.primaryAction === 'start_rebind'")) assert.ok(source.includes("bindingDecision?.primaryAction === 'refresh_rebind_qr'")) // 三处刷新/重新获取入口都不能再固定传 false。 assert.ok(!source.includes('handleRefreshBinding(false)')) assert.ok(source.includes('onClick={handleRefreshBindingQr}')) })