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

Add browser tests for next-export

This commit is contained in:
Arunoda Susiripala 2017-05-09 18:54:08 -07:00
parent 56dc85485f
commit 14fa6f5893
5 changed files with 84 additions and 24 deletions

View file

@ -23,6 +23,7 @@ export default class Counter extends React.Component {
</div>
<p>Counter: {count}</p>
<button
id='counter-increase'
onClick={() => this.increaseCounter()}
>
Increase

View file

@ -1,7 +1,7 @@
import Link from 'next/link'
const DynamicPage = ({ text }) => (
<div id='about-page'>
<div id='dynamic-page'>
<div>
<Link href='/'>
<a>Go Back</a>

View file

@ -9,8 +9,8 @@ function routeToAbout (e) {
export default () => (
<div id='home-page'>
<div>
<Link href='/about' id='about-via-link'>
<a>About via Link</a>
<Link href='/about'>
<a id='about-via-link'>About via Link</a>
</Link>
<a
href='#'
@ -19,28 +19,25 @@ export default () => (
>
About via Router
</a>
<Link href='/counter' id='counter'>
<a>Counter</a>
<Link href='/counter'>
<a id='counter'>Counter</a>
</Link>
<Link
href='/dynamic?text=cool+dynamic+text'
id='get-initial-props'
>
<a>getInitialProps</a>
<a id='get-initial-props'>getInitialProps</a>
</Link>
<Link
href='/dynamic?text=next+export+is+nice'
as='/dynamic/one'
id='dynamic-1'
>
<a>Dynamic 1</a>
<a id='dynamic-1'>Dynamic 1</a>
</Link>
<Link
href='/dynamic?text=zeit+is+awesome'
as='/dynamic/two'
id='dynamic-2'
>
<a>Dynamic 2</a>
<a id='dynamic-2'>Dynamic 2</a>
</Link>
</div>
<p>This is the home page</p>

View file

@ -0,0 +1,72 @@
/* global describe, it, expect */
import webdriver from 'next-webdriver'
export default function (context) {
describe('Render via browser', () => {
it('should render the home page', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#home-page p').text()
expect(text).toBe('This is the home page')
browser.close()
})
it('should do navigations via Link', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#about-via-link').click()
.waitForElementByCss('#about-page')
.elementByCss('#about-page p').text()
expect(text).toBe('This is the About page')
browser.close()
})
it('should do navigations via Router', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#about-via-router').click()
.waitForElementByCss('#about-page')
.elementByCss('#about-page p').text()
expect(text).toBe('This is the About page')
browser.close()
})
it('should do run client side javascript', 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')
browser.close()
})
it('should render pages using getInitialProps', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#get-initial-props').click()
.waitForElementByCss('#dynamic-page')
.elementByCss('#dynamic-page p').text()
expect(text).toBe('cool dynamic text')
browser.close()
})
it('should render dynamic pages with custom urls', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#dynamic-1').click()
.waitForElementByCss('#dynamic-page')
.elementByCss('#dynamic-page p').text()
expect(text).toBe('next export is nice')
browser.close()
})
})
}

View file

@ -1,4 +1,4 @@
/* global jasmine, describe, it, expect, beforeAll, afterAll */
/* global jasmine, describe, beforeAll, afterAll */
import { join } from 'path'
import {
@ -7,9 +7,9 @@ import {
startStaticServer,
stopApp
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import ssr from './ssr'
import browser from './browser'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000
const appDir = join(__dirname, '../')
@ -27,15 +27,5 @@ describe('Static Export', () => {
afterAll(() => stopApp(context.server))
ssr(context)
describe('Render via browser', () => {
it('should render the home page', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#home-page p').text()
expect(text).toBe('This is the home page')
browser.close()
})
})
browser(context)
})