diff --git a/test/integration/basic/pages/nav/index.js b/test/integration/basic/pages/nav/index.js index fad7a159..f92a7cba 100644 --- a/test/integration/basic/pages/nav/index.js +++ b/test/integration/basic/pages/nav/index.js @@ -27,6 +27,7 @@ export default class extends Component { Empty Props Self Reload Shallow Routing + Redirect ( +

This is the page

+) + +Page.getInitialProps = (ctx) => { + if (ctx.res) { + ctx.res.writeHead(302, { Location: '/nav/about' }) + ctx.res.end() + } else { + Router.push('/nav/about') + } + + return {} +} + +export default Page diff --git a/test/integration/basic/test/client-navigation.js b/test/integration/basic/test/client-navigation.js index 8807bdb0..2f4a187f 100644 --- a/test/integration/basic/test/client-navigation.js +++ b/test/integration/basic/test/client-navigation.js @@ -298,5 +298,28 @@ export default (context, render) => { browser.close() }) }) + + describe('with getInitialProp redirect', () => { + it('should redirect the page via client side', async () => { + const browser = await webdriver(context.appPort, '/nav') + const text = await browser + .elementByCss('#redirect-link').click() + .waitForElementByCss('.nav-about') + .elementByCss('p').text() + + expect(text).toBe('This is the about page.') + browser.close() + }) + + it('should redirect the page when loading', async () => { + const browser = await webdriver(context.appPort, '/nav/redirect') + const text = await browser + .waitForElementByCss('.nav-about') + .elementByCss('p').text() + + expect(text).toBe('This is the about page.') + browser.close() + }) + }) }) } diff --git a/test/integration/basic/test/index.test.js b/test/integration/basic/test/index.test.js index 94bacaa7..d7a7d5a1 100644 --- a/test/integration/basic/test/index.test.js +++ b/test/integration/basic/test/index.test.js @@ -48,7 +48,8 @@ describe('Basic Features', () => { renderViaHTTP(context.appPort, '/nav/querystring'), renderViaHTTP(context.appPort, '/nav/self-reload'), renderViaHTTP(context.appPort, '/nav/hash-changes'), - renderViaHTTP(context.appPort, '/nav/shallow-routing') + renderViaHTTP(context.appPort, '/nav/shallow-routing'), + renderViaHTTP(context.appPort, '/nav/redirect') ]) }) afterAll(() => stopApp(context.server))