|
| 1 | +import { mount } from '@vue/test-utils' |
| 2 | +import { BTable } from './table' |
| 3 | + |
| 4 | +const testItems = [{ a: 1, b: 2, c: 3 }] |
| 5 | +const testFields = [{ key: 'a', label: 'A' }, { key: 'b', label: 'B' }, { key: 'c', label: 'C' }] |
| 6 | + |
| 7 | +describe('table > custom tfoot slot', () => { |
| 8 | + it('should not render tfoot by default', async () => { |
| 9 | + const wrapper = mount(BTable, { |
| 10 | + propsData: { |
| 11 | + fields: testFields, |
| 12 | + items: testItems, |
| 13 | + footClone: false |
| 14 | + } |
| 15 | + }) |
| 16 | + expect(wrapper).toBeDefined() |
| 17 | + expect(wrapper.is('table')).toBe(true) |
| 18 | + expect(wrapper.find('thead').exists()).toBe(true) |
| 19 | + expect(wrapper.find('tbody').exists()).toBe(true) |
| 20 | + expect(wrapper.find('tfoot').exists()).toBe(false) |
| 21 | + |
| 22 | + wrapper.destroy() |
| 23 | + }) |
| 24 | + |
| 25 | + it('should render custom-foot slot inside b-tfoot', async () => { |
| 26 | + const wrapper = mount(BTable, { |
| 27 | + propsData: { |
| 28 | + fields: testFields, |
| 29 | + items: testItems, |
| 30 | + footClone: false |
| 31 | + }, |
| 32 | + slots: { |
| 33 | + 'custom-foot': '<tr><td colspan="3">CUSTOM-FOOTER</td></tr>' |
| 34 | + } |
| 35 | + }) |
| 36 | + expect(wrapper).toBeDefined() |
| 37 | + expect(wrapper.is('table')).toBe(true) |
| 38 | + expect(wrapper.find('thead').exists()).toBe(true) |
| 39 | + expect(wrapper.find('tbody').exists()).toBe(true) |
| 40 | + expect(wrapper.find('tfoot').exists()).toBe(true) |
| 41 | + expect(wrapper.find('tfoot').text()).toContain('CUSTOM-FOOTER') |
| 42 | + expect(wrapper.find('tfoot').classes().length).toBe(0) |
| 43 | + |
| 44 | + wrapper.destroy() |
| 45 | + }) |
| 46 | + |
| 47 | + it('should not render custom-foot slot when foot-clone is true', async () => { |
| 48 | + const wrapper = mount(BTable, { |
| 49 | + propsData: { |
| 50 | + fields: testFields, |
| 51 | + items: testItems, |
| 52 | + footClone: true |
| 53 | + }, |
| 54 | + slots: { |
| 55 | + 'custom-foot': '<tr><td colspan="3">CUSTOM-FOOTER</td></tr>' |
| 56 | + } |
| 57 | + }) |
| 58 | + expect(wrapper).toBeDefined() |
| 59 | + expect(wrapper.is('table')).toBe(true) |
| 60 | + expect(wrapper.find('thead').exists()).toBe(true) |
| 61 | + expect(wrapper.find('tbody').exists()).toBe(true) |
| 62 | + expect(wrapper.find('tfoot').exists()).toBe(true) |
| 63 | + expect(wrapper.find('tfoot').text()).not.toContain('CUSTOM-FOOTER') |
| 64 | + |
| 65 | + wrapper.destroy() |
| 66 | + }) |
| 67 | + |
| 68 | + it('should have foot-variant on custom-foot slot', async () => { |
| 69 | + const wrapper = mount(BTable, { |
| 70 | + propsData: { |
| 71 | + fields: testFields, |
| 72 | + items: testItems, |
| 73 | + footClone: false, |
| 74 | + footVariant: 'dark' |
| 75 | + }, |
| 76 | + slots: { |
| 77 | + 'custom-foot': '<tr><td colspan="3">CUSTOM-FOOTER</td></tr>' |
| 78 | + } |
| 79 | + }) |
| 80 | + expect(wrapper).toBeDefined() |
| 81 | + expect(wrapper.is('table')).toBe(true) |
| 82 | + expect(wrapper.find('thead').exists()).toBe(true) |
| 83 | + expect(wrapper.find('tbody').exists()).toBe(true) |
| 84 | + expect(wrapper.find('tfoot').exists()).toBe(true) |
| 85 | + expect(wrapper.find('tfoot').text()).toContain('CUSTOM-FOOTER') |
| 86 | + expect(wrapper.find('tfoot').classes()).toContain('thead-dark') |
| 87 | + expect(wrapper.find('tfoot').classes().length).toBe(1) |
| 88 | + |
| 89 | + wrapper.destroy() |
| 90 | + }) |
| 91 | +}) |
0 commit comments