🌐 AI搜索 & 代理 主页
Skip to content

Commit 547840f

Browse files
committed
Add test
1 parent 3c29040 commit 547840f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/components/table/helpers/mixin-sorting.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ export const sortingMixin = Vue.extend({
235235
}
236236
},
237237
sortTheadThAttrs(key, field, isFoot) {
238-
const { isSortable, noFooterSorting, localSortDesc, localSortBy } = this
238+
const { isSortable, noFooterSorting, localSortDesc, localSortBy, localSorting } = this
239239
if (!isSortable || (isFoot && noFooterSorting)) {
240240
// No attributes if not a sortable table
241241
return {}
242242
}
243+
243244
const sortable = field.sortable
244-
const sortKey = field.sortKey ?? key
245+
const sortKey = !localSorting ? field.sortKey ?? key : key
245246

246247
// Assemble the aria-sort attribute value
247248
const ariaSort =

src/components/table/table-sorting.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ describe('table > sorting', () => {
6363
expect(wrapper.emitted('sort-changed')[0][0].sortBy).toEqual('non-local')
6464
})
6565

66+
it('should set `aria-sort` when `field.sortKey` and `no-local-sorting` is used', async () => {
67+
const wrapper = mount(BTable, {
68+
propsData: {
69+
fields: [...testFields, { key: 'd', label: 'D', sortable: true, sortKey: 'non-local' }],
70+
items: testItems,
71+
noLocalSorting: true
72+
}
73+
})
74+
75+
expect(wrapper).toBeDefined()
76+
const $header = wrapper.findAll('thead > tr > th').at(3)
77+
78+
await $header.trigger('keydown.enter')
79+
expect(wrapper.emitted('sort-changed').length).toBe(1)
80+
expect(wrapper.emitted('sort-changed')[0][0].sortBy).toEqual('non-local')
81+
82+
expect($header.attributes('aria-sort')).toBe('ascending')
83+
})
84+
6685
it('should sort column descending when sortBy set and sortDesc changed, with proper attributes', async () => {
6786
const wrapper = mount(BTable, {
6887
propsData: {

0 commit comments

Comments
 (0)