|
1 | 1 | import Table from './table'
|
| 2 | +import defaultSortCompare from './helpers/default-sort-compare' |
2 | 3 | import { mount } from '@vue/test-utils'
|
3 | 4 |
|
4 | 5 | const testItems = [{ a: 3, b: 'b', c: 'x' }, { a: 1, b: 'c', c: 'y' }, { a: 2, b: 'a', c: 'z' }]
|
@@ -107,4 +108,40 @@ describe('table sorting', () => {
|
107 | 108 | expect(columnA[1]).toBe('1')
|
108 | 109 | expect(columnA[2]).toBe('2')
|
109 | 110 | })
|
| 111 | + |
| 112 | + it('should accept custom sort compare', async () => { |
| 113 | + const wrapper = mount(Table, { |
| 114 | + propsData: { |
| 115 | + fields: testFields, |
| 116 | + items: testItems, |
| 117 | + sortBy: 'a', |
| 118 | + sortDesc: false, |
| 119 | + sortCompare: (a, b, sortBy) => { |
| 120 | + // We just use our default sort compare to test passing a function |
| 121 | + return defaultSortCompare(a, b, sortBy) |
| 122 | + }) |
| 123 | + } |
| 124 | + }) |
| 125 | + expect(wrapper).toBeDefined() |
| 126 | + expect(wrapper.findAll('tbody > tr').exists()).toBe(true) |
| 127 | + expect(wrapper.findAll('tbody > tr').length).toBe(3) |
| 128 | + let $rows |
| 129 | + let columnA |
| 130 | + |
| 131 | + await wrapper.vm.$nextTick() |
| 132 | + expect(wrapper.emitted('input')).toBeDefined() |
| 133 | + expect(wrapper.emitted('input').length).toBe(1) |
| 134 | + $rows = wrapper.findAll('tbody > tr').wrappers |
| 135 | + expect($rows.length).toBe(3) |
| 136 | + // Map the rows to the first column text value |
| 137 | + columnA = $rows.map(row => { |
| 138 | + return row |
| 139 | + .findAll('td') |
| 140 | + .at(0) |
| 141 | + .text() |
| 142 | + }) |
| 143 | + expect(columnA[0]).toBe('1') |
| 144 | + expect(columnA[1]).toBe('2') |
| 145 | + expect(columnA[2]).toBe('3') |
| 146 | + }) |
110 | 147 | })
|
0 commit comments