From 1a32cb76379c8733d8b7dad28da215f8325437b1 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 8 Apr 2020 12:36:59 +0200 Subject: [PATCH] test(e2e): add hash test --- e2e/hash/index.html | 69 ++++++++++++++------------------------------- e2e/hash/index.ts | 22 ++++++++------- e2e/specs/hash.js | 59 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 58 deletions(-) create mode 100644 e2e/specs/hash.js diff --git a/e2e/hash/index.html b/e2e/hash/index.html index 673c2020..6290ca22 100644 --- a/e2e/hash/index.html +++ b/e2e/hash/index.html @@ -13,70 +13,43 @@
-
- Name: -
{{ route.name }}
-
- -
- Params: -
{{ route.params }}
-
- -
- Query: -
{{ route.query }}
-
- -
- Hash: -
{{ route.hash }}
-
- -
- FullPath: -
{{ route.fullPath }}
-
- -
- path: -
{{ route.path }}
-
- -
- +

+ path: {{ route.path }} +
+ query.t: {{ route.query.t }} +
+ hash: {{ route.hash }} +

+
diff --git a/e2e/hash/index.ts b/e2e/hash/index.ts index 06b13ca4..a64543dd 100644 --- a/e2e/hash/index.ts +++ b/e2e/hash/index.ts @@ -2,28 +2,29 @@ import { createRouter, useRoute, createWebHashHistory } from '../../src' import { RouteComponent } from '../../src/types' import { createApp } from 'vue' -const component: RouteComponent = { - template: `
A component
`, -} - const Home: RouteComponent = { - template: `
Home
`, + template: `
home
`, } -const Document: RouteComponent = { +const Foo: RouteComponent = { template: '
foo
' } +const Bar: RouteComponent = { template: '
bar
' } + +const Unicode: RouteComponent = { setup() { const route = useRoute() return { route } }, - template: `
Document: {{ route.params.id }}
`, + template: `
param: {{ route.params.id }}
`, } const router = createRouter({ history: createWebHashHistory('/' + __dirname), routes: [ - { path: '/', component: Home, name: 'home' }, - { path: '/documents/:id', name: 'docs', component: Document }, - { path: encodeURI('/n/€'), name: 'euro', component }, + { path: '/', component: Home }, + { path: '/foo', component: Foo }, + { path: '/bar', component: Bar }, + { path: '/unicode/:id', name: 'unicode', component: Unicode }, + { path: encodeURI('/n/é'), name: 'encoded', component: Foo }, ], }) @@ -35,4 +36,5 @@ const app = createApp({ }) app.use(router) +window.r = router window.vm = app.mount('#app') diff --git a/e2e/specs/hash.js b/e2e/specs/hash.js new file mode 100644 index 00000000..bb8c89e9 --- /dev/null +++ b/e2e/specs/hash.js @@ -0,0 +1,59 @@ +const bsStatus = require('../browserstack-send-status') + +const baseURL = 'http://localhost:8080/hash/#' + +module.exports = { + ...bsStatus(), + + '@tags': ['hash', 'encoding'], + + /** @type {import('nightwatch').NightwatchTest} */ + 'navigating to links': function(browser) { + browser + .url(baseURL) + .waitForElementVisible('#app', 1000) + .assert.attributeContains('li:nth-child(1) a', 'href', '/hash/#/') + .assert.attributeContains('li:nth-child(2) a', 'href', '/hash/#/foo') + .assert.attributeContains('li:nth-child(3) a', 'href', '/hash/#/bar') + .assert.attributeContains('li:nth-child(4) a', 'href', '/hash/#/n/%C3%A9') + .assert.attributeContains( + 'li:nth-child(5) a', + 'href', + '/hash/#/unicode/%C3%A9' + ) + .click('li:nth-child(3) a') + .assert.urlEquals(baseURL + '/bar') + .click('li:nth-child(2) a') + .assert.urlEquals(baseURL + '/foo') + .click('li:nth-child(4) a') + .assert.urlEquals(baseURL + '/n/%C3%A9') + .assert.containsText('#path', '/n/%C3%A9') + + // the correctly encoded version + .click('li:nth-child(6) a') + .assert.urlEquals(baseURL + '/unicode/%C3%A9') + .assert.containsText('#path', '/unicode/%C3%A9') + .assert.containsText('#param', 'é') + // the unencoded version, no check for the url because changes based on browser + .click('li:nth-child(5) a') + .assert.containsText('#param', 'é') + + .end() + }, + + /** @type {import('nightwatch').NightwatchTest} */ + 'encoding on initial navigation': function(browser) { + browser + .url(baseURL + '/unicode/é') + // navigation to unencoded value + // depending on the browser the value will be encoded or not + .assert.containsText('#param', 'é') + .url(baseURL + '/unicode/%C3%A9') + // navigation to unencoded value + .assert.urlEquals(baseURL + '/unicode/%C3%A9') + .assert.containsText('#path', '/unicode/%C3%A9') + .assert.containsText('#param', 'é') + + .end() + }, +} -- 2.47.2