Skip to content

Commit

Permalink
query-with-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Jul 25, 2020
1 parent 6f53352 commit 9ab9fa6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
76 changes: 25 additions & 51 deletions test/integration/query-with-encoding/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-env jest */

import {
nextBuild,
nextServer,
startApp,
stopApp,
waitFor,
} from 'next-test-utils'
import { nextBuild, nextServer, startApp, stopApp } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'

Expand Down Expand Up @@ -46,12 +40,11 @@ describe('Query String with Encoding', () => {
it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.waitForCondition('!!window.next.router')
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def\\n'}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"abc":"def\\n"}')
} finally {
await browser.close()
Expand All @@ -61,10 +54,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/newline')
try {
await waitFor(2000)
await browser.elementByCss('#hello-lf').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-lf').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"another":"hello\\n"}')
} finally {
await browser.close()
Expand All @@ -74,10 +65,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/newline')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-complex').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes\\n"}')
} finally {
await browser.close()
Expand All @@ -99,12 +88,11 @@ describe('Query String with Encoding', () => {
it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.waitForCondition('!!window.next.router')
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def '}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"abc":"def "}')
} finally {
await browser.close()
Expand All @@ -114,10 +102,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/space')
try {
await waitFor(2000)
await browser.elementByCss('#hello-space').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-space').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"another":"hello "}')
} finally {
await browser.close()
Expand All @@ -127,10 +113,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/space')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-complex').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes "}')
} finally {
await browser.close()
Expand All @@ -152,12 +136,11 @@ describe('Query String with Encoding', () => {
it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.waitForCondition('!!window.next.router')
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def%'}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"abc":"def%"}')
} finally {
await browser.close()
Expand All @@ -167,10 +150,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/percent')
try {
await waitFor(2000)
await browser.elementByCss('#hello-percent').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-percent').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"another":"hello%"}')
} finally {
await browser.close()
Expand All @@ -180,10 +161,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/percent')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-complex').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes%"}')
} finally {
await browser.close()
Expand All @@ -205,12 +184,11 @@ describe('Query String with Encoding', () => {
it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.waitForCondition('!!window.next.router')
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def+'}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"abc":"def+"}')
} finally {
await browser.close()
Expand All @@ -220,10 +198,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/plus')
try {
await waitFor(2000)
await browser.elementByCss('#hello-plus').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-plus').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"another":"hello+"}')
} finally {
await browser.close()
Expand All @@ -233,10 +209,8 @@ describe('Query String with Encoding', () => {
it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/plus')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
await browser.waitForElementByCss('#hello-complex').click()
const text = await browser.waitForElementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes+"}')
} finally {
await browser.close()
Expand Down
8 changes: 8 additions & 0 deletions test/lib/wd-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export default class Chain {
)
}

waitForCondition(condition) {
return this.updateChain(() =>
this.browser.wait(async (driver) => {
return driver.executeScript('return ' + condition).catch(() => false)
})
)
}

eval(snippet) {
if (typeof snippet === 'string' && !snippet.startsWith('return')) {
snippet = `return ${snippet}`
Expand Down

0 comments on commit 9ab9fa6

Please sign in to comment.