Files
kra-new/web/src/view/dashboard/components/dashboard-metrics.test.js
T

27 lines
1.7 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { overviewCards, escapeChartText } from './dashboard-metrics.js'
test('overview preserves exact money, eight cards, and unavailable event data', () => {
const cards = overviewCards({ available: true, settings: { days: 15, amount: 500 }, cards: {
todayPay: { value: '9007199254740993.01', changeRate: null },
todayRegister: { value: '0.00', changeRate: '0' },
todayActive: { value: '5998.00', changeRate: '2.1' },
lockedPromote: { value: null, compareLabel: '事件数据未接入' }
} })
assert.equal(cards.length, 8)
assert.equal(cards.find(c => c.key === 'todayPay').value, '¥9,007,199,254,740,993.01')
assert.equal(cards.find(c => c.key === 'todayRegister').value, '0')
assert.equal(cards.find(c => c.key === 'todayActive').value, '5,998')
assert.equal(cards.find(c => c.key === 'lockedPromote').value, '未接入')
assert.equal(cards.find(c => c.key === 'todayRegister').tip, '所选区间内新增注册玩家数。\n勾选右上角「身份证去重」后按实名身份证去重:同一身份证多账号计 1 人,无实名信息不计入。')
assert.match(cards.find(c => c.key === 'effectivePromote').tip, /注册后 15 天内累计充值流水满 ¥500/)
assert.match(cards.find(c => c.key === 'lockedPromote').tip, /1 月锁定、2 月恢复正常/)
assert.ok(overviewCards(null).every(c => c.value === '—'))
assert.ok(overviewCards({ available: false }).every(c => c.value === '未接入'))
})
test('chart HTML tooltips escape provider-controlled names', () => {
assert.equal(escapeChartText('<img src=x onerror="alert(1)">&'), '&lt;img src=x onerror=&quot;alert(1)&quot;&gt;&amp;')
})