-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from 67P/bugfix/220-reimbursement_sums
Reimbursement form fixes and improvements
- Loading branch information
Showing
6 changed files
with
98 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 48 additions & 3 deletions
51
tests/integration/components/add-reimbursement/component-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |