Commit 9553f4cb authored by Jimmy Lai's avatar Jimmy Lai

Stabilize rewrites manual href/as test

parent 25fe25b5
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
import { join } from 'path' import { join } from 'path'
import { import {
check,
findPort, findPort,
killApp, killApp,
launchApp, launchApp,
nextBuild, nextBuild,
nextStart, nextStart,
retry,
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
...@@ -16,6 +16,17 @@ const appDir = join(__dirname, '../') ...@@ -16,6 +16,17 @@ const appDir = join(__dirname, '../')
let appPort let appPort
let app let app
const waitForModalOnIndexPage = async (browser) => {
await retry(async () => {
expect(await browser.elementByCss('#index').text()).toBe('index page')
expect(await browser.hasElementByCssSelector('#modal')).toBeTruthy()
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
imageId: '123',
})
})
}
const runTests = () => { const runTests = () => {
it('should allow manual href/as on index page', async () => { it('should allow manual href/as on index page', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
...@@ -26,12 +37,7 @@ const runTests = () => { ...@@ -26,12 +37,7 @@ const runTests = () => {
await browser.elementByCss('#to-modal').click() await browser.elementByCss('#to-modal').click()
expect(await browser.elementByCss('#index').text()).toBe('index page') await waitForModalOnIndexPage(browser)
expect(await browser.hasElementByCssSelector('#modal')).toBeTruthy()
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
imageId: '123',
})
await browser await browser
.elementByCss('#to-preview') .elementByCss('#to-preview')
...@@ -86,12 +92,7 @@ const runTests = () => { ...@@ -86,12 +92,7 @@ const runTests = () => {
.click() .click()
.waitForElementByCss('#index') .waitForElementByCss('#index')
expect(await browser.elementByCss('#index').text()).toBe('index page') await waitForModalOnIndexPage(browser)
expect(await browser.hasElementByCssSelector('#modal')).toBeTruthy()
expect(await browser.eval('window.beforeNav')).toBe(1)
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
imageId: '123',
})
await browser await browser
.elementByCss('#to-preview') .elementByCss('#to-preview')
...@@ -108,13 +109,11 @@ const runTests = () => { ...@@ -108,13 +109,11 @@ const runTests = () => {
expect(await browser.elementByCss('#preview').text()).toBe('preview page') expect(await browser.elementByCss('#preview').text()).toBe('preview page')
expect(await browser.eval('window.beforeNav')).toBe(1) expect(await browser.eval('window.beforeNav')).toBe(1)
await check( await retry(async () => {
async () => expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
JSON.parse( slug: '321',
await browser.eval('document.querySelector("#query").innerHTML') })
).slug, })
'321'
)
await browser await browser
.elementByCss('#to-another') .elementByCss('#to-another')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment