天波用户运营管理后台系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { mount, createLocalVue } from '@vue/test-utils'
  2. import VueRouter from 'vue-router'
  3. import ElementUI from 'element-ui'
  4. import Breadcrumb from '@/components/Breadcrumb/index.vue'
  5. const localVue = createLocalVue()
  6. localVue.use(VueRouter)
  7. localVue.use(ElementUI)
  8. const routes = [
  9. {
  10. path: '/',
  11. name: 'home',
  12. children: [{
  13. path: 'dashboard',
  14. name: 'dashboard'
  15. }]
  16. },
  17. {
  18. path: '/menu',
  19. name: 'menu',
  20. children: [{
  21. path: 'menu1',
  22. name: 'menu1',
  23. meta: { title: 'menu1' },
  24. children: [{
  25. path: 'menu1-1',
  26. name: 'menu1-1',
  27. meta: { title: 'menu1-1' }
  28. },
  29. {
  30. path: 'menu1-2',
  31. name: 'menu1-2',
  32. redirect: 'noredirect',
  33. meta: { title: 'menu1-2' },
  34. children: [{
  35. path: 'menu1-2-1',
  36. name: 'menu1-2-1',
  37. meta: { title: 'menu1-2-1' }
  38. },
  39. {
  40. path: 'menu1-2-2',
  41. name: 'menu1-2-2'
  42. }]
  43. }]
  44. }]
  45. }]
  46. const router = new VueRouter({
  47. routes
  48. })
  49. describe('Breadcrumb.vue', () => {
  50. const wrapper = mount(Breadcrumb, {
  51. localVue,
  52. router
  53. })
  54. it('dashboard', () => {
  55. router.push('/dashboard')
  56. const len = wrapper.findAll('.el-breadcrumb__inner').length
  57. expect(len).toBe(1)
  58. })
  59. it('normal route', () => {
  60. router.push('/menu/menu1')
  61. const len = wrapper.findAll('.el-breadcrumb__inner').length
  62. expect(len).toBe(2)
  63. })
  64. it('nested route', () => {
  65. router.push('/menu/menu1/menu1-2/menu1-2-1')
  66. const len = wrapper.findAll('.el-breadcrumb__inner').length
  67. expect(len).toBe(4)
  68. })
  69. it('no meta.title', () => {
  70. router.push('/menu/menu1/menu1-2/menu1-2-2')
  71. const len = wrapper.findAll('.el-breadcrumb__inner').length
  72. expect(len).toBe(3)
  73. })
  74. // it('click link', () => {
  75. // router.push('/menu/menu1/menu1-2/menu1-2-2')
  76. // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
  77. // const second = breadcrumbArray.at(1)
  78. // console.log(breadcrumbArray)
  79. // const href = second.find('a').attributes().href
  80. // expect(href).toBe('#/menu/menu1')
  81. // })
  82. // it('noRedirect', () => {
  83. // router.push('/menu/menu1/menu1-2/menu1-2-1')
  84. // const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
  85. // const redirectBreadcrumb = breadcrumbArray.at(2)
  86. // expect(redirectBreadcrumb.contains('a')).toBe(false)
  87. // })
  88. it('last breadcrumb', () => {
  89. router.push('/menu/menu1/menu1-2/menu1-2-1')
  90. const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
  91. const redirectBreadcrumb = breadcrumbArray.at(3)
  92. expect(redirectBreadcrumb.contains('a')).toBe(false)
  93. })
  94. })