Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimbursement form fixes and improvements #223

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/components/add-reimbursement/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class AddReimbursementComponent extends Component {
this.exchangeRates.fetchRates();
}

get contributorId () {
return this.recipientId || this.kredits.currentUser?.id;
}

get isValidTotal () {
return isValidAmount(this.total);
}
Expand Down Expand Up @@ -70,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);
Expand Down Expand Up @@ -104,7 +108,7 @@ export default class AddReimbursementComponent extends Component {

@action
updateContributor (event) {
this.recipientId = event.target.value;
this.recipientId = parseInt(event.target.value);
}

@action
Expand Down Expand Up @@ -136,12 +140,12 @@ export default class AddReimbursementComponent extends Component {
if (!this.kredits.currentUser) { window.alert('You need to connect your RSK account first.'); return false }
if (!this.kredits.currentUserIsCore) { window.alert('Only core contributors can submit reimbursements.'); return false }

const contributor = this.contributors.findBy('id', parseInt(this.recipientId));
const contributor = this.contributors.findBy('id', this.contributorId);

const attributes = {
amount: parseInt(parseFloat(this.total) * 100000000), // convert to sats
token: config.tokens['BTC'],
recipientId: parseInt(this.recipientId),
recipientId: this.contributorId,
title: `Expenses covered by ${contributor.name}`,
description: this.description,
url: this.url,
Expand Down
8 changes: 5 additions & 3 deletions app/components/add-reimbursement/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<label>
<p class="label">Contributor:</p>
<p>
<select required {{on "change" this.updateContributor}}>
<option value="" selected disabled hidden></option>
<select id="contributor" required {{on "change" this.updateContributor}}>
{{#each this.contributors as |contributor|}}
<option value={{contributor.id}} selected={{eq this.contributorId contributor.id}}>{{contributor.name}}</option>
{{/each}}
Expand All @@ -15,6 +14,7 @@
<p class="label">Total amount (BTC):</p>
<p>
<Input @type="text"
@name="total-btc"
@placeholder="0.0015"
@value={{this.total}}
@required={{true}}
Expand Down Expand Up @@ -50,7 +50,9 @@

<p class="actions">
<button {{on "click" this.showExpenseForm}}
class="green small" type="button">+ Add another item</button>
id="add-another-item" class="green small" type="button">
+ Add another item
</button>
</p>
{{else}}
<p>No line items yet.</p>
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/budget.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { action } from '@ember/object';

export default class BudgetController extends Controller {
@service kredits;
@service router;

@alias('kredits.reimbursementsUnconfirmed') reimbursementsUnconfirmed;
@alias('kredits.reimbursementsConfirmed') reimbursementsConfirmed;
@alias('kredits.currentUserIsCore') currentUserIsCore;

@action
addReimbursement () {
if (!this.kredits.currentUser) {
window.alert('You need to connect your RSK account first.');
return false;
}
if (!this.kredits.currentUserIsCore) {
window.alert('Only core contributors can submit reimbursements.');
return false;
}
this.router.transitionTo('reimbursements.new');
}
}
28 changes: 10 additions & 18 deletions app/templates/budget.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
<main id="budget">

<div id="aside">
<!-- <section id="main&#45;nav"> -->
<!-- <header> -->
<!-- <h2>Budget</h2> -->
<!-- </header> -->
<!-- <div class="content"> -->
<!-- <ul> -->
<!-- <li> -->
<!-- <LinkTo @route="budget.expenses">Expenses</LinkTo> -->
<!-- </li> -->
<!-- <li> -->
<!-- <a href="#">Rewards</a> -->
<!-- </li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- </section> -->

<section id="funds">
<header>
<h2>Community funds</h2>
Expand All @@ -33,7 +17,11 @@
<header class="with-nav">
<h2>Proposed Reimbursements</h2>
<nav>
<LinkTo @route="reimbursements.new" @title="Submit a reimbursement" class="button small green">add</LinkTo>
<button type="button" class="button small green"
title="Submit a reimbursement"
{{on "click" this.addReimbursement}}>
add
</button>
</nav>
</header>
<div class="content">
Expand All @@ -47,7 +35,11 @@
<header class="with-nav">
<h2>Confirmed Reimbursements</h2>
<nav>
<LinkTo @route="reimbursements.new" @title="Submit a reimbursement" class="button small green">add</LinkTo>
<button type="button" class="button small green"
title="Submit a reimbursement"
{{on "click" this.addReimbursement}}>
add
</button>
</nav>
</header>
<div class="content">
Expand Down
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 48 additions & 3 deletions tests/integration/components/add-reimbursement/component-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
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';

module('Integration | Component | add-reimbursement', function(hooks) {
setupRenderingTest(hooks);

test('it works', async function(assert) {
hooks.beforeEach(function() {
let kredits = this.owner.lookup('service:kredits');
kredits.set('contributors', contributors);
kredits.set('currentUser', contributors.findBy('id', 3));
});

test('Contributor select menu', async function(assert) {
await render(hbs`<AddReimbursement />`);

assert.equal(this.element.querySelectorAll('select#contributor option').length, contributors.length,
'contains correct amount of items');

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`<AddReimbursement />`);
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');
});
});
Loading