Skip to content

Commit

Permalink
Fixed CardTransaction test
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Dec 1, 2017
1 parent 9105bf4 commit 9f9bcb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
20 changes: 3 additions & 17 deletions app/src/renderer/components/wallet/CardTransaction.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<template lang='pug'>
.card-transaction
.key-value(v-for='coin in coins')
.value(:class='sign(coin.amount * (sent ? -1 : 1))') {{ coin.amount }}
.value(:class='sent ? "negative" : "positive"') {{ coin.amount }}
.key {{ coin.denom.toUpperCase() }}
.date {{ date }}
</template>

<script>
import { mapGetters } from 'vuex'
import dateUnixAgo from 'scripts/dateUnixAgo'
export default {
computed: {
...mapGetters([ 'wallet' ]),
// TODO: sum relevant inputs/outputs
sent () {
return this.transactionValue.tx.inputs[0].sender === this.wallet.key.address
},
received () {
return this.transactionValue.tx.outputs[0].receiver === this.wallet.key.address
return this.transactionValue.tx.inputs[0].sender === this.address
},
coins () {
return this.transactionValue.tx.inputs[0].coins
Expand All @@ -26,16 +21,7 @@ export default {
return dateUnixAgo(this.transactionValue.time)
}
},
methods: {
sign (num) {
if (num > 0) {
return 'positive'
} else if (num < 0) {
return 'negative'
}
}
},
props: ['transaction-value']
props: ['transaction-value', 'address']
}
</script>

Expand Down
5 changes: 3 additions & 2 deletions app/src/renderer/components/wallet/PageTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ page(title='Transactions')

card-transaction(
v-for="i in filteredTransactions"
:transaction-value="i")
:transaction-value="i"
:address="wallet.key.address")
data-empty-tx(v-if='filteredTransactions.length === 0')
</template>

Expand Down Expand Up @@ -40,7 +41,7 @@ export default {
ToolBar
},
computed: {
...mapGetters(['filters', 'transactions']),
...mapGetters(['filters', 'transactions', 'wallet']),
filteredTransactions () {
return this.transactions
// TODO: restore searchability? (what part of the tx are we searching?)
Expand Down
35 changes: 16 additions & 19 deletions test/unit/specs/CardTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ import { shallow } from 'vue-test-utils'
import CardTransaction from 'renderer/components/wallet/CardTransaction'

describe('CardTransaction', () => {
let wrapper, num, result
let wrapper
let propsData = {
transactionValue: {
tx: {
inputs: [
{
coins: {
coins: [{
denom: 'jbcoins',
amount: 1234
}
}],
sender: 'otherAddress'
}
],
outputs: [
{
coins: [{
denom: 'jbcoins',
amount: 1234
}],
recipient: 'myAddress'
}
]
},
time: new Date()
}
time: Date.now()
},
address: 'myAddress'
}

beforeEach(() => {
Expand All @@ -28,18 +39,4 @@ describe('CardTransaction', () => {
it('has the expected html structure', () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})

it('returns negative as a string for numbers below zero', () => {
num = -1
result = wrapper.vm.sign(num)

expect(result).toEqual('negative')
})

it('returns positive as a string for numbers above zero', () => {
num = 1
result = wrapper.vm.sign(num)

expect(result).toEqual('positive')
})
})

0 comments on commit 9f9bcb9

Please sign in to comment.