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

refactor li proposal test #2074

Merged
merged 10 commits into from
Feb 28, 2019
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Refactored tests: LiProposal @jbibla

## [1.0.0-beta.9] - 2019-02-28

### Fixed
Expand Down Expand Up @@ -53,6 +57,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Refactored tests: PageStaking, PanelSort, TabStakingParameters @faboweb
- Sign in with local key @faboweb
- [\#2024](https://github.com/cosmos/voyager/issues/2024) Fixed feature setting the rpc from url param @faboweb

Expand Down
8 changes: 4 additions & 4 deletions app/src/renderer/components/governance/LiProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
</td>
<td>{{ `#` + proposal.proposal_id }}</td>
<td class="li-proposal__value yes">
{{ tally.yes }}
{{ tally.yes || `--` }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: we should maybe prettify the tally result numbers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by prettify?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a function called pretty which shortens the value after 4 decimals

</td>
<td class="li-proposal__value no">
{{ tally.no }}
{{ tally.no || `--` }}
</td>
<td class="li-proposal__value no_with_veto">
{{ tally.no_with_veto }}
{{ tally.no_with_veto || `--` }}
</td>
<td class="li-proposal__value abstain">
{{ tally.abstain }}
{{ tally.abstain || `--` }}
</td>
</tr>
</template>
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/components/staking/LiValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<td class="li-validator__delegated-steak">
{{
yourVotes.isLessThan(0.01) && yourVotes.isGreaterThan(0)
? "< " + num.shortNumber(0.01) // eslint-disable-line
? num.shortNumber(0.01)
: num.shortNumber(yourVotes)
}}
</td>
Expand Down
115 changes: 71 additions & 44 deletions test/unit/specs/components/governance/LiProposal.spec.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,141 @@
import setup from "../../../helpers/vuex-setup"
import lcdClientMock from "renderer/connectors/lcdClientMock.js"
import { shallowMount, createLocalVue } from "@vue/test-utils"
import LiProposal from "renderer/components/governance/LiProposal"

const { proposals, tallies } = lcdClientMock.state
const proposal = proposals[`2`]
import { proposals, tallies } from "../../store/json/proposals"

const $store = {
commit: jest.fn(),
dispatch: jest.fn(),
getters: {
proposals: { proposals, tallies }
}
}
const proposal = proposals[`1`]

describe(`LiProposal`, () => {
const localVue = createLocalVue()
localVue.directive(`tooltip`, () => { })

let wrapper
const { mount } = setup()

beforeEach(() => {
const instance = mount(LiProposal, {
doBefore: ({ store }) => {
store.commit(`setConnected`, true)
store.commit(`setProposal`, proposal)
store.commit(`setProposalTally`, {
proposal_id: `2`,
final_tally_result: tallies[`2`]
})
const $store = {
commit: jest.fn(),
dispatch: jest.fn(),
getters: {
proposals: {
tallies
}
}
}

wrapper = shallowMount(LiProposal, {
localVue,
mocks: {
$store
},
propsData: { proposal },
$store
stubs: [`router-link`]
})
wrapper = instance.wrapper
})

it(`has the expected html structure`, () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})

it(`should return status info for passed proposals`, () => {
proposal.proposal_status = `Passed`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
proposal: {
...proposal,
proposal_status: `Passed`
}
})
expect(wrapper.vm.status).toEqual({
message: `This proposal has passed`
})
})

it(`should return status info for rejected proposals`, () => {
proposal.proposal_status = `Rejected`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
proposal: {
...proposal,
proposal_status: `Rejected`
}
})
expect(wrapper.vm.status).toEqual({
message: `This proposal has been rejected and voting is closed`,
color: `red`
})
})

it(`should return status info for active proposals`, () => {
proposal.proposal_status = `VotingPeriod`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
proposal: {
...proposal,
proposal_status: `VotingPeriod`
}
})
expect(wrapper.vm.status).toEqual({
message: `Voting for this proposal is open`,
color: `green`
})
})

