rt-sim-training-client/tests/unit/components/Breadcrumb.spec.js

98 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-12-31 13:38:54 +08:00
import { mount, createLocalVue } from '@vue/test-utils';
import VueRouter from 'vue-router';
import ElementUI from 'element-ui';
import Breadcrumb from '@/components/Breadcrumb/index.vue';
2019-07-02 16:29:52 +08:00
2020-12-31 13:38:54 +08:00
const localVue = createLocalVue();
localVue.use(VueRouter);
localVue.use(ElementUI);
2019-07-02 16:29:52 +08:00
const routes = [
2020-12-31 13:38:54 +08:00
{
path: '/',
name: 'home',
2019-07-02 16:29:52 +08:00
children: [{
2020-12-31 13:38:54 +08:00
path: 'dashboard',
name: 'dashboard'
2019-07-02 16:29:52 +08:00
}]
2020-12-31 13:38:54 +08:00
},
{
path: '/menu',
name: 'menu',
children: [{
path: 'menu1',
name: 'menu1',
meta: { title: 'menu1' },
children: [{
path: 'menu1-1',
name: 'menu1-1',
meta: { title: 'menu1-1' }
},
{
path: 'menu1-2',
name: 'menu1-2',
redirect: 'noredirect',
meta: { title: 'menu1-2' },
children: [{
path: 'menu1-2-1',
name: 'menu1-2-1',
meta: { title: 'menu1-2-1' }
},
{
path: 'menu1-2-2',
name: 'menu1-2-2'
}]
}]
}]
}];
2019-07-02 16:29:52 +08:00
const router = new VueRouter({
2020-12-31 13:38:54 +08:00
routes
});
2019-07-02 16:29:52 +08:00
describe('Breadcrumb.vue', () => {
2020-12-31 13:38:54 +08:00
const wrapper = mount(Breadcrumb, {
localVue,
router
});
it('dashboard', () => {
router.push('/dashboard');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(1);
});
it('normal route', () => {
router.push('/menu/menu1');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(2);
});
it('nested route', () => {
router.push('/menu/menu1/menu1-2/menu1-2-1');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(4);
});
it('no meta.title', () => {
router.push('/menu/menu1/menu1-2/menu1-2-2');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(3);
});
// it('click link', () => {
// router.push('/menu/menu1/menu1-2/menu1-2-2')
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
// const second = breadcrumbArray.at(1)
// const href = second.find('a').attributes().href
// expect(href).toBe('#/menu/menu1')
// })
// it('noRedirect', () => {
// router.push('/menu/menu1/menu1-2/menu1-2-1')
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
// const redirectBreadcrumb = breadcrumbArray.at(2)
// expect(redirectBreadcrumb.contains('a')).toBe(false)
// })
it('last breadcrumb', () => {
router.push('/menu/menu1/menu1-2/menu1-2-1');
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner');
const redirectBreadcrumb = breadcrumbArray.at(3);
expect(redirectBreadcrumb.contains('a')).toBe(false);
});
});