Skip to content

Commit 373203e

Browse files
committed
test(e2e): add encoding tests
1 parent a967e42 commit 373203e

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

e2e/encoding/index.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createRouter, createWebHistory, useRoute } from '../../src'
1+
import { createRouter, createWebHistory } from '../../src'
22
import { RouteComponent } from '../../src/types'
3-
import { createApp } from 'vue'
3+
import { createApp, defineComponent } from 'vue'
44

55
const component: RouteComponent = {
66
template: `<div>A component</div>`,
@@ -10,58 +10,68 @@ const Home: RouteComponent = {
1010
template: `<div>Home</div>`,
1111
}
1212

13-
const Document: RouteComponent = {
14-
template: `<div>Document: {{ route.params.id }}</div>`,
15-
setup() {
16-
return { route: useRoute() }
17-
},
18-
}
13+
const ParamId = defineComponent({
14+
template: `<div>id: <span id="p-id">"{{ $route.params.id }}"</span></div>`,
15+
})
16+
17+
// full URL / !"$&'()*+,:;<=>%3F@[]^`{|}?a= !"$&'()*+,/:;<=>?@[]^`{|}# !"#$&'()*+,:;<=>?@[]^`{|}
1918

2019
const router = createRouter({
20+
// TODO: allow hash based history
2121
history: createWebHistory('/' + __dirname),
2222
routes: [
2323
{ path: '/', component: Home, name: 'home' },
24-
{ path: '/documents/:id', name: 'docs', component: Document },
24+
{ path: '/:id', component: ParamId, name: 'param' },
25+
{ path: '/documents/:id', name: 'docs', component: ParamId },
2526
{ path: encodeURI('/n/€'), name: 'euro', component },
2627
],
2728
})
2829

2930
const app = createApp({
3031
setup() {
31-
const route = useRoute()
32-
return { route }
32+
const url =
33+
'/' +
34+
__dirname +
35+
'/ !"%23$&\'()*+,%2F:;<=>%3F@[]^`{|}?a= !"$%26\'()*+,/:;<=>?@[]^`{|}# !"#$&\'()*+,/:;<=>?@[]^`{|}'
36+
const urlObject = {
37+
name: 'param',
38+
params: { id: ' !"#$&\'()*+,/:;<=>?@[]^`{|}' },
39+
query: { 'a=': ' !"#$&\'()*+,/:;<=>?@[]^`{|}' },
40+
hash: '# !"#$&\'()*+,/:;<=>?@[]^`{|}',
41+
}
42+
return { url, urlObject }
3343
},
3444

3545
template: `
3646
<div id="app">
3747
<section class="info">
3848
Name:
39-
<pre id="name">{{ route.name }}</pre>
49+
<pre id="name">{{ $route.name }}</pre>
4050
</section>
4151
4252
<section class="info">
4353
Params:
44-
<pre id="params">{{ route.params }}</pre>
54+
<pre id="params">{{ $route.params }}</pre>
4555
</section>
4656
4757
<section class="info">
4858
Query:
49-
<pre id="query">{{ route.query }}</pre>
59+
<pre id="query">{{ $route.query }}</pre>
5060
</section>
5161
5262
<section class="info">
5363
Hash:
54-
<pre id="hash">{{ route.hash }}</pre>
64+
<pre id="hash">{{ $route.hash }}</pre>
5565
</section>
5666
5767
<section class="info">
5868
FullPath:
59-
<pre id="fullPath">{{ route.fullPath }}</pre>
69+
<pre id="fullPath">{{ $route.fullPath }}</pre>
6070
</section>
6171
6272
<section class="info">
6373
path:
64-
<pre id="path">{{ route.path }}</pre>
74+
<pre id="path">{{ $route.path }}</pre>
6575
</section>
6676
6777
<hr />
@@ -95,6 +105,15 @@ const app = createApp({
95105
router)</a
96106
>
97107
</li>
108+
<li>
109+
<a :href="url"
110+
>Unencoded URL (force reload)</a
111+
>
112+
</li>
113+
<li>
114+
<router-link :to="urlObject"
115+
>Encoded by router</router-link>
116+
</li>
98117
</ul>
99118
100119
<router-view></router-view>

e2e/specs/encoding.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const bsStatus = require('../browserstack-send-status')
22

33
const baseURL = 'http://localhost:8080/encoding'
44

5+
const rawText = ' !"#$&\'()*+,/:;<=>?@[]^`{|}'
6+
57
module.exports = {
68
...bsStatus(),
79

@@ -18,14 +20,23 @@ module.exports = {
1820
.assert.urlEquals(baseURL + '/documents/%E2%82%ACuro')
1921
.assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
2022
.assert.containsText('#path', '/documents/%E2%82%ACuro')
21-
.assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
23+
.assert.containsText('#p-id', '"€uro"')
24+
25+
// full encoding test
26+
.click('li:nth-child(8) a')
27+
browser.expect.element('#p-id').text.equals(`"${rawText}"`)
28+
browser.expect
29+
.element('#query')
30+
.text.equals(JSON.stringify({ 'a=': rawText }, null, 2))
31+
browser.expect.element('#hash').text.equals('#' + rawText)
2232

23-
// check initial visit
33+
// check initial visit
34+
browser
2435
.url(baseURL + '/documents/%E2%82%ACuro')
2536
.waitForElementPresent('#app > *', 1000)
2637
.assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
2738
.assert.containsText('#path', '/documents/%E2%82%ACuro')
28-
.assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
39+
.assert.containsText('#p-id', '"€uro"')
2940

3041
// TODO: invalid in safari, tests on those where this is valid
3142
// .url(baseURL + '/unicode/€uro')

0 commit comments

Comments
 (0)