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> </div>
<p>Counter: {count}</p> <p>Counter: {count}</p>
<button <button
id='counter-increase'
onClick={() => this.increaseCounter()} onClick={() => this.increaseCounter()}
> >
Increase Increase

View file

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

View file

@ -9,8 +9,8 @@ function routeToAbout (e) {
export default () => ( export default () => (
<div id='home-page'> <div id='home-page'>
<div> <div>
<Link href='/about' id='about-via-link'> <Link href='/about'>
<a>About via Link</a> <a id='about-via-link'>About via Link</a>
</Link> </Link>
<a <a
href='#' href='#'
@ -19,28 +19,25 @@ export default () => (
> >
About via Router About via Router
</a> </a>
<Link href='/counter' id='counter'> <Link href='/counter'>
<a>Counter</a> <a id='counter'>Counter</a>
</Link> </Link>
<Link <Link
href='/dynamic?text=cool+dynamic+text' href='/dynamic?text=cool+dynamic+text'
id='get-initial-props'
> >
<a>getInitialProps</a> <a id='get-initial-props'>getInitialProps</a>
</Link> </Link>
<Link <Link
href='/dynamic?text=next+export+is+nice' href='/dynamic?text=next+export+is+nice'
as='/dynamic/one' as='/dynamic/one'
id='dynamic-1'
> >
<a>Dynamic 1</a> <a id='dynamic-1'>Dynamic 1</a>
</Link> </Link>
<Link <Link
href='/dynamic?text=zeit+is+awesome' href='/dynamic?text=zeit+is+awesome'
as='/dynamic/two' as='/dynamic/two'
id='dynamic-2'
> >
<a>Dynamic 2</a> <a id='dynamic-2'>Dynamic 2</a>
</Link> </Link>
</div> </div>
<p>This is the home page</p> <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 { join } from 'path'
import { import {
@ -7,9 +7,9 @@ import {
startStaticServer, startStaticServer,
stopApp stopApp
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver'
import ssr from './ssr' import ssr from './ssr'
import browser from './browser'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000 jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
@ -27,15 +27,5 @@ describe('Static Export', () => {
afterAll(() => stopApp(context.server)) afterAll(() => stopApp(context.server))
ssr(context) ssr(context)
browser(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()
})
})
}) })