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

Stabilize rewrites manual href/as test

parent 25fe25b5
......@@ -2,12 +2,12 @@
import { join } from 'path'
import {
check,
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
retry,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
......@@ -16,6 +16,17 @@ const appDir = join(__dirname, '../')
let appPort
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 = () => {
it('should allow manual href/as on index page', async () => {
const browser = await webdriver(appPort, '/')
......@@ -26,12 +37,7 @@ const runTests = () => {
await browser.elementByCss('#to-modal').click()
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',
})
await waitForModalOnIndexPage(browser)
await browser
.elementByCss('#to-preview')
......@@ -86,12 +92,7 @@ const runTests = () => {
.click()
.waitForElementByCss('#index')
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',
})
await waitForModalOnIndexPage(browser)
await browser
.elementByCss('#to-preview')
......@@ -108,13 +109,11 @@ const runTests = () => {
expect(await browser.elementByCss('#preview').text()).toBe('preview page')
expect(await browser.eval('window.beforeNav')).toBe(1)
await check(
async () =>
JSON.parse(
await browser.eval('document.querySelector("#query").innerHTML')
).slug,
'321'
)
await retry(async () => {
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
slug: '321',
})
})
await browser
.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