import { createRoutes } from '../src/template/routes' ; import { PageMeta } from '../src/resolve' ; describe ( 'Route template' , ( ) => { it ( 'should generate routes' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , } , { name : 'bar' , chunkName : 'bar' , specifier : 'Bar' , path : '/bar' , pathSegments : [ 'bar' ] , component : '@/pages/bar.vue' , } , ] ; expect ( createRoutes ( meta , true , '' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should generate nested routes' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , children : [ { name : 'bar' , chunkName : 'bar' , specifier : 'FooBar' , path : 'bar' , pathSegments : [ 'foo' , 'bar' ] , component : '@/pages/bar.vue' , } , { name : 'baz' , chunkName : 'baz' , specifier : 'FooBaz' , path : 'baz' , pathSegments : [ 'foo' , 'baz' ] , component : '@/pages/baz.vue' , } , ] , } , ] ; expect ( createRoutes ( meta , true , '' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should generate static import code' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , } , { name : 'bar' , chunkName : 'bar' , specifier : 'Bar' , path : '/bar' , pathSegments : [ 'bar' ] , component : '@/pages/bar.vue' , } , ] ; expect ( createRoutes ( meta , false , '' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should generate route meta' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , routeMeta : { title : 'Hello' , } , } , ] ; expect ( createRoutes ( meta , false , '' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should merge route block into route record' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , route : { name : 'Test' , meta : { title : 'Hello' , } , props : true , } , } , ] ; expect ( createRoutes ( meta , false , '' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should configure chunk name prefix' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , } , { name : 'bar' , chunkName : 'bar' , specifier : 'Bar' , path : '/bar' , pathSegments : [ 'bar' ] , component : '@/pages/bar.vue' , } , ] ; expect ( createRoutes ( meta , true , 'page-' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should pick chunkName as a webpack chunk name' , ( ) => { const meta = [ { name : 'users' , chunkName : 'users-index' , specifier : 'users_index' , path : '/users' , pathSegments : [ 'users' ] , component : '@/pages/users/index.vue' , } , ] ; expect ( createRoutes ( meta , true , 'page-' ) ) . toMatchSnapshot ( ) ; } ) ; it ( 'should not include name if the route has a default child' , ( ) => { const meta = [ { name : 'foo' , chunkName : 'foo' , specifier : 'Foo' , path : '/foo' , pathSegments : [ 'foo' ] , component : '@/pages/foo.vue' , children : [ { name : 'foo' , chunkName : 'foo-index' , specifier : 'FooIndex' , path : '' , pathSegments : [ 'foo' ] , component : '@/pages/foo/index.vue' , } , ] , } , ] ; expect ( createRoutes ( meta , true , '' ) ) . toMatchSnapshot ( ) ; } ) ; } ) ;