]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: test out-in nested transitions
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 2 Dec 2020 18:02:09 +0000 (19:02 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 2 Dec 2020 18:02:09 +0000 (19:02 +0100)
e2e/specs/transitions.js
e2e/transitions/index.ts

index e5e7954656c5a5b0ff8cfc1a93725c4e76fdce10..8506730190bc27f3f4d00106192b42d8dfa723ed 100644 (file)
@@ -51,4 +51,20 @@ module.exports = {
 
       .end()
   },
+
+  'out in transitions': function (browser) {
+    browser
+      .url('http://localhost:8080/transitions/')
+      .waitForElementPresent('#app > *', 1000)
+      .click('#toggle-transition')
+
+      .click('li:nth-child(7) a')
+      .assert.containsText('.nested-view', 'foo')
+      .click('li:nth-child(1) a')
+      .waitForElementPresent('.view.home', 1000)
+      .click('li:nth-child(7) a')
+      .assert.containsText('.nested-view', 'foo')
+
+      .end()
+  },
 }
index 9a4dc9ca45be94971c8388ca3bdc2d2b778eef9c..d45d4b830b42ecf7898f449a944997f4daecfe26 100644 (file)
@@ -1,6 +1,6 @@
-import { createRouter, createWebHistory, useRoute } from '../../src'
+import { createRouter, createWebHistory } from '../../src'
 import { RouteComponent } from '../../src/types'
-import { createApp, nextTick } from 'vue'
+import { createApp, defineComponent, nextTick, ref } from 'vue'
 
 const Home: RouteComponent = {
   template: `
@@ -56,6 +56,16 @@ const Parent: RouteComponent = {
   `,
 }
 
+const NestedTransition = defineComponent({
+  template: `
+      <router-view class="nested-view" mode="out-in" v-slot="{ Component }">
+        <transition name="none">
+          <component :is="Component" />
+        </transition>
+      </router-view>
+  `,
+})
+
 const Default: RouteComponent = {
   template: '<div class="default">default</div>',
 }
@@ -76,13 +86,28 @@ const router = createRouter({
         { path: 'bar', component: Bar },
       ],
     },
+
+    {
+      path: '/nested',
+      component: NestedTransition,
+      children: [
+        { path: '', component: Default },
+        { path: 'foo', component: Foo },
+        { path: 'bar', component: Bar },
+      ],
+    },
   ],
 })
 const app = createApp({
   setup() {
+    const transitionName = ref('fade')
+    function toggleTransition() {
+      transitionName.value = transitionName.value === 'fade' ? 'none' : 'fade'
+    }
+
     return {
-      show: true,
-      route: useRoute(),
+      transitionName,
+      toggleTransition,
     }
   },
 
@@ -90,15 +115,20 @@ const app = createApp({
     <div id="app">
       <h1>Transitions</h1>
       <pre>CI: ${__CI__}</pre>
+      <button id="toggle-transition" @click="toggleTransition">Toggle Transition</button>
       <ul>
         <li><router-link to="/">/</router-link></li>
         <li><router-link to="/parent">/parent</router-link></li>
         <li><router-link to="/parent/foo">/parent/foo</router-link></li>
         <li><router-link to="/parent/bar">/parent/bar</router-link></li>
         <li><router-link to="/not-found">Not existing</router-link></li>
+
+        <li><router-link to="/nested">/nested</router-link></li>
+        <li><router-link to="/nested/foo">/nested/foo</router-link></li>
+        <li><router-link to="/nested/bar">/nested/bar</router-link></li>
       </ul>
       <router-view class="view" v-slot="{ Component }">
-        <transition name="fade" mode="out-in">
+        <transition :name="transitionName" mode="out-in">
           <component :is="Component" />
         </transition>
       </router-view>