Blame view

node_modules/bootstrap-vue/src/components/card/card-body.spec.js 3.34 KB
4cd4fd28   郭伟龙   feat: 初始化项目
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { mount } from '@vue/test-utils'
import { BCardBody } from './card-body'

describe('card-body', () => {
  it('has root element "div"', async () => {
    const wrapper = mount(BCardBody)

    expect(wrapper.element.tagName).toBe('DIV')

    wrapper.destroy()
  })

  it('has class card-body', async () => {
    const wrapper = mount(BCardBody)

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes().length).toBe(1)

    wrapper.destroy()
  })

  it('has custom root element when prop bodyTag is set', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: {
          bodyTag: 'article'
        }
      }
    })

    expect(wrapper.element.tagName).toBe('ARTICLE')
    expect(wrapper.classes()).toContain('card-body')

    wrapper.destroy()
  })

  it('has class bg-info when prop bodyBgVariant=info', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: { bodyBgVariant: 'info' }
      }
    })

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes()).toContain('bg-info')
    expect(wrapper.classes().length).toBe(2)

    wrapper.destroy()
  })

  it('has class text-info when prop bodyTextVariant=info', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: { bodyTextVariant: 'info' }
      }
    })

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes()).toContain('text-info')
    expect(wrapper.classes().length).toBe(2)

    wrapper.destroy()
  })

  it('has class border-info when prop bodyBorderVariant=info', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: { bodyBorderVariant: 'info' }
      }
    })

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes()).toContain('border-info')
    expect(wrapper.classes().length).toBe(2)

    wrapper.destroy()
  })

  it('has all variant classes when all variant props set', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: {
          bodyTextVariant: 'info',
          bodyBgVariant: 'danger',
          bodyBorderVariant: 'dark'
        }
      }
    })

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes()).toContain('text-info')
    expect(wrapper.classes()).toContain('bg-danger')
    expect(wrapper.classes()).toContain('border-dark')
    expect(wrapper.classes().length).toBe(4)

    wrapper.destroy()
  })

  it('has class "card-img-overlay" when overlay="true"', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: {
          overlay: true
        }
      }
    })

    expect(wrapper.classes()).toContain('card-body')
    expect(wrapper.classes()).toContain('card-img-overlay')
    expect(wrapper.classes().length).toBe(2)

    wrapper.destroy()
  })

  it('has card-title when title prop is set', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: {
          title: 'title'
        }
      }
    })

    expect(wrapper.find('div.card-title')).toBeDefined()

    wrapper.destroy()
  })

  it('has card-sub-title when sub-title prop is set', async () => {
    const wrapper = mount(BCardBody, {
      context: {
        props: {
          subTitle: 'sub title'
        }
      }
    })

    expect(wrapper.find('div.card-subtitle')).toBeDefined()

    wrapper.destroy()
  })
})