@@ -3,23 +3,42 @@ import Router from '../src/router.js'
3
3
import IonVueRouter from '../src/components/ion-vue-router.vue'
4
4
5
5
describe ( 'IonVueRouter' , ( ) => {
6
- it ( 'Renders correctly' , ( ) => {
7
- Vue . use ( Router )
8
- Vue . config . ignoredElements . push ( / ^ i o n - / )
6
+ Vue . use ( Router )
7
+ Vue . config . ignoredElements . push ( / ^ i o n - / )
9
8
10
- const app = new Vue ( {
11
- render ( h ) {
12
- return h ( 'ion-vue-router' )
13
- } ,
14
- router : new Router ( {
15
- routes : [ { path : '/' , component : { template : '<h1>foo</h1>' } } ] ,
16
- } ) ,
17
- } ) . $mount ( )
9
+ const app = new Vue ( {
10
+ components : { Toolbar : Toolbar ( ) } ,
11
+ render ( h ) {
12
+ return h ( 'ion-vue-router' )
13
+ } ,
14
+ router : new Router ( {
15
+ mode : 'abstract' ,
16
+ routes : [ { path : '/' , component : Home ( ) } , { path : '/page' , component : Page ( ) } ] ,
17
+ } ) ,
18
+ } ) . $mount ( )
19
+
20
+ it ( 'Renders the home route correctly' , done => {
21
+ app . $router . push ( '/' )
22
+ setTimeout ( ( ) => {
23
+ expect ( app . $el . textContent . trim ( ) ) . toBe ( 'Home Go to page' )
24
+ done ( )
25
+ } , 1 )
26
+ } )
18
27
19
- app . $router . push ( '/foo' )
20
- app . $router . back ( )
28
+ it ( 'Renders the page route correctly' , done => {
29
+ app . $router . push ( '/page' )
30
+ setTimeout ( ( ) => {
31
+ expect ( app . $el . textContent . trim ( ) ) . toBe ( 'Page Go home' )
32
+ done ( )
33
+ } , 1 )
34
+ } )
21
35
22
- expect ( app . $el . textContent ) . toBe ( 'foo' )
36
+ it ( 'Renders back route correctly' , done => {
37
+ app . $router . go ( - 1 )
38
+ setTimeout ( ( ) => {
39
+ expect ( app . $el . textContent . trim ( ) ) . toBe ( 'Home Go to page' )
40
+ done ( )
41
+ } , 1 )
23
42
} )
24
43
25
44
it ( 'Sets the default data correctly' , ( ) => {
@@ -38,3 +57,51 @@ describe('IonVueRouter', () => {
38
57
expect ( component . name ) . toBe ( 'default' )
39
58
} )
40
59
} )
60
+
61
+ function Toolbar ( ) {
62
+ return Vue . component ( 'Toolbar' , {
63
+ name : 'Toolbar' ,
64
+ props : {
65
+ backURL : { type : String , default : '' } ,
66
+ title : { type : String , default : '' } ,
67
+ } ,
68
+ template : `
69
+ <ion-header>
70
+ <ion-toolbar>
71
+ <ion-buttons slot="start">
72
+ <ion-back-button :default-href="backURL"/>
73
+ </ion-buttons>
74
+ <ion-title>{{ title }}</ion-title>
75
+ </ion-toolbar>
76
+ </ion-header>` ,
77
+ } )
78
+ }
79
+
80
+ function Home ( ) {
81
+ return Vue . component ( 'Home' , {
82
+ template : `
83
+ <ion-page class="ion-page">
84
+ <toolbar title="Home"/>
85
+ <ion-content class="ion-content" padding>
86
+ <router-link to="/page">Go to page</router-link>
87
+ </ion-content>
88
+ </ion-page>` ,
89
+ } )
90
+ }
91
+
92
+ function Page ( ) {
93
+ return Vue . component ( 'Page' , {
94
+ methods : {
95
+ goHome ( ) {
96
+ this . $router . back ( )
97
+ } ,
98
+ } ,
99
+ template : `
100
+ <ion-page class="ion-page">
101
+ <toolbar title="Page"/>
102
+ <ion-content class="ion-content" padding>
103
+ <ion-button @click="goHome">Go home</ion-button>
104
+ </ion-content>
105
+ </ion-page>` ,
106
+ } )
107
+ }
0 commit comments