Skip to content

Commit

Permalink
test: add test for connection view
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlucas committed Mar 31, 2016
1 parent 7b7548b commit 826cdfa
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/views/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict'

const test = require('tap').test
const View = require('../../lib/views/connection')
const common = require('../common')

test('Connection View', (t) => {
const app = {
router: {
goto: (url) => {
t.pass('called goto')
t.equal(url, '/Freenode/settings', 'url is correct')
}
}
}

const verify = common.VerifyNode(t)

const view = new View(app)
t.type(view, View)
t.equal(view.target, app)

const conn = {
name: 'Freenode'
, url: '/Freenode'
, server: {
host: 'chat.freenode.net'
, port: 6667
}
, logs: [
{ ts: new Date()
, type: 'message'
, formatted: ''
}
]
}

const res = view.render(conn)

t.type(res, Array)
t.equal(res.length, 2, 'res.length')
const header = res[0]
verify(header, 'IRC-HEADER', {
className: 'pure-g'
}, 1, 'header')

const headerBody = header.children[0]
verify(headerBody, 'DIV', {
className: 'pure-u-1-1'
}, 3, 'header body')

const settings = headerBody.children[0]
verify(settings, 'A', {
className: 'settings'
}, 1, 'a.settings')

const opts = {
preventDefault: () => {
t.pass('called preventDefault()')
}
}

const out = settings.properties.onclick(opts)
t.equal(out, false, 'onclick returns false')

const body = res[1]
t.end()
})

0 comments on commit 826cdfa

Please sign in to comment.