-
Notifications
You must be signed in to change notification settings - Fork 98
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fa65c6c
li proposal test refactor
jbibla f7d6964
Merge branch 'develop' into jordan/1337-li-proposal-tests
jbibla 1eaa696
cleaned up LiProposal test
jbibla ece846e
lint
jbibla 7fa5491
cha cha cha
jbibla 854453e
Merge branch 'develop' into jordan/1337-li-proposal-tests
jbibla 27dd92d
fixed tests and eslint was complaining
jbibla 1a3ef00
DRYed out tests (danke karoly)
jbibla f2a23f0
Update CHANGELOG.md
jbibla 5fc87df
Merge branch 'develop' into jordan/1337-li-proposal-tests
faboweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
115 changes: 71 additions & 44 deletions
115
test/unit/specs/components/governance/LiProposal.spec.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,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() | ||
}) | ||
}) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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