// Generated, do not edit. sha256:43e27327deb8801c6e640676df136f116a9043c3e6d4e1f65b6469a9f90a6fa6 import { describe, it, mock } from 'node:test'; import assert from 'node:assert/strict'; const INSTELLING = { asset_show_name: 1, asset_show_symbol: 1 }; mock.module('../../client/app-settings.js', { namedExports: { appSetting: (k) => INSTELLING[k], baseCurrency: () => 'EUR', setAppSetting: async () => {} }, }); const { fiatAtPrice, fiatValue, fiatHistorical } = await import('../../client/ui/fiat.js'); const { assetLabel, assetLabelHtml } = await import('../../client/ui/asset-label.js'); const { RANGE_DAYS, SPOT_RANGE_DAYS, rangeSeries, intradayStart, rangeCycleButton, wireRangeCycle, rangePointLabel, rangePointSources, namedDaySources } = await import('../../client/ui/range-cycle.js'); const { serviceOrder, matrixCardHtml } = await import('../../client/ui/source-matrix.js'); describe('fiatAtPrice: van kleinste eenheid naar een bedrag', () => { it('rekent met de decimalen van het asset', () => { assert.match(fiatAtPrice(100000, 8, 50000), /50,00/); }); it('gebruikt acht decimalen als er geen meegegeven zijn', () => { assert.equal(fiatAtPrice(100000000, undefined, 7), fiatAtPrice(100000000, 8, 7)); }); it('geeft een lege string als er geen prijs bekend is', () => { assert.equal(fiatAtPrice(100, 8, null), ''); assert.equal(fiatAtPrice(100, 8, undefined), ''); }); it('rekent nul gewoon uit in plaats van hem als onbekend te behandelen', () => { assert.match(fiatAtPrice(0, 8, 50000), /0,00/); }); }); describe('fiatValue en fiatHistorical: de twee wegen naar leeg', () => { it('geeft niets voor het reken-asset', () => { assert.equal(fiatValue(12345, { id: 1, symbol: 'EUR', decimals: 2 }, 'eur'), ''); }); it('geeft niets zonder koers in de cache, en zonder asset', () => { assert.equal(fiatValue(100, { id: 999, symbol: 'BTC', decimals: 8 }, 'eur'), ''); assert.equal(fiatValue(100, null, 'eur'), ''); assert.equal(fiatHistorical(100, null, '2026-03-01'), ''); assert.equal(fiatHistorical(100, { id: 999, decimals: 8 }, '2026-03-01'), ''); }); }); describe('assetLabel: de twee weergaveschuiven', () => { const btc = { name: 'Bitcoin', symbol: 'BTC' }; it('toont naam en symbool samen', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); assert.equal(assetLabel(btc), 'Bitcoin (BTC)'); }); it('toont alleen de naam, of alleen het symbool', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 0 }); assert.equal(assetLabel(btc), 'Bitcoin'); Object.assign(INSTELLING, { asset_show_name: 0, asset_show_symbol: 1 }); assert.equal(assetLabel(btc), 'BTC'); }); it('valt terug op wat er wél is als de gekozen helft ontbreekt', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 0 }); assert.equal(assetLabel({ symbol: 'XAU' }), 'XAU'); Object.assign(INSTELLING, { asset_show_name: 0, asset_show_symbol: 1 }); assert.equal(assetLabel({ name: 'Goud' }), 'Goud'); }); it('leest de alias-velden van een JOIN-rij', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); assert.equal(assetLabel({ asset_name: 'Goud', asset_symbol: 'XAU' }), 'Goud (XAU)'); }); it('geeft voorrang aan het eigen veld boven de alias, ook als dat leeg is', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 0 }); assert.equal(assetLabel({ name: null, asset_name: 'Bitcoin', symbol: 'BTC' }), 'BTC'); }); it('geeft een lege string voor niets', () => { assert.equal(assetLabel(null), ''); assert.equal(assetLabelHtml(null), ''); }); it('laat met `withoutSymbol` het symbool weg, want de hoeveelheid droeg het al', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); const met = assetLabelHtml({ asset_name: 'Proef zonder koers', asset_symbol: 'PRFN' }); const zonder = assetLabelHtml({ asset_name: 'Proef zonder koers', asset_symbol: 'PRFN' }, { withoutSymbol: true }); assert.match(met, /PRFN/, 'zonder de vlag blijft het gedrag ongewijzigd'); assert.match(zonder, /Proef zonder koers/); assert.ok(!zonder.includes('PRFN'), zonder); }); it('toont een naam die gelijk is aan het symbool één keer, ook met beide schuiven aan', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); assert.equal(assetLabel({ name: 'XRP', symbol: 'XRP' }), 'XRP'); assert.equal(assetLabel({ name: 'Xrp', symbol: 'XRP' }), 'Xrp'); assert.equal(assetLabel({ name: 'XRP Ledger', symbol: 'XRP' }), 'XRP Ledger (XRP)'); const h = assetLabelHtml({ name: 'XRP', symbol: 'XRP' }); assert.equal(h.match(/XRP/g).length, 1, h); assert.ok(!h.includes('t-muted-cell'), h); }); it('valt met `withoutSymbol` terug op het symbool als er geen naam te tonen is', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); assert.match(assetLabelHtml({ asset_symbol: 'PRFN' }, { withoutSymbol: true }), /PRFN/); Object.assign(INSTELLING, { asset_show_name: 0, asset_show_symbol: 1 }); assert.match(assetLabelHtml({ asset_name: 'Bitcoin', asset_symbol: 'BTC' }, { withoutSymbol: true }), /BTC/); }); }); describe('assetLabelHtml: bouwt HTML en escapet zelf', () => { it('zet naam en symbool in hun eigen span', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 1 }); const h = assetLabelHtml({ name: 'Bitcoin', symbol: 'BTC' }); assert.match(h, /Bitcoin<\/span>/); assert.match(h, /BTC<\/span>/); }); it('escapet een naam uit de database', () => { Object.assign(INSTELLING, { asset_show_name: 1, asset_show_symbol: 0 }); const h = assetLabelHtml({ name: ' & co' }); assert.equal(h, '<script>x</script> & co'); assert.equal(h.includes('