From: Eduardo San Martin Morote Date: Fri, 2 Oct 2020 09:19:01 +0000 (+0200) Subject: test(e2e): add encoding tests X-Git-Tag: v4.0.0-beta.13~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=373203e6685766427828830b600a35759eb0f6e0;p=thirdparty%2Fvuejs%2Frouter.git test(e2e): add encoding tests --- diff --git a/e2e/encoding/index.ts b/e2e/encoding/index.ts index 7d454e32..bca03ef6 100644 --- a/e2e/encoding/index.ts +++ b/e2e/encoding/index.ts @@ -1,6 +1,6 @@ -import { createRouter, createWebHistory, useRoute } from '../../src' +import { createRouter, createWebHistory } from '../../src' import { RouteComponent } from '../../src/types' -import { createApp } from 'vue' +import { createApp, defineComponent } from 'vue' const component: RouteComponent = { template: `
A component
`, @@ -10,58 +10,68 @@ const Home: RouteComponent = { template: `
Home
`, } -const Document: RouteComponent = { - template: `
Document: {{ route.params.id }}
`, - setup() { - return { route: useRoute() } - }, -} +const ParamId = defineComponent({ + template: `
id: "{{ $route.params.id }}"
`, +}) + +// full URL / !"$&'()*+,:;<=>%3F@[]^`{|}?a= !"$&'()*+,/:;<=>?@[]^`{|}# !"#$&'()*+,:;<=>?@[]^`{|} const router = createRouter({ + // TODO: allow hash based history history: createWebHistory('/' + __dirname), routes: [ { path: '/', component: Home, name: 'home' }, - { path: '/documents/:id', name: 'docs', component: Document }, + { path: '/:id', component: ParamId, name: 'param' }, + { path: '/documents/:id', name: 'docs', component: ParamId }, { path: encodeURI('/n/€'), name: 'euro', component }, ], }) const app = createApp({ setup() { - const route = useRoute() - return { route } + const url = + '/' + + __dirname + + '/ !"%23$&\'()*+,%2F:;<=>%3F@[]^`{|}?a= !"$%26\'()*+,/:;<=>?@[]^`{|}# !"#$&\'()*+,/:;<=>?@[]^`{|}' + const urlObject = { + name: 'param', + params: { id: ' !"#$&\'()*+,/:;<=>?@[]^`{|}' }, + query: { 'a=': ' !"#$&\'()*+,/:;<=>?@[]^`{|}' }, + hash: '# !"#$&\'()*+,/:;<=>?@[]^`{|}', + } + return { url, urlObject } }, template: `
Name: -
{{ route.name }}
+
{{ $route.name }}
Params: -
{{ route.params }}
+
{{ $route.params }}
Query: -
{{ route.query }}
+
{{ $route.query }}
Hash: -
{{ route.hash }}
+
{{ $route.hash }}
FullPath: -
{{ route.fullPath }}
+
{{ $route.fullPath }}
path: -
{{ route.path }}
+
{{ $route.path }}

@@ -95,6 +105,15 @@ const app = createApp({ router) +
  • + Unencoded URL (force reload) +
  • +
  • + Encoded by router +
  • diff --git a/e2e/specs/encoding.js b/e2e/specs/encoding.js index ad288e42..e3e01967 100644 --- a/e2e/specs/encoding.js +++ b/e2e/specs/encoding.js @@ -2,6 +2,8 @@ const bsStatus = require('../browserstack-send-status') const baseURL = 'http://localhost:8080/encoding' +const rawText = ' !"#$&\'()*+,/:;<=>?@[]^`{|}' + module.exports = { ...bsStatus(), @@ -18,14 +20,23 @@ module.exports = { .assert.urlEquals(baseURL + '/documents/%E2%82%ACuro') .assert.containsText('#fullPath', '/documents/%E2%82%ACuro') .assert.containsText('#path', '/documents/%E2%82%ACuro') - .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2)) + .assert.containsText('#p-id', '"€uro"') + + // full encoding test + .click('li:nth-child(8) a') + browser.expect.element('#p-id').text.equals(`"${rawText}"`) + browser.expect + .element('#query') + .text.equals(JSON.stringify({ 'a=': rawText }, null, 2)) + browser.expect.element('#hash').text.equals('#' + rawText) - // check initial visit + // check initial visit + browser .url(baseURL + '/documents/%E2%82%ACuro') .waitForElementPresent('#app > *', 1000) .assert.containsText('#fullPath', '/documents/%E2%82%ACuro') .assert.containsText('#path', '/documents/%E2%82%ACuro') - .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2)) + .assert.containsText('#p-id', '"€uro"') // TODO: invalid in safari, tests on those where this is valid // .url(baseURL + '/unicode/€uro')