-
-
- Tally Parameters
-
-
- info_outline
-
-
-
+
+
+ -
+
+ Threshold
+
+
+ info_outline
+
+
+
+ -
+
+ 50 %
+
+
+
+
+
+ -
+
+ Veto
+
+
+ info_outline
+
+
+
+ -
+
+ 33.4 %
+
+
+
+
+
+
-
-
- -
-
- Threshold
-
-
- info_outline
-
-
-
- -
-
- 50 %
-
-
-
+
+
+ Governance Penalty
+
+
+ info_outline
+
+
-
- -
-
- Veto
-
-
- info_outline
-
-
-
- -
-
- 33.4 %
-
-
-
-
+
+
+ 0.0100000000
+
+
+
-
-
- -
-
- Governance Penalty
-
-
- info_outline
-
-
-
- -
-
- 0.0100000000
-
-
-
-
+
+
+ Quorum
+
+
+ info_outline
+
+
+
+
+
+ 33.4 %
+
+
+
-
-
-
- Voting Parameters
-
-
- info_outline
-
-
-
+
-
-
- -
-
- Voting Period
-
-
- info_outline
-
-
-
- -
-
- 1 days
-
-
-
-
-
-
+
+
+ Voting Period
+
+
+ info_outline
+
+
+
+
+
+ 1 days
+
+
+
+
+
diff --git a/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap b/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap
index 938fa96c98..f37fd9e027 100644
--- a/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap
+++ b/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap
@@ -10,57 +10,87 @@ exports[`TabProposals has the expected html structure 1`] = `
class="panel-sort-container"
>
Title
+
+ arrow_drop_up
+
|
- Proposal id
+ Proposal Id
+
+ arrow_drop_up
+
|
Yes
+
+ arrow_drop_up
+
|
No
+
+ arrow_drop_up
+
|
No with Veto
+
+ arrow_drop_up
+
|
Abstain
+
+ arrow_drop_up
+
|
diff --git a/test/unit/specs/components/governance/__snapshots__/TableProposals.spec.js.snap b/test/unit/specs/components/governance/__snapshots__/TableProposals.spec.js.snap
index 6b74b9193e..861ac5916c 100644
--- a/test/unit/specs/components/governance/__snapshots__/TableProposals.spec.js.snap
+++ b/test/unit/specs/components/governance/__snapshots__/TableProposals.spec.js.snap
@@ -10,57 +10,87 @@ exports[`TableProposals has the expected html structure 1`] = `
class="panel-sort-container"
>
Title
+
+ arrow_drop_up
+
|
- Proposal id
+ Proposal Id
+
+ arrow_drop_up
+
|
Yes
+
+ arrow_drop_up
+
|
No
+
+ arrow_drop_up
+
|
No with Veto
+
+ arrow_drop_up
+
|
Abstain
+
+ arrow_drop_up
+
|
@@ -316,57 +346,87 @@ exports[`TableProposals should filter the proposals 1`] = `
class="panel-sort-container"
>
Title
+
+ arrow_drop_up
+
|
- Proposal id
+ Proposal Id
+
+ arrow_drop_up
+
|
Yes
+
+ arrow_drop_up
+
|
No
+
+ arrow_drop_up
+
|
No with Veto
+
+ arrow_drop_up
+
|
Abstain
+
+ arrow_drop_up
+
|
diff --git a/test/unit/specs/components/network/PageBlock.spec.js b/test/unit/specs/components/network/PageBlock.spec.js
new file mode 100644
index 0000000000..11f28360ee
--- /dev/null
+++ b/test/unit/specs/components/network/PageBlock.spec.js
@@ -0,0 +1,77 @@
+import { shallowMount, createLocalVue } from "@vue/test-utils"
+import PageBlock from "renderer/components/network/PageBlock"
+
+const localVue = createLocalVue()
+localVue.directive(`tooltip`, () => {})
+
+describe(`PageBlock`, () => {
+ let wrapper
+
+ beforeEach(() => {
+ const getters = {
+ connected: true,
+ block: {
+ block_meta: {
+ block_id: {
+ hash: `ABCD1234`
+ }
+ },
+ block: {
+ data: {
+ txs: `txs`
+ },
+ header: {
+ height: `100`,
+ num_txs: 1200,
+ proposer_address: `ABCDEFG123456HIJKLMNOP`,
+ time: Date.now()
+ },
+ evidence: {
+ evidence: `evidence`
+ },
+ last_commit: {
+ precommits: [
+ {
+ validator_address: `validator address`,
+ timestamp: Date.now(),
+ round: 0
+ }
+ ]
+ }
+ }
+ }
+ }
+
+ wrapper = shallowMount(PageBlock, {
+ localVue,
+ mocks: {
+ $store: {
+ getters,
+ dispatch: jest.fn()
+ },
+ $route: {
+ params: { height: `100` }
+ }
+ },
+ stubs: [`router-link`]
+ })
+ })
+
+ it(`has the expected html structure`, () => {
+ expect(wrapper.vm.$el).toMatchSnapshot()
+ })
+
+ it(`sets properties for the block table`, () => {
+ expect(wrapper.vm.properties).toEqual([
+ {
+ title: `Proposer`
+ },
+ {
+ title: `Time`
+ },
+ {
+ title: `Round`
+ }
+ ])
+ })
+})
diff --git a/test/unit/specs/components/network/PageNetwork.spec.js b/test/unit/specs/components/network/PageNetwork.spec.js
new file mode 100644
index 0000000000..080163dfed
--- /dev/null
+++ b/test/unit/specs/components/network/PageNetwork.spec.js
@@ -0,0 +1,117 @@
+import { shallowMount, createLocalVue } from "@vue/test-utils"
+import PageNetwork from "renderer/components/network/PageNetwork"
+
+const localVue = createLocalVue()
+localVue.directive(`tooltip`, () => {})
+
+describe(`PageNetwork`, () => {
+ let wrapper, $store
+
+ beforeEach(() => {
+ $store = {
+ getters: {
+ connected: true,
+ lastHeader: {
+ chain_id: `gaia-20k`,
+ proposer_address: `EFH47FH723HDHSH`,
+ height: `6001`,
+ total_txs: `108`,
+ time: Date.now()
+ },
+ delegates: {
+ delegates: [
+ {
+ a: `b`,
+ c: `d`
+ }
+ ]
+ },
+ config: {
+ devMode: true
+ },
+ pool: {
+ pool: {
+ bonded_tokens: 125,
+ loose_tokens: 10
+ }
+ },
+ bondDenom: `stake`,
+ blocks: [
+ {
+ header: {
+ height: `100`,
+ num_txs: 1200,
+ proposer_address: `ABCDEFG123456HIJKLMNOP`
+ }
+ },
+ {
+ header: {
+ height: `101`,
+ num_txs: 405,
+ proposer_address: `ZYXCRS123456HIJKLMNOPQ`
+ }
+ }
+ ]
+ }
+ }
+
+ wrapper = shallowMount(PageNetwork, {
+ localVue,
+ mocks: {
+ $store
+ },
+ stubs: [`router-link`]
+ })
+ })
+
+ it(`has the expected html structure`, () => {
+ expect(wrapper.vm.$el).toMatchSnapshot()
+ })
+
+ it(`sets the status correctly`, () => {
+ expect(wrapper.vm.status).toEqual({
+ color: `green`,
+ message: `Network is up and running`
+ })
+
+ $store = {
+ getters: {
+ connected: false
+ }
+ }
+
+ wrapper = shallowMount(PageNetwork, {
+ localVue,
+ mocks: {
+ $store
+ },
+ stubs: [`router-link`]
+ })
+
+ expect(wrapper.vm.status).toEqual({
+ color: `red`,
+ message: `Network is down`
+ })
+ })
+
+ it(`sets last block to something human readable`, () => {
+ expect(wrapper.vm.lastBlock).toEqual(`a few seconds ago`)
+ })
+
+ it(`sets properties for the block table`, () => {
+ expect(wrapper.vm.properties).toEqual([
+ {
+ title: `Block Number`,
+ value: `block_number`,
+ tooltip: `Block Number`,
+ class: `blockNumber`
+ },
+ {
+ title: `Transactions`,
+ value: `transactions`,
+ tooltip: `Number of transactions per block`,
+ class: `transactions`
+ }
+ ])
+ })
+})
diff --git a/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap b/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap
new file mode 100644
index 0000000000..187740ffba
--- /dev/null
+++ b/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap
@@ -0,0 +1,105 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`PageBlock has the expected html structure 1`] = `
+
+
+
+
+
+
+
+ -
+ Transactions
+
+
+ -
+ txs
+
+
+
+
+
+
+
+
+
+
+ -
+ Evidence
+
+
+ -
+ evidence
+
+
+
+
+
+
+`;
diff --git a/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap b/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap
new file mode 100644
index 0000000000..39cd3a48f7
--- /dev/null
+++ b/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap
@@ -0,0 +1,176 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`PageNetwork has the expected html structure 1`] = `
+
+
+
+
+
+
+
+
+
+
+
+
+ #100
+
+ |
+
+
+ 1200
+ |
+
+
+
+
+ #101
+
+ |
+
+
+ 405
+ |
+
+
+
+
+`;
diff --git a/test/unit/specs/components/staking/DelegationModal.spec.js b/test/unit/specs/components/staking/DelegationModal.spec.js
index 4f8e9567e0..1e8df3080c 100644
--- a/test/unit/specs/components/staking/DelegationModal.spec.js
+++ b/test/unit/specs/components/staking/DelegationModal.spec.js
@@ -7,16 +7,17 @@ import lcdClientMock from "renderer/connectors/lcdClientMock.js"
describe(`DelegationModal`, () => {
let wrapper, store
- let { stakingParameters } = lcdClientMock.state
- let { mount, localVue } = setup()
+ const { stakingParameters } = lcdClientMock.state
+ const { mount, localVue } = setup()
localVue.use(Vuelidate)
localVue.directive(`tooltip`, () => {})
localVue.directive(`focus`, () => {})
beforeEach(() => {
- let instance = mount(DelegationModal, {
+ const instance = mount(DelegationModal, {
localVue,
propsData: {
+ validator: lcdClientMock.state.candidates[0],
fromOptions: [
{
address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`,
@@ -25,7 +26,7 @@ describe(`DelegationModal`, () => {
value: 0
},
{
- address: `cosmos126ayk3hse5zvk9gxfmpsjr9565ef72pv9g20yx`,
+ address: lcdClientMock.state.candidates[0].operator_address,
key: `Billy the Bill - cosmos…psjr9565ef72pv9g20yx`,
maximum: 23.0484375481,
value: 1
@@ -43,7 +44,14 @@ describe(`DelegationModal`, () => {
})
wrapper = instance.wrapper
store = instance.store
+
+ store.state.connection.connected = true
+ store.state.wallet.address = `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
+ store.state.delegates.delegates = lcdClientMock.state.candidates
store.commit(`setStakingParameters`, stakingParameters.parameters)
+ store.commit(`setSignIn`, true)
+
+ wrapper.vm.$refs.actionModal.open()
})
describe(`component matches snapshot`, () => {
@@ -52,106 +60,93 @@ describe(`DelegationModal`, () => {
})
})
- describe(`default values are set correctly`, () => {
- it(`the 'amount' defaults to 0`, () => {
- expect(wrapper.vm.amount).toEqual(0)
- })
-
- it(`displays the user's wallet address as the default`, () => {
- let toField = wrapper.find(`#to`)
- expect(toField).toBeDefined()
- expect(toField.element.value).toEqual(
- `cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au`
- )
- })
-
- it(`account password defaults to an empty string`, () => {
- expect(wrapper.vm.password).toEqual(``)
- })
-
- it(`password is hidden by default`, () => {
- expect(wrapper.vm.showPassword).toBe(false)
- })
+ it(`opens`, () => {
+ wrapper.vm.$refs.actionModal.open = jest.fn()
+ wrapper.vm.open()
+ expect(wrapper.vm.$refs.actionModal.open).toHaveBeenCalled()
})
- describe(`Password display`, () => {
- it(`toggles the password between text and password`, () => {
- wrapper.vm.togglePassword()
- expect(wrapper.vm.showPassword).toBe(true)
- wrapper.vm.togglePassword()
- expect(wrapper.vm.showPassword).toBe(false)
- })
- })
-
- describe(`enables or disables the Delegation button correctly`, () => {
- describe(`disables the 'Delegation' button`, () => {
+ describe(`validation`, () => {
+ describe(`fails`, () => {
it(`with default values`, () => {
- let delegationBtn = wrapper.find(`#submit-delegation`)
- expect(delegationBtn.html()).toContain(`disabled="disabled"`)
+ expect(wrapper.vm.validateForm()).toBe(false)
})
it(`if the user manually inputs a number greater than the balance`, () => {
- wrapper.setData({ amount: 142, password: `1234567890` })
- let amountField = wrapper.find(`#amount`)
-
- let delegationBtn = wrapper.find(`#submit-delegation`)
- expect(delegationBtn.html()).toContain(`disabled="disabled"`)
- let errorMessage = wrapper.find(`input#amount + div`)
- expect(errorMessage.classes()).toContain(`tm-form-msg--error`)
-
- amountField.trigger(`input`)
- expect(amountField.element.value).toBe(`100`)
- })
-
- it(`if the password field is empty`, () => {
- wrapper.setData({ amount: 10, password: `` })
- let delegationBtn = wrapper.find(`#submit-delegation`)
- expect(delegationBtn.html()).toContain(`disabled="disabled"`)
+ wrapper.setData({ amount: 142 })
+ expect(wrapper.vm.validateForm()).toBe(false)
})
})
- describe(`enables the 'Delegation' button`, () => {
- it(`if the amout is positive and the user has enough balance`, () => {
- wrapper.setData({ amount: 50, password: `1234567890` })
-
- let delegationBtn = wrapper.find(`#submit-delegation`)
- expect(delegationBtn.html()).not.toContain(`disabled="disabled"`)
+ describe(`succeeds`, () => {
+ it(`if the amount is positive and the user has enough balance`, () => {
+ wrapper.setData({ amount: 50 })
+ expect(wrapper.vm.validateForm()).toBe(true)
})
})
})
describe(`(Re)delegate`, () => {
- it(`Delegation button submits a (re)delegation and closes modal`, () => {
- wrapper.setData({ amount: 50, password: `1234567890` })
- wrapper.vm.onDelegation()
-
- expect(wrapper.emittedByOrder()).toEqual([
- {
- name: `submitDelegation`,
- args: [
- {
- amount: 50,
- from: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`,
- password: `1234567890`
- }
- ]
- },
- {
- name: `update:showDelegationModal`,
- args: [false]
- }
+ it(`submits a delegation`, async () => {
+ wrapper.vm.$store.dispatch = jest.fn()
+ wrapper.vm.$store.commit = jest.fn()
+
+ wrapper.setData({ amount: 50 })
+ await wrapper.vm.submitForm(`local`, `1234567890`)
+
+ expect(wrapper.vm.$store.dispatch.mock.calls).toEqual([
+ [
+ `submitDelegation`,
+ {
+ amount: `50`,
+ // validatorSrc: lcdClientMock.state.candidates[1],
+ // validatorDst: lcdClientMock.state.candidates[0],
+ validator_addr: `cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw`,
+ password: `1234567890`,
+ submitType: `local`
+ }
+ ]
+ ])
+
+ expect(wrapper.vm.$store.commit.mock.calls).toEqual([
+ [
+ `notify`,
+ {
+ body: `You have successfully delegated your STAKEs`,
+ title: `Successful delegation!`
+ }
+ ]
])
})
- })
- describe(`closes modal correctly`, () => {
- it(`X button emits close signal`, () => {
- wrapper.vm.close()
- expect(wrapper.emittedByOrder()).toEqual([
- {
- name: `update:showDelegationModal`,
- args: [false]
- }
+ it(`submits a redelegation`, async () => {
+ wrapper.vm.$store.dispatch = jest.fn()
+ wrapper.vm.$store.commit = jest.fn()
+
+ wrapper.setData({ amount: 50, selectedIndex: 1 })
+ await wrapper.vm.submitForm(`local`, `1234567890`)
+
+ expect(wrapper.vm.$store.dispatch.mock.calls).toEqual([
+ [
+ `submitRedelegation`,
+ {
+ amount: `50`,
+ validatorSrc: lcdClientMock.state.candidates[0],
+ validatorDst: lcdClientMock.state.candidates[0],
+ submitType: `local`,
+ password: `1234567890`
+ }
+ ]
+ ])
+
+ expect(wrapper.vm.$store.commit.mock.calls).toEqual([
+ [
+ `notify`,
+ {
+ body: `You have successfully redelegated your STAKEs`,
+ title: `Successful redelegation!`
+ }
+ ]
])
})
})
diff --git a/test/unit/specs/components/staking/LiValidator.spec.js b/test/unit/specs/components/staking/LiValidator.spec.js
index 5eee31e901..b348d041ed 100644
--- a/test/unit/specs/components/staking/LiValidator.spec.js
+++ b/test/unit/specs/components/staking/LiValidator.spec.js
@@ -4,7 +4,7 @@ import LiValidator from "renderer/components/staking/LiValidator"
describe(`LiValidator`, () => {
let wrapper, store
- let { mount } = setup()
+ const { mount } = setup()
const validator = Object.assign({}, lcdClientMock.state.candidates[1], {
commission: {
rate: `0.05`,
@@ -24,7 +24,7 @@ describe(`LiValidator`, () => {
})
beforeEach(() => {
- let instance = mount(LiValidator, {
+ const instance = mount(LiValidator, {
propsData: {
validator,
disabled: false
@@ -41,7 +41,7 @@ describe(`LiValidator`, () => {
})
it(`should calculate the validator's power ratio`, () => {
- let ratio = wrapper.vm.validator.tokens / wrapper.vm.delegates.globalPower
+ const ratio = wrapper.vm.validator.tokens / wrapper.vm.delegates.globalPower
expect(wrapper.vm.powerRatio).toBe(ratio)
})
diff --git a/test/unit/specs/components/staking/PageStaking.spec.js b/test/unit/specs/components/staking/PageStaking.spec.js
index e24f196364..e3cd67b333 100644
--- a/test/unit/specs/components/staking/PageStaking.spec.js
+++ b/test/unit/specs/components/staking/PageStaking.spec.js
@@ -2,39 +2,28 @@ import setup from "../../../helpers/vuex-setup"
import PageStaking from "renderer/components/staking/PageStaking"
import lcdClientMock from "renderer/connectors/lcdClientMock.js"
+// TODO refactor according to new unit test standard
describe(`PageStaking`, () => {
let wrapper, store
- let { stakingParameters } = lcdClientMock.state
- let { mount } = setup()
+ const { mount } = setup()
beforeEach(() => {
- let instance = mount(PageStaking)
+ const instance = mount(PageStaking, {
+ doBefore: ({ store }) => {
+ store.commit(`setSignIn`, true)
+ store.commit(`setConnected`, true)
+ store.dispatch(`updateDelegates`)
+ },
+ stubs: {
+ "tm-balance": true
+ }
+ })
wrapper = instance.wrapper
store = instance.store
-
- store.commit(`setConnected`, true)
store.state.user.address = lcdClientMock.addresses[0]
- store.dispatch(`updateDelegates`)
- store.commit(`setAtoms`, 1337)
- store.commit(`setStakingParameters`, stakingParameters.parameters)
})
- it(`has the expected html structure`, async () => {
- // somehow we need to wait one tick for the total atoms to update
- await wrapper.vm.$nextTick()
+ it(`has the expected html structure`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
-
- it(`should show the search on click`, () => {
- wrapper.find(`.tm-tool-bar i.search`).trigger(`click`)
- expect(wrapper.contains(`.tm-modal-search`)).toBe(true)
- })
-
- it(`should refresh candidates on click`, () => {
- wrapper
- .findAll(`.tm-tool-bar i`)
- .at(1)
- .trigger(`click`)
- expect(store.dispatch).toHaveBeenCalledWith(`updateDelegates`)
- })
})
diff --git a/test/unit/specs/components/staking/PageValidator.spec.js b/test/unit/specs/components/staking/PageValidator.spec.js
index 828ab0d9b7..18ed901f13 100644
--- a/test/unit/specs/components/staking/PageValidator.spec.js
+++ b/test/unit/specs/components/staking/PageValidator.spec.js
@@ -1,4 +1,3 @@
-import Delegation from "renderer/vuex/modules/delegation"
import DelegationModal from "staking/DelegationModal"
import UndelegationModal from "staking/UndelegationModal"
import TmModal from "common/TmModal"
@@ -13,11 +12,14 @@ const validator = Object.assign({}, lcdClientMock.state.candidates[0], {
rate: `0.05`,
max_rate: `0.1`,
max_change_rate: `0.005`,
- update_time: `1970-01-01T00:00:00Z`
+ update_time: Date.now() - 1
},
prev_bonded_shares: `0`,
voting_power: `10`,
- selfBond: 0.01
+ selfBond: 0.01,
+ signing_info: {
+ missed_blocks_counter: 2
+ }
})
const validatorTo = lcdClientMock.state.candidates[1]
@@ -34,10 +36,13 @@ const getterValues = {
committedDelegations: {
[lcdClientMock.validators[0]]: 0
},
+ lastHeader: {
+ height: 500
+ },
keybase: `keybase`,
- oldBondedAtoms: 50,
- totalAtoms: 100,
- user: { atoms: 42 },
+ liquidAtoms: 1337,
+ oldBondedAtoms: 100,
+ totalAtoms: 1437,
wallet: { address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9` },
connected: true,
lastPage: null,
@@ -45,18 +50,20 @@ const getterValues = {
bondDenom: stakingParameters.parameters.bond_denom
}
+// TODO refactor tests according to new unit test standard
describe(`PageValidator`, () => {
let wrapper, store
- let { mount } = setup()
+ const { mount } = setup()
beforeEach(() => {
- let instance = mount(PageValidator, {
+ const instance = mount(PageValidator, {
doBefore: ({ store }) => {
store.commit(`setCommittedDelegation`, {
candidateId: lcdClientMock.validators[0],
value: `123.45678`
})
store.commit(`setConnected`, true)
+ store.commit(`setSignIn`, true)
store.commit(`setDelegates`, [validator, validatorTo])
},
mocks: {
@@ -64,14 +71,33 @@ describe(`PageValidator`, () => {
params: { validator: validator.operator_address }
}
},
- getters: { bondDenom: () => stakingParameters.parameters.bond_denom }
+ stubs: {
+ "undelegation-modal": true,
+ "delegation-modal": true
+ },
+ getters: {
+ bondDenom: () => stakingParameters.parameters.bond_denom,
+ wallet: () => ({
+ address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
+ })
+ }
})
wrapper = instance.wrapper
store = instance.store
+
+ wrapper.vm.$refs.undelegationModal = { open: () => {} }
+ wrapper.vm.$refs.delegationModal = { open: () => {} }
})
- it(`has the expected html structure`, async () => {
- expect(wrapper.vm.$el).toMatchSnapshot()
+ describe(`has the expected html structure`, () => {
+ it(`if user has signed in`, async () => {
+ expect(wrapper.vm.$el).toMatchSnapshot()
+ })
+
+ it(`if user hasn't signed in`, async () => {
+ store.commit(`setSignIn`, false)
+ expect(wrapper.vm.$el).toMatchSnapshot()
+ })
})
it(`should return one delegate based on route params`, () => {
@@ -84,24 +110,47 @@ describe(`PageValidator`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
+ it(`should return the self bond based on the validator`, () => {
+ const validator = {
+ selfBond: 1
+ }
+ wrapper.setData({ validator })
+ expect(wrapper.vm.selfBond).toBe(`100.00%`)
+
+ validator.selfBond = undefined
+ wrapper.setData({ validator })
+ expect(wrapper.vm.selfBond).toBe(`0.00%`)
+ })
+
it(`shows an error if the validator couldn't be found`, () => {
- let instance = mount(PageValidator, {
+ const instance = mount(PageValidator, {
getters: {
config: () => ({ desktop: false }),
delegates: () => ({
delegates: []
}),
- bondDenom: () => stakingParameters.parameters.bond_denom
+ bondDenom: () => stakingParameters.parameters.bond_denom,
+ wallet: () => ({
+ address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
+ })
},
mocks: {
$route: {
params: { validator: validator.operator_address }
}
+ },
+ stubs: {
+ "undelegation-modal": true,
+ "delegation-modal": true
}
})
wrapper = instance.wrapper
store = instance.store
+
+ wrapper.vm.$refs.undelegationModal = { open: () => {} }
+ wrapper.vm.$refs.delegationModal = { open: () => {} }
+
expect(wrapper.vm.$el).toMatchSnapshot()
})
@@ -113,7 +162,7 @@ describe(`PageValidator`, () => {
},
ratio: 0.01
})
- expect(wrapper.find(`#page-profile__self-bond`).text()).toBe(`1.00 %`)
+ expect(wrapper.find(`#page-profile__self-bond`).text()).toBe(`1.00%`)
})
it(`should show the validator status`, () => {
@@ -237,12 +286,12 @@ describe(`PageValidator`, () => {
describe(`delegationTargetOptions`, () => {
it(`always shows wallet in the first position`, () => {
- let $store = {
+ const $store = {
commit: jest.fn(),
dispatch: jest.fn()
}
- let options = PageValidator.methods.delegationTargetOptions.call({
+ const options = PageValidator.methods.delegationTargetOptions.call({
...getterValues,
committedDelegations: {},
$store,
@@ -257,12 +306,12 @@ describe(`delegationTargetOptions`, () => {
})
it(`hides displayed validator if bonded`, () => {
- let $store = {
+ const $store = {
commit: jest.fn(),
dispatch: jest.fn()
}
- let options = PageValidator.methods.delegationTargetOptions.call({
+ const options = PageValidator.methods.delegationTargetOptions.call({
...getterValues,
committedDelegations: {
[lcdClientMock.validators[0]]: 10
@@ -288,12 +337,12 @@ describe(`delegationTargetOptions`, () => {
})
it(`shows bonded validators for redelegation options`, () => {
- let $store = {
+ const $store = {
commit: jest.fn(),
dispatch: jest.fn()
}
- let options = PageValidator.methods.delegationTargetOptions.call({
+ const options = PageValidator.methods.delegationTargetOptions.call({
...getterValues,
committedDelegations: {
[lcdClientMock.validators[0]]: 10,
@@ -325,336 +374,86 @@ describe(`delegationTargetOptions`, () => {
})
})
-describe(`onDelegation`, () => {
+describe(`Staking functions`, () => {
let wrapper, store
beforeEach(() => {
- let { mount } = setup()
+ const { mount } = setup()
- let instance = mount(PageValidator, {
+ const instance = mount(PageValidator, {
doBefore: ({ store }) => {
+ store.commit(`setSignIn`, true)
store.commit(`setCommittedDelegation`, {
candidateId: lcdClientMock.validators[0],
value: 100
})
- store.commit(`setAtoms`, 1337)
store.commit(`setConnected`, true)
+ store.commit(`setStakingParameters`, stakingParameters.parameters)
store.commit(`setDelegates`, [validator, validatorTo])
+ store.commit(`updateWalletBalance`, {
+ denom: `STAKE`,
+ amount: 1337
+ })
store.state.wallet.address = lcdClientMock.addresses[0]
+ store.commit(`setStakingParameters`, stakingParameters.parameters)
},
mocks: {
$route: {
params: { validator: validator.operator_address }
}
},
- getters: { bondDenom: () => stakingParameters.parameters.bond_denom }
+ stubs: {
+ "undelegation-modal": true,
+ "delegation-modal": true
+ },
+ getters: {
+ bondDenom: () => stakingParameters.parameters.bond_denom,
+ wallet: () => ({
+ address: `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
+ })
+ }
})
wrapper = instance.wrapper
store = instance.store
- })
-
- describe(`make sure we have enough atoms to delegate`, () => {
- it(`is enough`, () => {
- wrapper.find(`#delegation-btn`).trigger(`click`)
- expect(wrapper.contains(DelegationModal)).toEqual(true)
- })
-
- it(`is not enough`, () => {
- store.commit(`setAtoms`, 0)
-
- wrapper.find(`#delegation-btn`).trigger(`click`)
- expect(wrapper.vm.showCannotModal).toBe(true)
- expect(wrapper.contains(TmModal)).toEqual(true)
- expect(wrapper.text()).toContain(`delegate.`) // ...no atoms to delegate.
- expect(wrapper.vm.$el).toMatchSnapshot()
- wrapper.find(`#no-atoms-modal__btn`).trigger(`click`)
- expect(wrapper.vm.showCannotModal).toBe(false)
- expect(wrapper.contains(TmModal)).toEqual(false)
- expect(wrapper.text()).not.toContain(`delegate.`) // ...no atoms to delegate.
- expect(wrapper.vm.$el).toMatchSnapshot()
- })
+ wrapper.vm.$refs.undelegationModal = { open: () => {} }
+ wrapper.vm.$refs.delegationModal = { open: () => {} }
})
- describe(`submitDelegation`, () => {
- describe(`delegation`, () => {
- describe(`unit`, () => {
- it(`success`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
- const address = `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- amount: 10,
- from: address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitDelegation`,
- {
- password: `12345`,
- validator_addr: validator.operator_address,
- amount: 10
- }
- ]
- ])
- expect($store.commit.mock.calls).toEqual([
- [
- `notify`,
- {
- body: `You have successfully delegated your ${
- stakingParameters.parameters.bond_denom
- }s`,
- title: `Successful delegation!`
- }
- ]
- ])
- })
-
- it(`error`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(() => {
- throw new Error(`message`)
- }),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
- const address = `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- amount: 10000000,
- from: address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitDelegation`,
- {
- password: `12345`,
- validator_addr: validator.operator_address,
- amount: 10000000
- }
- ]
- ])
-
- expect($store.commit.mock.calls).toEqual([
- [
- `notifyError`,
- {
- body: `message`,
- title: `Error while delegating ${
- stakingParameters.parameters.bond_denom
- }s`
- }
- ]
- ])
- })
- })
-
- describe(`composition`, () => {
- it(`delegation.submitDelegation`, async () => {
- const delegation = Delegation({})
- const address = `cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9`
- const dispatch = jest.fn((type, payload) => {
- if (type === `submitDelegation`) {
- delegation.actions[type]($store, payload)
- }
- })
-
- const $store = {
- commit: jest.fn(),
- dispatch,
- rootState: getterValues,
- state: {
- committedDelegates: { [lcdClientMock.validators[0]]: 0 },
- unbondingDelegations: {},
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
- }
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- amount: 10,
- from: address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toMatchSnapshot()
- expect($store.commit.mock.calls).toMatchSnapshot()
- })
+ describe(`onDelegation`, () => {
+ describe(`make sure we have enough atoms to delegate`, () => {
+ it(`is enough`, () => {
+ wrapper.find(`#delegation-btn`).trigger(`click`)
+ expect(wrapper.contains(DelegationModal)).toEqual(true)
})
- })
- describe(`redelegation`, () => {
- describe(`unit`, () => {
- it(`success`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator: validatorTo,
- $store
- },
- {
- amount: 5,
- from: validator.operator_address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitRedelegation`,
- {
- password: `12345`,
- validatorSrc: validator,
- validatorDst: validatorTo,
- amount: 5
- }
- ]
- ])
-
- expect($store.commit.mock.calls).toEqual([
- [
- `notify`,
- {
- title: `Successful redelegation!`,
- body: `You have successfully redelegated your ${
- stakingParameters.parameters.bond_denom
- }s`
- }
- ]
- ])
+ it(`is not enough`, () => {
+ store.commit(`updateWalletBalance`, {
+ denom: `STAKE`,
+ amount: 0
})
- it(`error`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(() => {
- throw new Error(`message`)
- }),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator: validatorTo,
- $store,
- $route: {
- params: { validator: validatorTo.operator_address }
- }
- },
- {
- password: `12345`,
- amount: 5,
- from: validator.operator_address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitRedelegation`,
- {
- password: `12345`,
- validatorSrc: validator,
- validatorDst: validatorTo,
- amount: 5
- }
- ]
- ])
-
- expect($store.commit.mock.calls).toEqual([
- [
- `notifyError`,
- {
- title: `Error while redelegating ${
- stakingParameters.parameters.bond_denom
- }s`,
- body: `message`
- }
- ]
- ])
- })
- })
+ wrapper.find(`#delegation-btn`).trigger(`click`)
+ expect(wrapper.vm.showCannotModal).toBe(true)
+ expect(wrapper.contains(TmModal)).toEqual(true)
+ expect(wrapper.text()).toContain(`delegate.`) // ...no atoms to delegate.
+ expect(wrapper.vm.$el).toMatchSnapshot()
- describe(`composition`, () => {
- it(`redelegation.submitDelegation`, async () => {
- const delegation = Delegation({})
-
- const dispatch = jest.fn((type, payload) => {
- if (type === `submitDelegation`) {
- delegation.actions[type]($store, payload)
- }
- })
-
- const $store = {
- commit: jest.fn(),
- dispatch,
- getters: getterValues,
- rootState: getterValues,
- state: {
- committedDelegates: { [lcdClientMock.validators[0]]: 10 },
- unbondingDelegations: {},
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
- }
-
- await PageValidator.methods.submitDelegation.call(
- {
- ...getterValues,
- validator: validatorTo,
- $store
- },
- {
- password: `12345`,
- amount: 5,
- from: validator.operator_address,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toMatchSnapshot()
- expect($store.commit.mock.calls).toMatchSnapshot()
- })
+ wrapper.find(`#no-atoms-modal__btn`).trigger(`click`)
+ expect(wrapper.vm.showCannotModal).toBe(false)
+ expect(wrapper.contains(TmModal)).toEqual(false)
+ expect(wrapper.text()).not.toContain(`delegate.`) // ...no atoms to delegate.
+ expect(wrapper.vm.$el).toMatchSnapshot()
})
})
})
- describe(`onUnstake`, () => {
+ describe(`onUndelegation`, () => {
describe(`make sure there are enough atoms to unstake`, () => {
+ beforeEach(() => {
+ store.commit(`setSignIn`, true)
+ })
+
it(`is enough`, () => {
store.commit(`setCommittedDelegation`, {
candidateId: lcdClientMock.validators[0],
@@ -663,11 +462,10 @@ describe(`onDelegation`, () => {
wrapper.find(`#undelegation-btn`).trigger(`click`)
expect(wrapper.vm.myBond.isGreaterThan(0)).toBe(true)
- expect(wrapper.vm.showUndelegationModal).toBe(true)
expect(wrapper.contains(UndelegationModal)).toEqual(true)
})
- it(`is not enough`, () => {
+ it(`is not enough`, async () => {
store.commit(`setCommittedDelegation`, {
candidateId: lcdClientMock.validators[0],
value: 0
@@ -684,136 +482,5 @@ describe(`onDelegation`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
})
-
- describe(`submitUndelegation`, () => {
- describe(`unit`, () => {
- it(`success`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
-
- await PageValidator.methods.submitUndelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- amount: 10,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitUnbondingDelegation`,
- {
- password: `12345`,
- amount: -10,
- validator
- }
- ]
- ])
-
- expect($store.commit.mock.calls).toEqual([
- [
- `notify`,
- {
- body: `You have successfully undelegated 10 ${
- stakingParameters.parameters.bond_denom
- }s.`,
- title: `Successful undelegation!`
- }
- ]
- ])
- })
-
- it(`error`, async () => {
- let $store = {
- commit: jest.fn(),
- dispatch: jest.fn(() => {
- throw new Error(`message`)
- }),
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
-
- await PageValidator.methods.submitUndelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- amount: 10,
- password: `12345`
- }
- )
-
- expect($store.dispatch.mock.calls).toEqual([
- [
- `submitUnbondingDelegation`,
- {
- password: `12345`,
- amount: -10,
- validator
- }
- ]
- ])
-
- expect($store.commit.mock.calls).toEqual([
- [
- `notifyError`,
- {
- body: `message`,
- title: `Error while undelegating ${
- stakingParameters.parameters.bond_denom
- }s`
- }
- ]
- ])
- })
- })
-
- describe(`composition`, () => {
- it(`submits a successful undelegation`, async () => {
- const delegation = Delegation({})
-
- const dispatch = jest.fn((type, payload) => {
- if (type === `submitDelegation`) {
- delegation.actions[type]($store, payload)
- }
- })
-
- const $store = {
- commit: jest.fn(),
- dispatch,
- getters: getterValues,
- rootState: getterValues,
- state: {
- committedDelegates: { [lcdClientMock.validators[0]]: 10 },
- unbondingDelegations: {},
- getters: { bondDenom: stakingParameters.parameters.bond_denom }
- }
- }
-
- await PageValidator.methods.submitUndelegation.call(
- {
- ...getterValues,
- validator,
- $store
- },
- {
- password: `12345`,
- amount: 10
- }
- )
-
- expect($store.dispatch.mock.calls).toMatchSnapshot()
- expect($store.commit.mock.calls).toMatchSnapshot()
- })
- })
- })
})
})
diff --git a/test/unit/specs/components/staking/PanelSort.spec.js b/test/unit/specs/components/staking/PanelSort.spec.js
index d49e4f3ea8..125639ba3e 100644
--- a/test/unit/specs/components/staking/PanelSort.spec.js
+++ b/test/unit/specs/components/staking/PanelSort.spec.js
@@ -3,10 +3,10 @@ import PanelSort from "renderer/components/staking/PanelSort"
describe(`PanelSort`, () => {
let wrapper
- let instance = setup()
+ const instance = setup()
beforeEach(() => {
- let test = instance.mount(PanelSort, {
+ const test = instance.mount(PanelSort, {
propsData: {
sort: {
order: `asc`
@@ -31,8 +31,8 @@ describe(`PanelSort`, () => {
})
it(`should show an arrow according to ordering`, () => {
- let firstCol = wrapper.vm.$el.querySelector(`.sort-by`)
- let link = wrapper.vm.$el.querySelector(`.sort-by-link`)
+ const firstCol = wrapper.vm.$el.querySelector(`.sort-by`)
+ const link = wrapper.vm.$el.querySelector(`.sort-by-link`)
expect(firstCol.className.split(` `)).not.toContain(`asc`)
expect(firstCol.className.split(` `)).not.toContain(`desc`)
link.click()
@@ -47,10 +47,10 @@ describe(`PanelSort`, () => {
})
it(`should only sort one col actively`, () => {
- let firstCol = wrapper.vm.$el.querySelectorAll(`.sort-by`)[0]
- let secondCol = wrapper.vm.$el.querySelectorAll(`.sort-by`)[1]
- let firstLink = wrapper.vm.$el.querySelectorAll(`.sort-by-link`)[0]
- let secondLink = wrapper.vm.$el.querySelectorAll(`.sort-by-link`)[1]
+ const firstCol = wrapper.vm.$el.querySelectorAll(`.sort-by`)[0]
+ const secondCol = wrapper.vm.$el.querySelectorAll(`.sort-by`)[1]
+ const firstLink = wrapper.vm.$el.querySelectorAll(`.sort-by-link`)[0]
+ const secondLink = wrapper.vm.$el.querySelectorAll(`.sort-by-link`)[1]
firstLink.click()
secondLink.click()
expect(firstCol.className.split(` `)).not.toContain(`asc`)
diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js
index 9dd43877ed..f4b6bdb013 100644
--- a/test/unit/specs/components/staking/TabMyDelegations.spec.js
+++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js
@@ -12,11 +12,11 @@ const unbondingTransactions = lcdClientMock.state.txs.slice(5).map(t => {
})
describe(`Component: TabMyDelegations`, () => {
- let { mount } = setup()
+ const { mount } = setup()
const { stakingParameters } = lcdClientMock.state
it(`should show committed validators`, () => {
- let instance = mount(TabMyDelegations, {
+ const instance = mount(TabMyDelegations, {
getters: {
committedDelegations: () => ({
[delegates[0].operator_address]: 42
@@ -41,7 +41,7 @@ describe(`Component: TabMyDelegations`, () => {
it(`should show unbonding validators and the current committed validator`, () => {
const address = delegates[0].operator_address
- let instance = mount(TabMyDelegations, {
+ const instance = mount(TabMyDelegations, {
getters: {
// We decided that is should not be possible to undelegate from something that is not committed
committedDelegations: () => ({
@@ -54,7 +54,7 @@ describe(`Component: TabMyDelegations`, () => {
unbondingDelegations: {
[address]: {
creation_height: `170`,
- min_time: new Date().toISOString()
+ min_time: new Date(Date.now()).toISOString()
}
},
loaded: true
@@ -65,12 +65,12 @@ describe(`Component: TabMyDelegations`, () => {
}
})
- expect(instance.wrapper.html()).toContain(`Unbonding transactions`)
+ expect(instance.wrapper.html()).toContain(`Pending Undelegations`)
expect(instance.wrapper.vm.$el).toMatchSnapshot()
})
it(`should show a message if not staked yet to any validator`, () => {
- let instance = mount(TabMyDelegations, {
+ const instance = mount(TabMyDelegations, {
getters: {
committedDelegations: () => ({}),
delegates: () => ({
@@ -89,7 +89,7 @@ describe(`Component: TabMyDelegations`, () => {
})
it(`should show a message if not still connecting to a node`, () => {
- let instance = mount(TabMyDelegations, {
+ const instance = mount(TabMyDelegations, {
getters: {
committedDelegations: () => ({}),
delegates: () => ({
@@ -111,7 +111,7 @@ describe(`Component: TabMyDelegations`, () => {
})
it(`should show a message if not still loading delegations`, () => {
- let instance = mount(TabMyDelegations, {
+ const instance = mount(TabMyDelegations, {
getters: {
committedDelegations: () => ({}),
delegates: () => ({
diff --git a/test/unit/specs/components/staking/TabParameters.spec.js b/test/unit/specs/components/staking/TabParameters.spec.js
index b6bef6898e..462fc5e273 100644
--- a/test/unit/specs/components/staking/TabParameters.spec.js
+++ b/test/unit/specs/components/staking/TabParameters.spec.js
@@ -2,14 +2,14 @@ import setup from "../../../helpers/vuex-setup"
import TabParameters from "renderer/components/staking/TabParameters"
import lcdClientMock from "renderer/connectors/lcdClientMock.js"
-let { pool, stakingParameters } = lcdClientMock.state
+const { stakingParameters } = lcdClientMock.state
describe(`TabParameters`, () => {
let wrapper, store
- let { mount } = setup()
+ const { mount } = setup()
beforeEach(() => {
- let instance = mount(TabParameters, {
+ const instance = mount(TabParameters, {
stubs: {
"tm-data-connecting": true,
"tm-data-loading": true
@@ -18,21 +18,18 @@ describe(`TabParameters`, () => {
wrapper = instance.wrapper
store = instance.store
store.commit(`setConnected`, true)
- store.commit(`setPool`, pool)
store.commit(`setStakingParameters`, stakingParameters.parameters)
store.state.stakingParameters.loaded = true
- store.state.pool.loaded = true
})
it(`has the expected html structure`, async () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
- it(`shows the staking parameters and pool`, () => {
+ it(`shows the staking parameters`, () => {
expect(store.state.stakingParameters.parameters).toEqual(
stakingParameters.parameters
)
- expect(store.state.pool.pool).toEqual(pool)
})
it(`displays unbonding period in days`, () => {
@@ -47,25 +44,23 @@ describe(`TabParameters`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
store.state.stakingParameters.loaded = true
- store.state.pool.loaded = false
+
expect(wrapper.vm.$el).toMatchSnapshot()
- expect(wrapper.contains(`tm-data-connecting-stub`)).toBe(true)
+ expect(wrapper.contains(`tm-data-connecting-stub`)).toBe(false)
})
it(`displays a message if loading`, () => {
store.commit(`setConnected`, true)
store.state.stakingParameters.loaded = false
store.state.stakingParameters.loading = true
- store.state.pool.loaded = true
- store.state.pool.loading = true
+
expect(wrapper.vm.$el).toMatchSnapshot()
expect(wrapper.contains(`tm-data-loading-stub`)).toBe(true)
store.state.stakingParameters.loaded = true
store.state.stakingParameters.loading = false
- store.state.pool.loaded = false
- store.state.pool.loading = true
+
expect(wrapper.vm.$el).toMatchSnapshot()
- expect(wrapper.contains(`tm-data-loading-stub`)).toBe(true)
+ expect(wrapper.contains(`tm-data-loading-stub`)).toBe(false)
})
})
diff --git a/test/unit/specs/components/staking/TabValidators.spec.js b/test/unit/specs/components/staking/TabValidators.spec.js
index 2aba0c7d8b..6bf4b9fbbe 100644
--- a/test/unit/specs/components/staking/TabValidators.spec.js
+++ b/test/unit/specs/components/staking/TabValidators.spec.js
@@ -2,15 +2,15 @@ import setup from "../../../helpers/vuex-setup"
import TabValidators from "renderer/components/staking/TabValidators"
import lcdClientMock from "renderer/connectors/lcdClientMock.js"
-let { stakingParameters } = lcdClientMock.state
+const { stakingParameters } = lcdClientMock.state
describe(`TabValidators`, () => {
let wrapper
let store
- let { mount } = setup()
+ const { mount } = setup()
beforeEach(async () => {
- let instance = mount(TabValidators, {
+ const instance = mount(TabValidators, {
doBefore: ({ store }) => {
store.commit(`setConnected`, true)
},
diff --git a/test/unit/specs/components/staking/TableValidators.spec.js b/test/unit/specs/components/staking/TableValidators.spec.js
index 253ca892dc..cfc02fbcd3 100644
--- a/test/unit/specs/components/staking/TableValidators.spec.js
+++ b/test/unit/specs/components/staking/TableValidators.spec.js
@@ -2,24 +2,30 @@ import setup from "../../../helpers/vuex-setup"
import TableValidators from "renderer/components/staking/TableValidators"
import lcdClientMock from "renderer/connectors/lcdClientMock.js"
-let { stakingParameters } = lcdClientMock.state
+const { stakingParameters } = lcdClientMock.state
describe(`TableValidators`, () => {
let wrapper, store
- let { mount } = setup()
+ const { mount } = setup()
beforeEach(() => {
- let instance = mount(TableValidators, {
+ const instance = mount(TableValidators, {
doBefore: ({ store }) => {
store.commit(`setConnected`, true)
- store.commit(`setAtoms`, 1337)
+ store.commit(`updateWalletBalance`, {
+ denom: `atom`,
+ amount: 1337
+ })
},
propsData: { validators: lcdClientMock.candidates }
})
wrapper = instance.wrapper
store = instance.store
store.state.user.address = `address1234`
- store.commit(`setAtoms`, 1337)
+ store.commit(`updateWalletBalance`, {
+ denom: `atom`,
+ amount: 1337
+ })
store.commit(`setStakingParameters`, stakingParameters.parameters)
})
@@ -68,6 +74,32 @@ describe(`TableValidators`, () => {
expect(wrapper.vm.somethingToSearch).toBe(false)
})
+ it(`should disallow delegation if user can't delegate`, () => {
+ let res = TableValidators.computed.userCanDelegate.call({
+ liquidAtoms: 0,
+ delegation: {
+ loaded: true
+ }
+ })
+ expect(res).toBe(false)
+
+ res = TableValidators.computed.userCanDelegate.call({
+ liquidAtoms: 1,
+ delegation: {
+ loaded: true
+ }
+ })
+ expect(res).toBe(true)
+
+ res = TableValidators.computed.userCanDelegate.call({
+ liquidAtoms: 1,
+ delegation: {
+ loaded: false
+ }
+ })
+ expect(res).toBe(false)
+ })
+
describe(`setSearch`, () => {
it(`should show search when there is something to search`, () => {
const $store = {
diff --git a/test/unit/specs/components/staking/UndelegationModal.spec.js b/test/unit/specs/components/staking/UndelegationModal.spec.js
index de7403beee..41f79cdea1 100644
--- a/test/unit/specs/components/staking/UndelegationModal.spec.js
+++ b/test/unit/specs/components/staking/UndelegationModal.spec.js
@@ -7,130 +7,99 @@ import lcdClientMock from "renderer/connectors/lcdClientMock.js"
describe(`UndelegationModal`, () => {
let wrapper, store
- let { stakingParameters } = lcdClientMock.state
- let { mount, localVue } = setup()
+ const { stakingParameters } = lcdClientMock.state
+ const { mount, localVue } = setup()
localVue.use(Vuelidate)
localVue.directive(`tooltip`, () => {})
localVue.directive(`focus`, () => {})
beforeEach(() => {
- let instance = mount(UndelegationModal, {
+ const instance = mount(UndelegationModal, {
localVue,
propsData: {
maximum: 100,
+ validator: lcdClientMock.state.candidates[0],
to: `cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au`,
- denom: stakingParameters.parameters.bond_denom
+ denom: stakingParameters.parameters.bond_denom,
+ fromOptions: [
+ {
+ address: `cosmosval1234`
+ }
+ ]
}
})
wrapper = instance.wrapper
store = instance.store
+ store.state.connection.connected = true
store.commit(`setStakingParameters`, stakingParameters.parameters)
+ store.commit(`setSignIn`, true)
+
+ wrapper.vm.$refs.actionModal.open()
})
describe(`component matches snapshot`, () => {
- it(`has the expected html structure`, async () => {
+ it(`has the expected html structure`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
})
- describe(`default values are set correctly`, () => {
- it(`the 'amount' defaults to 0`, () => {
- expect(wrapper.vm.amount).toEqual(0)
- })
+ it(`opens`, () => {
+ wrapper.vm.$refs.actionModal.open = jest.fn()
+ wrapper.vm.open()
+ expect(wrapper.vm.$refs.actionModal.open).toHaveBeenCalled()
+ })
+ describe(`default values are set correctly`, () => {
it(`displays the user's wallet address as the default`, () => {
- let toField = wrapper.find(`#to`)
+ const toField = wrapper.find(`#to`)
expect(toField).toBeDefined()
expect(toField.element.value).toEqual(
`cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au`
)
})
-
- it(`account password defaults to an empty string`, () => {
- expect(wrapper.vm.password).toEqual(``)
- })
-
- it(`password is hidden by default`, () => {
- expect(wrapper.vm.showPassword).toBe(false)
- })
- })
-
- describe(`Password display`, () => {
- it(`toggles the password between text and password`, () => {
- wrapper.vm.togglePassword()
- expect(wrapper.vm.showPassword).toBe(true)
- wrapper.vm.togglePassword()
- expect(wrapper.vm.showPassword).toBe(false)
- })
})
- describe(`enables or disables the Delegation button correctly`, () => {
- describe(`disables the 'Delegation' button`, () => {
- it(`with default values`, () => {
- let undelegationBtn = wrapper.find(`#submit-undelegation`)
- expect(undelegationBtn.html()).toContain(`disabled="disabled"`)
- })
-
- it(`if the user manually inputs a number greater than the balance`, () => {
- wrapper.setData({ amount: 142, password: `1234567890` })
- let amountField = wrapper.find(`#amount`)
- let undelegationBtn = wrapper.find(`#submit-undelegation`)
- expect(undelegationBtn.html()).toContain(`disabled="disabled"`)
- let errorMessage = wrapper.find(`input#amount + div`)
- expect(errorMessage.classes()).toContain(`tm-form-msg--error`)
-
- amountField.trigger(`input`)
- expect(amountField.element.value).toBe(`100`)
+ describe(`only submits on correct form`, () => {
+ describe(`validates`, () => {
+ it(`to false with default values`, () => {
+ expect(wrapper.vm.validateForm()).toBe(false)
})
- it(`if the password field is empty`, () => {
- wrapper.setData({ amount: 10, password: `` })
- let undelegationBtn = wrapper.find(`#submit-undelegation`)
- expect(undelegationBtn.html()).toContain(`disabled="disabled"`)
- })
- })
-
- describe(`enables the 'Delegation' button`, () => {
- it(`if the amout is positive and the user has enough balance`, () => {
- wrapper.setData({ amount: 50, password: `1234567890` })
-
- let undelegationBtn = wrapper.find(`#submit-undelegation`)
- expect(undelegationBtn.html()).not.toContain(`disabled="disabled"`)
+ it(`to true if the amount is positive and the user has enough liquid atoms`, () => {
+ wrapper.setData({ amount: 50 })
+ expect(wrapper.vm.validateForm()).toBe(true)
})
})
})
describe(`Undelegate`, () => {
- it(`Undelegation button submits an unbonding delegation and closes modal`, () => {
- wrapper.setData({ amount: 4.2, password: `1234567890` })
- wrapper.vm.onUndelegate()
-
- expect(wrapper.emittedByOrder()).toEqual([
- {
- name: `submitUndelegation`,
- args: [
- {
- amount: 4.2,
- password: `1234567890`
- }
- ]
- },
- {
- name: `update:showUndelegationModal`,
- args: [false]
- }
+ it(`submits undelegation`, async () => {
+ wrapper.vm.$store.dispatch = jest.fn()
+ wrapper.vm.$store.commit = jest.fn()
+
+ wrapper.setData({ amount: 4.2 })
+ await wrapper.vm.submitForm(`local`, `1234567890`)
+
+ expect(wrapper.vm.$store.dispatch.mock.calls).toEqual([
+ [
+ `submitUnbondingDelegation`,
+ {
+ amount: -4.2,
+ validator: lcdClientMock.state.candidates[0],
+ submitType: `local`,
+ password: `1234567890`
+ }
+ ]
])
- })
- })
- describe(`closes modal correctly`, () => {
- it(`X button emits close signal`, () => {
- wrapper.vm.close()
- expect(wrapper.emittedByOrder()).toEqual([
- {
- name: `update:showUndelegationModal`,
- args: [false]
- }
+ expect(wrapper.vm.$store.commit.mock.calls).toEqual([
+ [
+ `notify`,
+ {
+ body: `You have successfully undelegated 4.2 STAKEs.`,
+ title: `Successful undelegation!`
+ }
+ ]
])
})
})
diff --git a/test/unit/specs/components/staking/__snapshots__/DelegationModal.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/DelegationModal.spec.js.snap
index ce672925b5..703420f5b6 100644
--- a/test/unit/specs/components/staking/__snapshots__/DelegationModal.spec.js.snap
+++ b/test/unit/specs/components/staking/__snapshots__/DelegationModal.spec.js.snap
@@ -2,24 +2,28 @@
exports[`DelegationModal component matches snapshot has the expected html structure 1`] = `
+
+
`;
diff --git a/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap
index 9874508413..d2c30b18f4 100644
--- a/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap
+++ b/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap
@@ -21,136 +21,23 @@ exports[`PageStaking has the expected html structure 1`] = `