it(`should return status info for 'DepositPeriod' proposals`, () => {
proposal.proposal_status = `DepositPeriod`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
proposal: {
...proposal,
proposal_status: `DepositPeriod`
}
})
expect(wrapper.vm.status).toEqual({
message: `Deposits are open for this proposal`,
color: `yellow`
})
})

it(`should return status info for an unknown proposal type`, () => {
proposal.proposal_status = `Unknown`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
proposal: {
...proposal,
proposal_status: `Unknown`
}
})
expect(wrapper.vm.status).toEqual({
message: `There was an error determining the status of this proposal.`,
color: `grey`
})
})

it(`should not truncate the description or add an ellipsis`, () => {
expect(wrapper.vm.description).toEqual(`custom text proposal description`)
expect(wrapper.vm.description).toEqual(`Proposal description`)
})

it(`should truncate the description and add an ellipsis`, () => {
proposal.description = `this is some kind of long description. longer than 100 characters for optimum-maximum-ideal truncation.`
wrapper.setProps({ proposal: JSON.parse(JSON.stringify(proposal)) })
wrapper.setProps({
proposal: {
...proposal,
description: `This is some kind of long description. longer than 100 characters for optimum-maximum-ideal truncation.`,
}
})
expect(wrapper.vm.description).toEqual(
`this is some kind of long description. longer than 100 characters for optimum-maximum-ideal truncati…`
`This is some kind of long description. longer than 100 characters for optimum-maximum-ideal truncati…`
)
})

it(`survives the tally result not being present yet`, () => {
jbibla marked this conversation as resolved.
Show resolved Hide resolved
it(`should survive the tally result not being present yet`, () => {
const $store = {
commit: jest.fn(),
dispatch: jest.fn(),
getters: {
proposals: { proposals, tallies: {} }
proposals: {
tallies: {}
}
}
}
const instance = mount(LiProposal, {
doBefore: ({ store }) => {
store.commit(`setConnected`, true)
store.commit(`setProposal`, proposal)

wrapper = shallowMount(LiProposal, {
localVue,
mocks: {
$store
},
propsData: { proposal },
$store
stubs: [`router-link`]
})
wrapper = instance.wrapper

expect(wrapper.vm.$el).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,140 @@ exports[`LiProposal has the expected html structure 1`] = `
class="data-table__row__info__container"
>
<span
class="data-table__row__info__container__status green"
/>
class="data-table__row__info__container__status material-icons"
>

checkmark

</span>

<router-link-stub
class="data-table__row__info__container__name"
to="[object Object]"
>

Proposal Title

</router-link-stub>

<p
class="data-table__row__info__container__description"
>

Proposal description

</p>
</div>
</td>

<td>
#1
</td>

<td
class="li-proposal__value yes"
>

500

</td>

<td
class="li-proposal__value no"
>

25

</td>

<td
class="li-proposal__value no_with_veto"
>

10

</td>

<td
class="li-proposal__value abstain"
>

56

</td>
</tr>
`;

exports[`LiProposal should survive the tally result not being present yet 1`] = `
<tr
class="data-table__row li-proposal"
>
<td
class="data-table__row__info"
>
<div
class="data-table__row__info__container"
>
<span
class="data-table__row__info__container__status material-icons"
>

checkmark

</span>

<router-link-stub
class="data-table__row__info__container__name"
to="[object Object]"
>

VotingPeriod proposal
Proposal Title

</router-link-stub>

<p
class="data-table__row__info__container__description"
>

custom text proposal description
Proposal description

</p>
</div>
</td>

<td>
#2
#1
</td>

<td
class="li-proposal__value yes"
>

0
--

</td>

<td
class="li-proposal__value no"
>

0
--

</td>

<td
class="li-proposal__value no_with_veto"
>

0
--

</td>

<td
class="li-proposal__value abstain"
>

0
--

</td>
</tr>
Expand Down
Loading