Blame view

node_modules/bootstrap-vue/src/components/skeleton/skeleton-img.spec.js 3.82 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
import { mount } from '@vue/test-utils'
import { BSkeletonImg } from './skeleton-img'

describe('skeleton-img', () => {
  it('component has correct default layout', async () => {
    const wrapper = mount(BSkeletonImg)

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.classes()).toContain('b-aspect')
    expect(wrapper.find('.b-aspect-sizer').element.style.paddingBottom).toBe('56.25%')
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').exists()).toBe(true)
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').classes()).toContain(
      'b-skeleton-animate-wave'
    )

    wrapper.destroy()
  })

  it('`aspect` prop applies correct padding', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        aspect: '4:3'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.classes()).toContain('b-aspect')
    expect(wrapper.find('.b-aspect-sizer').exists()).toBe(true)
    expect(wrapper.find('.b-aspect-sizer').element.style.paddingBottom).toBe('75%')

    wrapper.destroy()
  })

  it('`no-aspect` prop removes wrapping `b-aspect`', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        noAspect: true
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.classes()).not.toContain('b-aspect')
    expect(wrapper.classes()).toContain('b-skeleton-img')
    expect(wrapper.find('.b-aspect-sizer').exists()).toBe(false)
    expect(wrapper.find('.b-aspect-content').exists()).toBe(false)

    wrapper.destroy()
  })

  it('`width` prop applies correct style to element', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        noAspect: true,
        width: '200px'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.element.style.width).toBe('200px')

    wrapper.destroy()
  })

  it('`height` prop applies correct style to element', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        noAspect: true,
        height: '200px'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.element.style.height).toBe('200px')

    wrapper.destroy()
  })

  it('`variant` prop adds `bg-[variant]` class', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        variant: 'primary'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').classes()).toContain('bg-primary')

    wrapper.destroy()
  })

  it('has class `b-skeleton-animate-fade` when `animation="fade"` is set', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        animation: 'fade'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').classes()).toContain(
      'b-skeleton-animate-fade'
    )

    wrapper.destroy()
  })

  it('`card-img` applies the correct class', async () => {
    const wrapper = mount(BSkeletonImg, {
      propsData: {
        cardImg: 'top'
      }
    })

    expect(wrapper).toBeDefined()
    expect(wrapper.element.tagName).toBe('DIV')
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').classes()).toContain('card-img-top')

    wrapper.destroy()
  })

  it('accepts custom classes', async () => {
    const wrapper = mount(BSkeletonImg, {
      context: {
        class: ['foobar']
      }
    })

    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').exists()).toBe(true)
    expect(wrapper.find('.b-aspect-content > .b-skeleton-img').classes()).toContain('foobar')

    wrapper.destroy()
  })
})