aboutsummaryrefslogtreecommitdiffstats
path: root/tools/amount-field-unit-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/amount-field-unit-test.js')
-rw-r--r--tools/amount-field-unit-test.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/amount-field-unit-test.js b/tools/amount-field-unit-test.js
index 596969d..a25432e 100644
--- a/tools/amount-field-unit-test.js
+++ b/tools/amount-field-unit-test.js
@@ -11,7 +11,7 @@ import puppeteer from './puppeteer.js';
const bundle = await Bun.build({ entrypoints: ['src/app.js'], target: 'browser', minify: true,
plugins: [{ name: 'amount-field-test', setup(build) {
build.onLoad({ filter: /src\/app\.js$/ }, async ({ path }) => ({ loader: 'js', contents: await Bun.file(path).text() + `
-window.amtApp = { ctx, ui, toggleUnit, get unit() { return unit; } };
+window.amtApp = { ctx, ui, toggleUnit, handleScanned, get unit() { return unit; } };
` }));
build.onLoad({ filter: /src\/video-compress\.js$/ }, () => ({ loader: 'js', contents: 'export async function compressVideo(f) { return f; }' }));
} }] });
@@ -46,6 +46,16 @@ try {
out.ring = [];
for (let i = 0; i < 3; i++) { amtApp.toggleUnit(); out.ring.push([amtApp.unit, ...rs.map((r) => r.amount)]); }
rs.splice(1);
+ // a scanned payment request with an amount, with dollars as the unit
+ while (amtApp.unit !== 'fiat') amtApp.toggleUnit();
+ rs[0].amount = ''; rs[0].address = '';
+ amtApp.handleScanned('bitcoin:bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080?amount=0.0005&label=x');
+ out.scan = [amtApp.unit, localStorage.getItem('btc-wallet-unit'), rs[0].address, rs[0].amount, ctx.parseAmount(rs[0].amount)];
+ // without an amount the unit is left alone
+ amtApp.toggleUnit();
+ const before = amtApp.unit;
+ amtApp.handleScanned('bitcoin:bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080');
+ out.plain = [before, amtApp.unit];
return out;
});
console.log(r);
@@ -60,6 +70,9 @@ try {
['fiat', '93.31', '0.13', '', 'abc'],
['sats', '62212', '93', '', 'abc'],
], 'a typed amount follows the unit around the ring and comes back exact; blanks and junk are left alone');
+ assert.deepEqual(r.scan, ['btc', 'btc', 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080', '0.00050000', 50000],
+ 'a scanned bitcoin: request with an amount switches the unit to BTC and fills 50,000 sats, not 0.0005 dollars');
+ assert.deepEqual(r.plain, ['fiat', 'fiat'], 'a request with no amount leaves the unit as it was');
assert.deepEqual(errors, []);
console.log('✅ amount fills follow the display unit');
} finally { await browser.close(); server.stop(true); }