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

poquito requests #2289

Merged
merged 24 commits into from
Mar 20, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests
Federico Kunze committed Mar 17, 2019
commit 0455579e7038e94057b9058bfdd74e03b3ca1676
6 changes: 5 additions & 1 deletion app/src/renderer/components/staking/TabMyDelegations.vue
Original file line number Diff line number Diff line change
@@ -130,7 +130,11 @@ export default {
immediate: true,
handler(newHeader) {
const waitTenBlocks = Number(newHeader.height) % 20 === 0
if (waitTenBlocks && this.yourValidators) {
if (
waitTenBlocks &&
this.yourValidators &&
this.yourValidators.length > 0
) {
this.$store.dispatch(
`getRewardsFromAllValidators`,
this.yourValidators
6 changes: 5 additions & 1 deletion app/src/renderer/components/staking/TabValidators.vue
Original file line number Diff line number Diff line change
@@ -55,7 +55,11 @@ export default {
immediate: true,
handler(newHeader) {
const waitTenBlocks = Number(newHeader.height) % 20 === 0
if (waitTenBlocks && this.yourValidators) {
if (
waitTenBlocks &&
this.yourValidators &&
this.yourValidators.length > 0
) {
this.$store.dispatch(
`getRewardsFromAllValidators`,
this.yourValidators
39 changes: 39 additions & 0 deletions test/unit/specs/components/common/TmBalance.spec.js
Original file line number Diff line number Diff line change
@@ -53,4 +53,43 @@ describe(`TmBalance`, () => {
TmBalance.methods.onWithdrawal.call({ $refs })
expect($refs.modalWithdrawAllRewards.open).toHaveBeenCalled()
})

describe(`update balance and total rewards on new blocks`, () => {
describe(`shouldn't update`, () => {
it(`if user is not signed in `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: false }
const newHeader = { height: `10` }
TmBalance.watch.lastHeader.handler.call(
{ session, $store },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(`getTotalRewards`)
expect($store.dispatch).not.toHaveBeenCalledWith(`queryWalletBalances`)
})

it(`if hasn't waited for 10 blocks `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
const newHeader = { height: `12` }
TmBalance.watch.lastHeader.handler.call(
{ session, $store },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(`getTotalRewards`)
expect($store.dispatch).not.toHaveBeenCalledWith(`queryWalletBalances`)
})
})

describe(`should update balance and rewards `, () => {
it(`if user is signed in and wait for 10 blocks`, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
const newHeader = { height: `10` }
TmBalance.watch.lastHeader.handler.call(
{ session, $store },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(`getTotalRewards`)
expect($store.dispatch).toHaveBeenCalledWith(`queryWalletBalances`)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -60,4 +60,42 @@ describe(`ModalWithdrawAllRewards`, () => {
)
})
})

describe(`update total rewards on new blocks`, () => {
describe(`shouldn't update total `, () => {
it(`if user is not signed in `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: false }
const $refs = { actionModal: { show: true } }
ModalWithdrawAllRewards.watch.lastHeader.handler.call(
{ session, $store, $refs })
expect($store.dispatch).not.toHaveBeenCalledWith(`getTotalRewards`)
})

it(`if user is not on watching the modal `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
let $refs = {}
ModalWithdrawAllRewards.watch.lastHeader.handler.call(
{ session, $store, $refs })
expect($store.dispatch).not.toHaveBeenCalledWith(`getTotalRewards`)

$refs = { actionModal: { show: false } }
ModalWithdrawAllRewards.watch.lastHeader.handler.call(
{ session, $store, $refs })
expect($store.dispatch).not.toHaveBeenCalledWith(`getTotalRewards`)
})
})

describe(`should update total rewards `, () => {
it(`if user is signed in and is watching the modal `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
const $refs = { actionModal: { show: true } }
ModalWithdrawAllRewards.watch.lastHeader.handler.call(
{ session, $store, $refs })
expect($store.dispatch).toHaveBeenCalledWith(`getTotalRewards`)
})
})
})
})
40 changes: 23 additions & 17 deletions test/unit/specs/components/staking/PageValidator.spec.js
Original file line number Diff line number Diff line change
@@ -285,7 +285,6 @@ describe(`PageValidator`, () => {

describe(`update rewards on new blocks`, () => {
describe(`shouldn't update`, () => {

it(`if user is not signed in `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: false }
@@ -303,6 +302,7 @@ describe(`PageValidator`, () => {
$route.params.validator
)
})

it(`if hasn't waited for 20 blocks `, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
@@ -358,22 +358,28 @@ describe(`PageValidator`, () => {
})
})

it(`should update rewards if waited for 20 blocks`, () => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
const $route = {
params: { validator: `cosmos1address` },
name: `validator`
}
const myDelegation = `1 atom`
const newHeader = { height: `20` }
PageValidator.watch.lastHeader.handler.call(
{ session, $store, $route, myDelegation },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromValidator`,
$route.params.validator
)
describe(`should update rewards `, () => {
it(
`if waited for 20 blocks, ` +
`user has signed in, ` +
`has delegations and is watching the validator page`,
() => {
const $store = { dispatch: jest.fn() }
const session = { signedIn: true }
const $route = {
params: { validator: `cosmos1address` },
name: `validator`
}
const myDelegation = `1 atom`
const newHeader = { height: `20` }
PageValidator.watch.lastHeader.handler.call(
{ session, $store, $route, myDelegation },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromValidator`,
$route.params.validator
)
})
})
})
})
45 changes: 45 additions & 0 deletions test/unit/specs/components/staking/TabMyDelegations.spec.js
Original file line number Diff line number Diff line change
@@ -200,5 +200,50 @@ describe(`Component: TabMyDelegations`, () => {
).toBe(false)
})
})

describe(`update rewards on new blocks`, () => {
describe(`shouldn't update`, () => {
it(`if hasn't waited for 20 blocks `, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = [{}]
const newHeader = { height: `30` }
TabMyDelegations.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})

it(`if user doesn't have any delegations `, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = []
const newHeader = { height: `40` }
TabMyDelegations.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})

describe(`should update rewards `, () => {
it(`if has waited for 20 blocks and has delegations`, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = [{}]
const newHeader = { height: `40` }
TabMyDelegations.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})
})
})
})
})
})
45 changes: 45 additions & 0 deletions test/unit/specs/components/staking/TabValidators.spec.js
Original file line number Diff line number Diff line change
@@ -172,4 +172,49 @@ describe(`TabValidators`, () => {
).toBe(false)
})
})

describe(`update rewards on new blocks`, () => {
describe(`shouldn't update`, () => {
it(`if hasn't waited for 20 blocks `, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = [{}]
const newHeader = { height: `30` }
TabValidators.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})

it(`if user doesn't have any delegations `, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = []
const newHeader = { height: `40` }
TabValidators.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).not.toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})

describe(`should update rewards `, () => {
it(`if has waited for 20 blocks and has delegations`, () => {
const $store = { dispatch: jest.fn() }
const yourValidators = [{}]
const newHeader = { height: `40` }
TabValidators.watch.lastHeader.handler.call(
{ $store, yourValidators },
newHeader)
expect($store.dispatch).toHaveBeenCalledWith(
`getRewardsFromAllValidators`,
yourValidators
)
})
})
})
})
})