From eabd75d8f3bdf1bdff89b2db5eb1b8f02d5cf1c6 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 15 Jan 2020 10:52:32 -0500 Subject: [PATCH] Test Query String With LF --- .../query-with-newline/pages/another.js | 15 ++++ .../query-with-newline/pages/index.js | 7 ++ .../query-with-newline/test/index.test.js | 85 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 test/integration/query-with-newline/pages/another.js create mode 100644 test/integration/query-with-newline/pages/index.js create mode 100644 test/integration/query-with-newline/test/index.test.js diff --git a/test/integration/query-with-newline/pages/another.js b/test/integration/query-with-newline/pages/another.js new file mode 100644 index 0000000000000..f54a15a0ec780 --- /dev/null +++ b/test/integration/query-with-newline/pages/another.js @@ -0,0 +1,15 @@ +import Link from 'next/link' + +const Another = () => ( +
+ + Hello LF + +
+ + Hello Complex + +
+) + +export default Another diff --git a/test/integration/query-with-newline/pages/index.js b/test/integration/query-with-newline/pages/index.js new file mode 100644 index 0000000000000..5abbac3c14b81 --- /dev/null +++ b/test/integration/query-with-newline/pages/index.js @@ -0,0 +1,7 @@ +const Index = ({ query }) => ( +
{JSON.stringify(query)}
+) + +Index.getInitialProps = ({ query }) => ({ query }) + +export default Index diff --git a/test/integration/query-with-newline/test/index.test.js b/test/integration/query-with-newline/test/index.test.js new file mode 100644 index 0000000000000..41bb8091046b5 --- /dev/null +++ b/test/integration/query-with-newline/test/index.test.js @@ -0,0 +1,85 @@ +/* eslint-env jest */ +/* global jasmine */ +import { + nextBuild, + nextServer, + startApp, + stopApp, + waitFor, +} from 'next-test-utils' +import webdriver from 'next-webdriver' +import { join } from 'path' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 + +const appDir = join(__dirname, '..') + +let appPort +let app +let server + +describe('New Line in Query', () => { + beforeAll(async () => { + await nextBuild(appDir) + app = nextServer({ + dir: join(__dirname, '../'), + dev: false, + quiet: true, + }) + + server = await startApp(app) + appPort = server.address().port + }) + afterAll(() => stopApp(server)) + + it('should have correct query on SSR', async () => { + const browser = await webdriver(appPort, '/?test=abc%0A') + try { + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"test":"abc\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on Router#push', async () => { + const browser = await webdriver(appPort, '/') + try { + await waitFor(2000) + await browser.eval( + `window.next.router.push({pathname:'/',query:{abc:'def\\n'}})` + ) + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"abc":"def\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on simple client-side ', async () => { + const browser = await webdriver(appPort, '/another') + try { + await waitFor(2000) + await browser.elementByCss('#hello-lf').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"another":"hello\\n"}') + } finally { + await browser.close() + } + }) + + it('should have correct query on complex client-side ', async () => { + const browser = await webdriver(appPort, '/another') + try { + await waitFor(2000) + await browser.elementByCss('#hello-complex').click() + await waitFor(1000) + const text = await browser.elementByCss('#query-content').text() + expect(text).toBe('{"complex":"yes\\n"}') + } finally { + await browser.close() + } + }) +})