1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add a test case for client side routing for next export.

This commit is contained in:
Arunoda Susiripala 2017-05-11 08:52:28 -07:00
parent b18ecc925b
commit 880eb4caff
2 changed files with 30 additions and 10 deletions

View file

@ -1,27 +1,23 @@
import React from 'react'
import Link from 'next/link'
export default class Counter extends React.Component {
constructor (...args) {
super(...args)
this.state = { count: 0 }
}
let counter = 0
export default class Counter extends React.Component {
increaseCounter () {
const { count } = this.state
this.setState({ count: count + 1 })
counter++
this.forceUpdate()
}
render () {
const { count } = this.state
return (
<div id='counter-page'>
<div>
<Link href='/'>
<a>Go Back</a>
<a id='go-back'>Go Back</a>
</Link>
</div>
<p>Counter: {count}</p>
<p>Counter: {counter}</p>
<button
id='counter-increase'
onClick={() => this.increaseCounter()}

View file

@ -68,5 +68,29 @@ export default function (context) {
expect(text).toBe('next export is nice')
browser.close()
})
it('should support client side naviagtion', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#counter').click()
.waitForElementByCss('#counter-page')
.elementByCss('#counter-increase').click()
.elementByCss('#counter-increase').click()
.elementByCss('#counter-page p').text()
expect(text).toBe('Counter: 2')
// let's go back and come again to this page:
const textNow = await browser
.elementByCss('#go-back').click()
.waitForElementByCss('#home-page')
.elementByCss('#counter').click()
.waitForElementByCss('#counter-page')
.elementByCss('#counter-page p').text()
expect(textNow).toBe('Counter: 2')
browser.close()
})
})
}