This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
94 lines (70 loc) · 2.9 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* eslint-env jest */
import { join } from 'path'
import webdriver from 'next-webdriver'
import {
launchApp,
killApp,
findPort,
nextBuild,
nextStart,
check,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '..')
let appPort
let app
const runTests = () => {
it('should update props on locale change with same hash', async () => {
const browser = await webdriver(appPort, `/about#hash`)
await browser.elementByCss('#change-locale').click()
await check(() => browser.eval('window.location.pathname'), '/fr/about')
await check(() => browser.eval('window.location.hash'), '#hash')
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')
expect(await browser.elementByCss('#props-locale').text()).toBe('fr')
await browser.elementByCss('#change-locale').click()
await check(() => browser.eval('window.location.pathname'), '/about')
await check(() => browser.eval('window.location.hash'), '#hash')
expect(await browser.elementByCss('#router-locale').text()).toBe('en')
expect(await browser.elementByCss('#props-locale').text()).toBe('en')
})
it('should update props on locale change with same hash (dynamic page)', async () => {
const browser = await webdriver(appPort, `/posts/a#hash`)
await browser.elementByCss('#change-locale').click()
await check(() => browser.eval('window.location.pathname'), '/fr/posts/a')
await check(() => browser.eval('window.location.hash'), '#hash')
expect(await browser.elementByCss('#router-locale').text()).toBe('fr')
expect(await browser.elementByCss('#props-locale').text()).toBe('fr')
await browser.elementByCss('#change-locale').click()
await check(() => browser.eval('window.location.pathname'), '/posts/a')
await check(() => browser.eval('window.location.hash'), '#hash')
expect(await browser.elementByCss('#router-locale').text()).toBe('en')
expect(await browser.elementByCss('#props-locale').text()).toBe('en')
})
it('should trigger hash change events', async () => {
const browser = await webdriver(appPort, `/about#hash`)
await check(() => browser.eval('window.location.hash'), '#hash')
await browser.elementByCss('#hash-change').click()
await check(() => browser.eval('window.hashChangeStart'), 'yes')
await check(() => browser.eval('window.hashChangeComplete'), 'yes')
await check(() => browser.eval('window.location.hash'), '#newhash')
})
}
describe('Hash changes i18n', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
})