tab.spec.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { shallowMount, mount } from '@vue/test-utils'
  2. import Tab from '../tab.vue';
  3. import Vue from 'vue';
  4. describe('Tab.vue', () => {
  5. const wrapper = mount(Tab);
  6. it('页签类型为based', () => {
  7. wrapper.setProps({ type: 'based' });
  8. return Vue.nextTick().then(function () {
  9. expect(wrapper.contains('.based')).toBe(true);
  10. })
  11. });
  12. it('当前tab的位置', () => {
  13. wrapper.setProps({ positionNav: 'left' });
  14. return Vue.nextTick().then(function () {
  15. expect(wrapper.contains('.nut-tab-title-leftnav')).toBe(true);
  16. })
  17. });
  18. it('是否显示内容区域', () => {
  19. wrapper.setProps({ contentShow: true });
  20. return Vue.nextTick().then(function () {
  21. expect(wrapper.contains('.nut-tab-item')).toBe(true);
  22. })
  23. });
  24. it('禁止选择第一个标签', () => {
  25. wrapper.setData({ tabTitleList: [
  26. {
  27. tabTitle: "衣物",
  28. disable: true,
  29. iconUrl:
  30. "http://img13.360buyimg.com/uba/jfs/t27280/289/2061314663/2392/872e32ff/5bf76318Ndc80c1d8.jpg",
  31. content: "<p>衣物内容</p>"
  32. },
  33. {
  34. tabTitle: "日用品",
  35. iconUrl:
  36. "http://img13.360buyimg.com/uba/jfs/t30331/209/562746340/2190/6619973d/5bf763aaN6ff02099.jpg",
  37. content: "<p>日用品内容</p>"
  38. },
  39. {
  40. tabTitle: "运动器材",
  41. iconUrl:
  42. "http://img20.360buyimg.com/uba/jfs/t30346/262/553689202/2257/5dfa3983/5bf76407N72deabf4.jpg",
  43. content: "<p>运动器材内容</p>"
  44. },
  45. {
  46. tabTitle: "电影票",
  47. iconUrl:
  48. "http://img10.360buyimg.com/uba/jfs/t26779/215/2118525153/2413/470d1613/5bf767b2N075957b7.jpg",
  49. content: "<p>电影票内容</p>"
  50. }
  51. ] });
  52. return Vue.nextTick().then(function () {
  53. expect(wrapper.findAll('.nut-title-nav-leftnav').at(0).is('.nut-tab-disable')).toBe(true)
  54. })
  55. });
  56. it('是否显示关闭按钮', () => {
  57. wrapper.setProps({ closable: true });
  58. return Vue.nextTick().then(function () {
  59. expect(wrapper.contains('.close-btn')).toBe(true);
  60. })
  61. });
  62. it('当前默认选中的tab', () => {
  63. wrapper.setProps({ positionNav: 'top' });
  64. return Vue.nextTick().then(function () {
  65. expect(wrapper.findAll('.nut-title-nav-list').at(0).is('.nut-tab-active')).toBe(true)
  66. })
  67. });
  68. it('tab标签标题', () => {
  69. return Vue.nextTick().then(function () {
  70. expect(wrapper.findAll('.nut-tab-link').at(0).text()).toBe('衣物');
  71. })
  72. });
  73. it('点击tab标签', () => {
  74. return Vue.nextTick().then(function () {
  75. wrapper.findAll('.nut-title-nav-list').at(1).trigger('click');
  76. expect(wrapper.findAll('.nut-title-nav-list').at(1).is('.nut-tab-active')).toBe(true)
  77. })
  78. });
  79. });