Files
AtreidesAssetsFree/tests/ui/tweede-valuta.test.mjs
2026-10-29 11:57:29 +01:00

64 lines
2.5 KiB
JavaScript

// Generated, do not edit. sha256:0810eb8c4c62fd3109b5429626a785af591e318584e97a2a5a912991b30c9a95
import { describe, it, mock } from 'node:test';
import assert from 'node:assert/strict';
let BASIS = 'EUR';
mock.module('../../client/app-settings.js', {
namedExports: { appSetting: () => 1, baseCurrency: () => BASIS },
});
const fiat = (symbol, id) => ({ id, symbol, name: symbol, kind: 'fiat' });
let ASSETS = [];
mock.module('../../client/data/assets.js', { namedExports: { listAssets: async () => ASSETS } });
let KOERS = {};
mock.module('../../client/price/providers.js', {
namedExports: { currentRate: async code => (code === BASIS ? 1 : KOERS[code] ?? null) },
});
const { secondCurrencyOf, secondCurrencyChoices, secondAmount } = await import('../../client/widgets/second-currency.js');
const { fmtMoney } = await import('../../client/ui/format.js');
describe('secondCurrencyOf: de keuze van een widget', () => {
it('leest de keuze uit params', () => {
assert.equal(secondCurrencyOf({ params: { second: 'USD' } }), 'USD');
});
it('valt terug op de oude voorkeur als de widget nooit gekozen heeft', () => {
assert.equal(secondCurrencyOf({ params: null }, 'USD'), 'USD');
assert.equal(secondCurrencyOf({ params: { assetId: 3 } }, 'USD'), 'USD');
});
it('houdt een bewuste "geen" vast, ook als de oude voorkeur USD zegt', () => {
assert.equal(secondCurrencyOf({ params: { second: null } }, 'USD'), null);
});
it('telt de rekenvaluta als geen tweede valuta', () => {
BASIS = 'USD';
try { assert.equal(secondCurrencyOf({ params: { second: 'USD' } }), null); }
finally { BASIS = 'EUR'; }
});
});
describe('secondCurrencyChoices: welke munten er te kiezen zijn', () => {
it('alleen fiat met een koers, zonder de rekenvaluta, op alfabet', async () => {
ASSETS = [fiat('USD', 1), fiat('EUR', 2), fiat('GBP', 3), fiat('JPY', 4), { id: 5, symbol: 'BTC', kind: 'crypto' }];
KOERS = { USD: 0.8, GBP: 1.2 };
assert.deepEqual(await secondCurrencyChoices(), ['GBP', 'USD']);
});
});
describe('secondAmount: het bedrag in de tweede valuta', () => {
it('deelt door de koers van die munt', async () => {
KOERS = { USD: 0.8 };
assert.equal(await secondAmount(800, 'USD', { decimals: 0 }), fmtMoney(1000, 'USD', { decimals: 0 }));
});
it('geeft niets zonder koers, zonder munt of zonder bedrag', async () => {
KOERS = {};
assert.equal(await secondAmount(800, 'USD'), '');
assert.equal(await secondAmount(800, null), '');
assert.equal(await secondAmount(null, 'USD'), '');
});
});