index.test.js 1.41 KB
Newer Older
1
import { getBreadcrumb } from './index';
jim's avatar
jim committed
2
import { urlToList } from '../_utils/pathTools';
jim's avatar
jim committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

const routerData = {
  '/dashboard/analysis': {
    name: '分析页',
  },
  '/userinfo': {
    name: '用户列表',
  },
  '/userinfo/:id': {
    name: '用户信息',
  },
  '/userinfo/:id/addr': {
    name: '收货订单',
  },
};
describe('test getBreadcrumb', () => {
  it('Simple url', () => {
jim's avatar
jim committed
20
    expect(getBreadcrumb(routerData, '/dashboard/analysis').name).toEqual('分析页');
jim's avatar
jim committed
21 22
  });
  it('Parameters url', () => {
jim's avatar
jim committed
23
    expect(getBreadcrumb(routerData, '/userinfo/2144').name).toEqual('用户信息');
jim's avatar
jim committed
24 25
  });
  it('The middle parameter url', () => {
jim's avatar
jim committed
26
    expect(getBreadcrumb(routerData, '/userinfo/2144/addr').name).toEqual('收货订单');
jim's avatar
jim committed
27 28
  });
  it('Loop through the parameters', () => {
jim's avatar
jim committed
29
    const urlNameList = urlToList('/userinfo/2144/addr').map(url => {
jim's avatar
jim committed
30 31 32 33 34 35
      return getBreadcrumb(routerData, url).name;
    });
    expect(urlNameList).toEqual(['用户列表', '用户信息', '收货订单']);
  });

  it('a path', () => {
jim's avatar
jim committed
36
    const urlNameList = urlToList('/userinfo').map(url => {
jim's avatar
jim committed
37 38 39 40 41
      return getBreadcrumb(routerData, url).name;
    });
    expect(urlNameList).toEqual(['用户列表']);
  });
  it('Secondary path', () => {
jim's avatar
jim committed
42
    const urlNameList = urlToList('/userinfo/2144').map(url => {
jim's avatar
jim committed
43 44 45 46 47
      return getBreadcrumb(routerData, url).name;
    });
    expect(urlNameList).toEqual(['用户列表', '用户信息']);
  });
});