From: Austin Akers Date: Tue, 7 Apr 2020 09:45:41 +0000 (-0500) Subject: test: onBeforeRouteLeave (#161) X-Git-Tag: v4.0.0-alpha.5~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a4cfe8f4489af24a0c09ff8196867b4248a1a00;p=thirdparty%2Fvuejs%2Frouter.git test: onBeforeRouteLeave (#161) [ci skip] --- diff --git a/e2e/navigation-guards/GuardedWithLeave.vue b/e2e/navigation-guards/GuardedWithLeave.vue new file mode 100644 index 00000000..0cf10074 --- /dev/null +++ b/e2e/navigation-guards/GuardedWithLeave.vue @@ -0,0 +1,30 @@ + + + diff --git a/e2e/navigation-guards/index.html b/e2e/navigation-guards/index.html new file mode 100644 index 00000000..81847f62 --- /dev/null +++ b/e2e/navigation-guards/index.html @@ -0,0 +1,28 @@ + + + + + + + Vue Router e2e tests - Navigation Guards + + + + + << Back to Homepage +
+ +
+ + + +
+ + diff --git a/e2e/navigation-guards/index.ts b/e2e/navigation-guards/index.ts new file mode 100644 index 00000000..64b08bc2 --- /dev/null +++ b/e2e/navigation-guards/index.ts @@ -0,0 +1,38 @@ +import { createRouter, createWebHistory, useRoute } from '../../src' +import { RouteComponent } from '../../src/types' +import { createApp } from 'vue' +import GuardedWithLeave from './GuardedWithLeave' + +// const component: RouteComponent = { +// template: `
A component
`, +// } + +const Home: RouteComponent = { + template: `
Home
`, +} + +// const Document: RouteComponent = { +// template: `
Document: {{ route.params.id }}
`, +// setup() { +// return { route: useRoute() } +// }, +// } + +const router = createRouter({ + history: createWebHistory('/' + __dirname), + routes: [ + { path: '/', component: Home, name: 'home' }, + { path: '/cant-leave', component: GuardedWithLeave }, + ], +}) + +const app = createApp({ + setup() { + const route = useRoute() + return { route } + }, +}) +app.use(router) + +window.vm = app.mount('#app') +window.r = router diff --git a/e2e/specs/navigation-guards.js b/e2e/specs/navigation-guards.js new file mode 100644 index 00000000..ae454c92 --- /dev/null +++ b/e2e/specs/navigation-guards.js @@ -0,0 +1,34 @@ +const bsStatus = require('../browserstack-send-status') + +const baseURL = 'http://localhost:8080/navigation-guards' + +module.exports = { + ...bsStatus(), + + /** @type {import('nightwatch').NightwatchTest} */ + 'blocks leaving navigation with onBeforeRouteLeave': function(browser) { + browser + .url(baseURL) + .assert.urlEquals(baseURL + '/') + .waitForElementVisible('#app', 1000) + .click('li:nth-child(2) a') + .assert.urlEquals(baseURL + '/cant-leave') + .assert.containsText('#tries', '0 times') + .click('li:nth-child(1) a') + .dismissAlert() + .waitFor(100) + .assert.urlEquals(baseURL + '/cant-leave') + .assert.containsText('#tries', '1 times') + .click('li:nth-child(1) a') + .dismissAlert() + .waitFor(100) + .assert.urlEquals(baseURL + '/cant-leave') + .assert.containsText('#tries', '2 times') + .click('li:nth-child(1) a') + .acceptAlert() + .waitFor(100) + .assert.urlEquals(baseURL + '/') + + .end() + }, +} diff --git a/e2e/webpack.config.js b/e2e/webpack.config.js index 88ba9d08..60a9441e 100644 --- a/e2e/webpack.config.js +++ b/e2e/webpack.config.js @@ -3,6 +3,7 @@ const fs = require('fs') const { resolve, join } = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') const webpack = require('webpack') +const { VueLoaderPlugin } = require('vue-loader') /** @type {string[]} */ let examples = [] @@ -58,6 +59,10 @@ const config = (env = {}) => ({ test: /\.ts$/, use: 'ts-loader', }, + { + test: /\.vue$/, + use: 'vue-loader', + }, { test: /\.css$/, use: ['style-loader', 'css-loader'], @@ -70,9 +75,10 @@ const config = (env = {}) => ({ 'vue-router': join(__dirname, '..', 'src'), }, // Add `.ts` and `.tsx` as a resolvable extension. - extensions: ['.ts', '.tsx', '.js'], + extensions: ['.ts', '.tsx', '.js', '.vue'], }, plugins: [ + new VueLoaderPlugin(), new webpack.DefinePlugin({ __DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'), __BROWSER__: `typeof window !== 'undefined'`,