From 61f9b21fd06a1d6cc6dfdcd5a738d47d19cad0ae Mon Sep 17 00:00:00 2001 From: Alexandre Chopin Date: Fri, 10 Feb 2017 21:24:29 +0100 Subject: [PATCH] add tests for dynamic routes --- test/dynamic-routes.test.js | 82 ++++++++++--------- .../pages/test/projects/_category.vue | 0 .../pages/test/projects/index.vue | 0 .../pages/test/users/projects/_category.vue | 0 .../pages/test/users/projects/index.vue | 0 5 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 test/fixtures/dynamic-routes/pages/test/projects/_category.vue create mode 100644 test/fixtures/dynamic-routes/pages/test/projects/index.vue create mode 100644 test/fixtures/dynamic-routes/pages/test/users/projects/_category.vue create mode 100644 test/fixtures/dynamic-routes/pages/test/users/projects/index.vue diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js index 754fd114cb..e7ca8c9746 100644 --- a/test/dynamic-routes.test.js +++ b/test/dynamic-routes.test.js @@ -27,50 +27,56 @@ test('Check .nuxt/router.js', t => { // pages/index.vue t.is(routes[0].path, '/') t.is(routes[0].name, 'index') - // pages/test/songs/toto.vue - t.is(routes[1].path, '/test/songs/toto') - t.is(routes[1].name, 'test-songs-toto') - // pages/test/songs/_id.vue - t.is(routes[2].path, '/test/songs/:id?') - t.is(routes[2].name, 'test-songs-id') - // pages/test/users.vue - t.is(routes[3].path, '/test/users') - t.falsy(routes[3].name) // parent route has no name - // pages/test/users/*.vue - t.is(routes[3].children.length, 3) // parent has 3 children - t.deepEqual(routes[3].children.map((r) => r.path), ['', ':index/teub', ':id']) - t.deepEqual(routes[3].children.map((r) => r.name), ['test-users', 'test-users-index-teub', 'test-users-id']) - // pages/users/_id.vue - t.is(routes[4].path, '/users/:id?') - t.is(routes[4].name, 'users-id') - // pages/test/_.vue - t.is(routes[5].path, '/test/*') - t.is(routes[5].name, 'test-all') // pages/test/index.vue - t.is(routes[6].path, '/test') - t.is(routes[6].name, 'test') + t.is(routes[1].path, '/test') + t.is(routes[1].name, 'test') // pages/posts.vue - t.is(routes[7].path, '/posts') - t.is(routes[7].name, 'posts') - t.is(routes[7].children.length, 1) + t.is(routes[2].path, '/posts') + t.is(routes[2].name, 'posts') + t.is(routes[2].children.length, 1) // pages/posts/_id.vue - t.is(routes[7].children[0].path, ':id?') - t.is(routes[7].children[0].name, 'posts-id') + t.is(routes[2].children[0].path, ':id?') + t.is(routes[2].children[0].name, 'posts-id') // pages/parent.vue - t.is(routes[8].path, '/parent') - t.falsy(routes[8].name) // parent route has no name + t.is(routes[3].path, '/parent') + t.falsy(routes[3].name) // parent route has no name // pages/parent/*.vue - t.is(routes[8].children.length, 3) // parent has 3 children - t.deepEqual(routes[8].children.map((r) => r.path), ['', 'teub', 'child']) - t.deepEqual(routes[8].children.map((r) => r.name), ['parent', 'parent-teub', 'parent-child']) - // pages/_key/_id.vue - t.is(routes[9].path, '/:key/:id?') - t.is(routes[9].name, 'key-id') + t.is(routes[3].children.length, 3) // parent has 3 children + t.deepEqual(routes[3].children.map((r) => r.path), ['', 'teub', 'child']) + t.deepEqual(routes[3].children.map((r) => r.name), ['parent', 'parent-teub', 'parent-child']) + // pages/test/projects/index.vue + t.is(routes[4].path, '/test/projects') + t.is(routes[4].name, 'test-projects') + // pages/test/users.vue + t.is(routes[5].path, '/test/users') + t.falsy(routes[5].name) // parent route has no name + // pages/test/users/*.vue + t.is(routes[5].children.length, 5) // parent has 5 children + t.deepEqual(routes[5].children.map((r) => r.path), ['', 'projects', 'projects/:category', ':id', ':index/teub']) + t.deepEqual(routes[5].children.map((r) => r.name), ['test-users', 'test-users-projects', 'test-users-projects-category', 'test-users-id', 'test-users-index-teub']) + // pages/test/songs/toto.vue + t.is(routes[6].path, '/test/songs/toto') + t.is(routes[6].name, 'test-songs-toto') + // pages/test/songs/_id.vue + t.is(routes[7].path, '/test/songs/:id?') + t.is(routes[7].name, 'test-songs-id') + // pages/test/projects/_category.vue + t.is(routes[8].path, '/test/projects/:category') + t.is(routes[8].name, 'test-projects-category') + // pages/users/_id.vue + t.is(routes[9].path, '/users/:id?') + t.is(routes[9].name, 'users-id') + // pages/test/_.vue + t.is(routes[10].path, '/test/*') + t.is(routes[10].name, 'test-all') // pages/_slug.vue - t.is(routes[10].path, '/:slug') - t.is(routes[10].name, 'slug') + t.is(routes[11].path, '/:slug') + t.is(routes[11].name, 'slug') + // pages/_key/_id.vue + t.is(routes[12].path, '/:key/:id?') + t.is(routes[12].name, 'key-id') // pages/_.vue - t.is(routes[11].path, '/*') - t.is(routes[11].name, 'all') + t.is(routes[13].path, '/*') + t.is(routes[13].name, 'all') }) }) diff --git a/test/fixtures/dynamic-routes/pages/test/projects/_category.vue b/test/fixtures/dynamic-routes/pages/test/projects/_category.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/test/projects/index.vue b/test/fixtures/dynamic-routes/pages/test/projects/index.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/test/users/projects/_category.vue b/test/fixtures/dynamic-routes/pages/test/users/projects/_category.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/dynamic-routes/pages/test/users/projects/index.vue b/test/fixtures/dynamic-routes/pages/test/users/projects/index.vue new file mode 100644 index 0000000000..e69de29bb2