Skip to content

Commit

Permalink
Merge pull request #484 from cosmos/fabo/326-monitor-tests
Browse files Browse the repository at this point in the history
Increase coverage for monitor components
  • Loading branch information
jbibla authored Feb 16, 2018
2 parents 6f9f6d6 + c28a376 commit ec76822
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 52 deletions.
80 changes: 41 additions & 39 deletions app/src/renderer/components/monitor/PageBlock.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
<template lang="pug">
page(:title="pageBlockTitle" v-if="block.header")
div(slot="menu"): tool-bar
a(:href="blockUrl" target="_blank")
i.material-icons code
.label JSON
router-link(:to="{ name: 'block', params: { block: block.header.height - 1 }}")
i.material-icons chevron_left
.label Previous Block
router-link(:to="{ name: 'block', params: { block: block.header.height + 1 }}")
i.material-icons chevron_right
.label Next Block
page(:title="pageBlockTitle")
data-loading(v-if="!block.header")
template(v-else)
div(slot="menu"): tool-bar
a(:href="blockUrl" target="_blank")
i.material-icons code
.label JSON
router-link(:to="{ name: 'block', params: { block: block.header.height - 1 }}")
i.material-icons chevron_left
.label Previous Block
router-link(:to="{ name: 'block', params: { block: block.header.height + 1 }}")
i.material-icons chevron_right
.label Next Block

part(title='')
list-item(dt="Block Hash" :dd="blockMeta.block_id.hash")
part(title='')
list-item(dt="Block Hash" :dd="blockMeta.block_id.hash")

part(title='Header')
list-item(dt="Chain ID" :dd="block.header.chain_id")
list-item(dt="Time" :dd="blockHeaderTime")
list-item(dt="Transactions" :dd="block.header.num_txs")
list-item(dt="Last Commit Hash" :dd="block.header.last_commit_hash")
list-item(dt="Validators Hash" :dd="block.header.validators_hash")
list-item(dt="App Hash" :dd="block.header.app_hash")
part(title='Header')
list-item(dt="Chain ID" :dd="block.header.chain_id")
list-item(dt="Time" :dd="blockHeaderTime")
list-item(dt="Transactions" :dd="block.header.num_txs")
list-item(dt="Last Commit Hash" :dd="block.header.last_commit_hash")
list-item(dt="Validators Hash" :dd="block.header.validators_hash")
list-item(dt="App Hash" :dd="block.header.app_hash")

part(title='Last Block')
list-item(dt="Hash" :dd="block.header.last_block_id.hash")
list-item(dt="Parts Total"
:dd="block.header.last_block_id.parts.total")
list-item(dt="Parts Hash" :dd="block.header.last_block_id.parts.hash")
part(title='Last Block')
list-item(dt="Hash" :dd="block.header.last_block_id.hash")
list-item(dt="Parts Total"
:dd="block.header.last_block_id.parts.total")
list-item(dt="Parts Hash" :dd="block.header.last_block_id.parts.hash")

part(title="Precommit"
v-for="p in block.last_commit.precommits"
:key="p.validator_address" v-if="p !== null")
list-item(dt="Address" :dd="p.validator_address")
list-item(dt="Index" :dd="p.validator_index")
list-item(dt="Round" :dd="p.round")
list-item(:dt="`Sig (${p.signature.type})`"
:dd="p.signature.data")
part(title="Precommit"
v-for="p in block.last_commit.precommits"
:key="p.validator_address" v-if="p !== null")
list-item(dt="Address" :dd="p.validator_address")
list-item(dt="Index" :dd="p.validator_index")
list-item(dt="Round" :dd="p.round")
list-item(:dt="`Sig (${p.signature.type})`"
:dd="p.signature.data")

part(title='Transactions')
data-loading(v-if="blockchain.blockLoading")
data-empty(v-else-if="block.header.num_txs === 0" title="Empty Block" subtitle="There were no transactions in this block.")
list-item(v-else v-for="tx in block.data.txs" :key="tx.id" dt="Transaction" :dd="TODO")
part(title='Transactions')
data-loading(v-if="blockchain.blockLoading")
data-empty(v-else-if="block.header.num_txs === 0" title="Empty Block" subtitle="There were no transactions in this block.")
list-item(v-else v-for="tx in block.data.txs" :key="tx.id" dt="Transaction" :dd="TODO")
</template>

