From 7afc75dbfffe3e9d0b9637909efe9c29c6e5ed73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 20 Mar 2024 17:24:37 +0100 Subject: [PATCH] Fix wrong BTC sum when adding multiple line items closes #220 --- app/components/add-reimbursement/component.js | 2 +- app/components/add-reimbursement/template.hbs | 5 ++- .../add-reimbursement/component-test.js | 34 +++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/components/add-reimbursement/component.js b/app/components/add-reimbursement/component.js index 16ea04c..58bcda1 100644 --- a/app/components/add-reimbursement/component.js +++ b/app/components/add-reimbursement/component.js @@ -74,7 +74,7 @@ export default class AddReimbursementComponent extends Component { } updateTotalAmountFromFiat() { - let btcAmount = parseFloat(this.total); + let btcAmount = 0; if (this.exchangeRates.btceur > 0 && this.totalEUR > 0) { btcAmount += (this.totalEUR / this.exchangeRates.btceur); diff --git a/app/components/add-reimbursement/template.hbs b/app/components/add-reimbursement/template.hbs index 1f80f71..271d67a 100644 --- a/app/components/add-reimbursement/template.hbs +++ b/app/components/add-reimbursement/template.hbs @@ -14,6 +14,7 @@

Total amount (BTC):

+ id="add-another-item" class="green small" type="button"> + + Add another item +

{{else}}

No line items yet.

diff --git a/tests/integration/components/add-reimbursement/component-test.js b/tests/integration/components/add-reimbursement/component-test.js index fd02877..a1b3233 100644 --- a/tests/integration/components/add-reimbursement/component-test.js +++ b/tests/integration/components/add-reimbursement/component-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; +import { click, fillIn, render } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; import contributors from '../../../fixtures/contributors'; @@ -22,7 +22,37 @@ module('Integration | Component | add-reimbursement', function(hooks) { assert.equal(this.element.querySelector('select#contributor option:checked').value, "3", 'preselects the connected contributor account'); }); + + test('Adding expense items', async function(assert) { await render(hbs``); - assert.ok(true); + + assert.dom(this.element).includesText('New expense item'); + + await fillIn('form input[name="expense-amount"]', '49'); + await fillIn('form input[name="expense-title"]', 'Domain kosmos.org (yearly fee)'); + await click('form#add-expense-item input[type="submit"]'); + + assert.equal(this.element.querySelector('input[name="total-eur"]').value, '49', + 'updates the total EUR amount'); + assert.equal(this.element.querySelector('input[name="total-usd"]').value, '0', + 'does not update the total USD amount'); + assert.equal(this.element.querySelector('input[name="total-btc"]').value, '0.00534493', + 'updates the total BTC amount'); + + assert.dom(this.element).doesNotIncludeText('New expense item'); + + await click('button#add-another-item'); + + await fillIn('form input[name="expense-amount"]', '29'); + await fillIn('select[name="expense-currency"]', 'USD'); + await fillIn('form input[name="expense-title"]', 'Domain kosmos.social (yearly fee)'); + await click('form#add-expense-item input[type="submit"]'); + + assert.equal(this.element.querySelector('input[name="total-usd"]').value, '29', + 'updates the total USD amount'); + assert.equal(this.element.querySelector('input[name="total-eur"]').value, '49', + 'does not update the total EUR amount'); + assert.equal(this.element.querySelector('input[name="total-btc"]').value, '0.00804268', + 'updates the total BTC amount'); }); });