Skip to content

Commit

Permalink
WIP: Composition test for new proposal creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Braun authored and David Braun committed Nov 8, 2018
1 parent 2b22403 commit e7f2a91
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default {
title: this.fields.title
})
this.resetForm()
this.$router.push({ name: `proposals` })
this.$router.push({ name: `Governance` })
}
},
resetForm() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Client = (axios, localLcdURL, remoteLcdURL) => {
async function request(method, path, data, useRemote) {
const url = useRemote ? remoteLcdURL : localLcdURL
return (await axios[method.toLowerCase()](url + path, data)).data
return (await axios({ data, method, url: url + path })).data
}

// returns an async function which makes a request for the given
Expand Down
3 changes: 1 addition & 2 deletions app/src/renderer/connectors/node.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"use strict"

const axios = require(`axios`)
const RestClient = require(`./lcdClient.js`)
const mockedRestClient = require(`./lcdClientMock.js`)
const RpcWrapper = require(`./rpcWrapper.js`)
const MockedRpcWrapper = require(`./rpcWrapperMock.js`)

module.exports = function(localLcdURL, remoteLcdURL, mocked = false) {
module.exports = function(axios, localLcdURL, remoteLcdURL, mocked = false) {
let connector = {
mocked,
localLcdURL,
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict"

import axios from "axios"
import Vue from "vue"
import Electron from "vue-electron"
import Router from "vue-router"
Expand Down Expand Up @@ -69,7 +70,7 @@ async function main() {
let lcdPort = getQueryParameter(`lcd_port`)
let localLcdURL = `http://localhost:${lcdPort}`
console.log(`Expecting lcd-server on port: ` + lcdPort)
node = Node(localLcdURL, config.node_lcd, config.mocked)
node = Node(axios, localLcdURL, config.node_lcd, config.mocked)

store = Store({ node })
store.dispatch(`loadTheme`)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/specs/App.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
import axios from "axios"

/* mocking electron differently in one file apparently didn't work so I had to split the App tests in 2 files */

Expand Down Expand Up @@ -60,6 +60,7 @@ describe(`App without analytics`, () => {
let Node = require(`renderer/connectors/node.js`)
require(`renderer/main.js`)
expect(Node).toHaveBeenCalledWith(
axios,
`http://localhost:8080`,
`https://awesomenode.de:12345`,
true
Expand Down
57 changes: 54 additions & 3 deletions test/unit/specs/components/govern/PageProposalsNewText.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import PageProposalsNewText from "renderer/components/govern/PageProposalsNewText"
import Node from "renderer/connectors/node"
import PageProposalsNewText from "renderer/components/governance/PageProposalsNewText"
import Store from "renderer/vuex/store"
import Vuelidate from "vuelidate"
import { createLocalVue, mount } from "@vue/test-utils"

Expand Down Expand Up @@ -29,7 +31,10 @@ describe(`PageProposalsNewText`, () => {
})

it(`onSubmit`, () => {
wrapper.setData({ fields: { body: `description`, title: `proposaltitle` } })
wrapper.setData({
fields: { body: `description`, title: `proposal title` }
})

wrapper.vm.onSubmit()

expect($store.dispatch.mock.calls).toEqual([
Expand All @@ -38,9 +43,55 @@ describe(`PageProposalsNewText`, () => {
{
description: `description`,
proposal_type: `Text`,
title: `proposaltitle`
title: `proposal title`
}
]
])
})

it(`sends the correct request to Gaia Lite`, done => {
const axios = async options => {
expect(options).toEqual({
data: {
base_req: {
account_number: undefined,
chain_id: ``,
name: null,
password: null,
sequence: `0`
},
description: `description`,
gas: `50000000`,
initial_deposit: undefined,
proposal_type: `Text`,
proposer: null,
title: `proposal title`
},
method: `POST`,
url: `remoteURL/gov/proposals`
})

done()
return { data: { check_tx: {}, deliver_tx: {} } }
}

const node = Node(axios, `localURL`, `remoteURL`)
const store = Store({ node })
const localVue = createLocalVue()
localVue.use(Vuelidate)

wrapper = mount(PageProposalsNewText, {
localVue,
mocks: {
$router: []
},
store
})

wrapper.setData({
fields: { body: `description`, title: `proposal title` }
})

wrapper.vm.onSubmit()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports[`PageProposalsNewText has the expected HTML structure 1`] = `
</a>
<router-link
exact="exact"
to="/proposals/new"
to="/governance/proposals/new"
>
<i
class="material-icons"
Expand Down
Loading

0 comments on commit e7f2a91

Please sign in to comment.