all files / tests/unit/ tabs.spec.js

100% Statements 32/32
100% Branches 0/0
100% Functions 10/10
100% Lines 32/32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122                                                                                                                                                                                   
import chai, { expect } from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
chai.use(sinonChai)
import { mount } from '@vue/test-utils'
 
import Vue from 'vue'
import Tabs from '../../src/tabs/tabs'
import TabsHeader from '../../src/tabs/tabsHeader'
import TabsBody from '../../src/tabs/tabsBody'
import TabsItem from '../../src/tabs/tabsItem'
import TabsPane from '../../src/tabs/tabsPane'
 
Vue.component('am-tabs', Tabs)
Vue.component('am-tabs-header', TabsHeader)
Vue.component('am-tabs-body', TabsBody)
Vue.component('am-tabs-item', TabsItem)
Vue.component('am-tabs-pane', TabsPane)
 
describe('Tabs', () => {
  it('存在.', () => {
    expect(Tabs).to.be.ok
  })
  it('接受 selected 属性', done => {
    const wrapper = mount(Tabs, {
      propsData: {
        selected: 'music'
      },
      slots: {
        default: `
            <am-tabs-header>
                <am-tabs-item name="sport">sport</am-tabs-item>
                <am-tabs-item name="music">music</am-tabs-item>
                <am-tabs-item name="moving">moving</am-tabs-item>
            </am-tabs-header>
            <am-tabs-body>
                <am-tabs-pane name="sport">sport content</am-tabs-pane>
                <am-tabs-pane name="music">music content</am-tabs-pane>
                <am-tabs-pane name="moving">moving content</am-tabs-pane>
            </am-tabs-body>
              `
      }
    })
    setTimeout(() => {
      const element = wrapper.find('.am-tabs-item[data-name="music"]')
      expect(element.exists()).to.be.true
      expect(wrapper.find('.am-tabs-pane[data-name="music"]').isVisible()).to.be
        .true
      done()
    })
  })
  it('可以设置 direction .', done => {
    const wrapper = mount(Tabs, {
      propsData: {
        selected: 'music',
        direction: 'vertical'
      },
      slots: {
        default: `
            <am-tabs-header>
                <am-tabs-item name="sport">sport</am-tabs-item>
                <am-tabs-item name="music">music</am-tabs-item>
                <am-tabs-item name="moving">moving</am-tabs-item>
            </am-tabs-header>
            <am-tabs-body>
                <am-tabs-pane name="sport">sport content</am-tabs-pane>
                <am-tabs-pane name="music">music content</am-tabs-pane>
                <am-tabs-pane name="moving">moving content</am-tabs-pane>
            </am-tabs-body>
              `
      }
    })
    setTimeout(() => {
      const element = wrapper.find('.am-tabs-item[data-name="music"].vertical')
      expect(element.exists()).to.be.true
      done()
    })
  })
 
  it('可以设置 lineWidthOrHeight .', done => {
    const wrapper = mount(Tabs, {
      propsData: {
        selected: 'music',
        lineWidthOrHeight: 24
      },
      slots: {
        default: `
            <am-tabs-header>
                <am-tabs-item name="sport">sport</am-tabs-item>
                <am-tabs-item name="music">music</am-tabs-item>
                <am-tabs-item name="moving">moving</am-tabs-item>
            </am-tabs-header>
            <am-tabs-body>
                <am-tabs-pane name="sport">sport content</am-tabs-pane>
                <am-tabs-pane name="music">music content</am-tabs-pane>
                <am-tabs-pane name="moving">moving content</am-tabs-pane>
            </am-tabs-body>
              `
      }
    })
    setTimeout(() => {
      expect(wrapper.props().lineWidthOrHeight).to.eq(24)
      done()
    })
  })
 
  it('没有子组件时为空 .', done => {
    const wrapper = mount(Tabs, {
      propsData: {
        selected: 'music'
      },
      slots: {
        default: ''
      }
    })
    setTimeout(() => {
      expect(wrapper.isEmpty()).to.be.true
      done()
    })
  })
})