table-thead-top.spec.js
2.63 KB
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
import { mount } from '@vue/test-utils'
import { normalizeFields } from './helpers/normalize-fields'
import { BTable } from './table'
const testItems = [{ a: 1, b: 2, c: 3 }, { a: 5, b: 5, c: 6 }, { a: 7, b: 8, c: 9 }]
const testFields = ['a', 'b', 'c']
describe('table > thead thead-top slot', () => {
it('should not have thead-top row by default', async () => {
const wrapper = mount(BTable, {
propsData: {
fields: testFields,
items: testItems
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
expect(wrapper.find('thead').exists()).toBe(true)
expect(wrapper.findAll('thead > tr').exists()).toBe(true)
expect(wrapper.findAll('thead > tr').length).toBe(1)
wrapper.destroy()
})
it('should render named slot `thead-top`', async () => {
const wrapper = mount(BTable, {
propsData: {
fields: testFields,
items: testItems
},
slots: {
'thead-top': `<tr class="test"><th span="${testFields.length}">foobar</th></tr>`
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
expect(wrapper.find('thead').exists()).toBe(true)
expect(wrapper.findAll('thead > tr').exists()).toBe(true)
expect(wrapper.findAll('thead > tr').length).toBe(2)
expect(
wrapper
.findAll('thead > tr')
.at(0)
.text()
).toBe('foobar')
expect(
wrapper
.findAll('thead > tr')
.at(0)
.classes()
).toContain('test')
wrapper.destroy()
})
it('should render scoped slot `thead-top`', async () => {
let fields = []
let columns
const wrapper = mount(BTable, {
propsData: {
fields: testFields,
items: testItems
},
scopedSlots: {
'thead-top': function(scope) {
fields = scope.fields
columns = scope.columns
return this.$createElement('tr', { class: 'test' }, [
this.$createElement('th', { attrs: { span: columns } }, 'foobar')
])
}
}
})
expect(wrapper).toBeDefined()
expect(wrapper.element.tagName).toBe('TABLE')
expect(wrapper.find('thead').exists()).toBe(true)
expect(columns).toBe(3)
expect(fields).toEqual(normalizeFields(testFields))
expect(wrapper.findAll('thead > tr').exists()).toBe(true)
expect(wrapper.findAll('thead > tr').length).toBe(2)
expect(
wrapper
.findAll('thead > tr')
.at(0)
.text()
).toBe('foobar')
expect(
wrapper
.findAll('thead > tr')
.at(0)
.classes()
).toContain('test')
wrapper.destroy()
})
})