<script>
Expand Down Expand Up @@ -76,14 +78,14 @@ export default {
return this.blockchain.url
},
blockHeaderTime () {
if (this.block.header.time) {
if (this.block.header) {
return moment(this.block.header.time).format('MMMM Do YYYY — hh:mm:ss')
} else {
return 'Loading...'
}
},
blockMeta () {
if (this.block) {
if (this.block.header) {
return this.blockchain.block.block_meta
} else {
return {}
Expand Down
6 changes: 1 addition & 5 deletions app/src/renderer/components/monitor/PageBlocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ export default {
return this.blockchain.status
},
latestBlockTime () {
if (this.lastHeader.time) {
return moment(this.lastHeader.time).format('MMMM Do YYYY — hh:mm:ss')
} else {
return 'Loading…'
}
return moment(this.lastHeader.time).format('MMMM Do YYYY — hh:mm:ss')
},
latestBlockHash () {
return this.lastHeader.last_block_id.hash
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"lodash": "^4.17.4",
"markdown-it": "^8.3.2",
"mkdirp": "^0.5.1",
"moment-timezone": "~0.5.13",
"node-loader": "^0.6.0",
"node-sass": "^4.7.2",
"proxyquire": "^1.8.0",
Expand Down Expand Up @@ -113,7 +114,7 @@
"glob": "^7.1.2",
"interactjs": "^1.3.3",
"jszip": "^3.1.5",
"moment": "^2.17.1",
"moment": "~2.18.1",
"mousetrap": "^1.6.1",
"nib": "^1.1.2",
"no-scroll": "^2.1.0",
Expand Down
3 changes: 3 additions & 0 deletions test/unit/helpers/fixed_time.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* globals jest */
require('moment')
const mockMomentTz = require('moment-timezone')
jest.mock('moment', () => (time) => mockMomentTz(time).tz('Europe/Berlin'))

const DATE_TO_USE = new Date(1608)
const _Date = Date
Expand Down
10 changes: 8 additions & 2 deletions test/unit/specs/components/monitor/PageBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('PageBlock', () => {
},
num_txs: 0,
height: 10,
time: null
time: 1608
},
last_commit: {
precommits: []
Expand Down Expand Up @@ -63,15 +63,21 @@ describe('PageBlock', () => {
expect(store.dispatch).toHaveBeenCalledWith('getBlock', wrapper.vm.$route.params.block)
})

it('should return an empty object if there is no block', () => {
it('should show a loading state if no block loaded yet', () => {
let {wrapper} = mount(PageBlock, {
getters: {
blockchain: () => ({
block: {}
})
},
stubs: {
'data-loading': '<data-loading />'
}
})
wrapper.update()

expect(wrapper.vm.block).toEqual({})
expect(wrapper.contains('data-loading')).toBe(true)
expect(htmlBeautify(wrapper.html())).toMatchSnapshot()
})
})
2 changes: 1 addition & 1 deletion test/unit/specs/components/monitor/PageBlocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('PageBlocks', () => {
},
getters: {
lastHeader: () => ({
time: null,
time: 1608,
last_block_id: {
hash: '123'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ exports[`PageBlock has the expected html structure 1`] = `
Time
</div>
<div class=\\"ni-li-dd\\">
Loading...
January 1st 1970 02:00:01
</div>
</div>
</div>
Expand Down Expand Up @@ -260,3 +260,28 @@ exports[`PageBlock has the expected html structure 1`] = `
</main>
</div>"
`;
exports[`PageBlock should show a loading state if no block loaded yet 1`] = `
"<div class=\\"ni-page\\">
<header class=\\"ni-page-header\\">
<div class=\\"ni-page-header-container\\">
<div class=\\"ni-page-header-text\\">
<div class=\\"ni-page-header-title\\">
<h2>
Loading...
</h2>
</div>
<div class=\\"ni-page-header-subtitle\\">
<h3></h3>
</div>
</div>
<menu class=\\"ni-page-header-menu\\">
<div></div>
</menu>
</div>
</header>
<main class=\\"ni-page-main\\">
<data-loading></data-loading>
</main>
</div>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`PageBlocks has the expected html structure 1`] = `
Block Time
</div>
<div class=\\"ni-li-dd\\">
Loading…
January 1st 1970 02:00:01
</div>
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5420,11 +5420,17 @@ module-not-found-error@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"

moment@^2.15.2, moment@^2.17.1:
moment-timezone@~0.5.13:
version "0.5.14"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.14.tgz#4eb38ff9538b80108ba467a458f3ed4268ccfcb1"
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0", moment@^2.15.2:
version "2.20.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"

moment@~2.18.0:
moment@~2.18.0, moment@~2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

Expand Down

0 comments on commit ec76822

Please sign in to comment.