Skip to content

Commit

Permalink
test: sorter multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 27, 2024
1 parent 4c3e2f4 commit d89477a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src/packages/table/__tests__/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BaseSearch, EditableTable, Table } from '../index'
import Search from '../compatible/search'
import Toolbar from '../compatible/toolbar'
import Alert from '../compatible/alert'
import { BaseForm, Text } from '../../form'
import { BaseForm, Text, Submitter } from '../../form'
import mountTest from '../../../../tests/shared/mountTest'

describe('Table', () => {
Expand Down Expand Up @@ -69,6 +69,10 @@ describe('Table', () => {
demo1: 'demo 1 value',
demo2: 'demo 2 value'
})
const submitter = wrapper.findComponent(Submitter)
const buttonAll = submitter.findAll('button')
await Promise.all(buttonAll.map((button) => button.trigger('click')))
expect(wrapper.emitted()).toHaveProperty('reset')
})

it(`test Table Toolbar`, async () => {
Expand Down Expand Up @@ -241,4 +245,37 @@ describe('Table', () => {
await wrapper.find('.ant-table-column-sorter').trigger('click')
expect(wrapper.emitted()).toHaveProperty('sortChange')
})

it(`test Table sorter multiple`, async () => {
const request = () => Promise.resolve({
data: [{ demo1: 'demo1', demo2: 'demo2', key: 'key-1' }]
})
const wrapper = mount(Table, {
props: {
search: false,
request: request,
columns: [
{
title: 'Title 1',
dataIndex: 'demo1',
sorter: {
compare: (a, b) => a.demo1 - b.demo1,
multiple: 1
}
},
{
title: 'Title 2',
dataIndex: 'demo2',
sorter: {
compare: (a, b) => a.demo2 - b.demo2,
multiple: 2
}
},
]
}
})
const sorterAll = wrapper.findAll('.ant-table-column-sorter')
await Promise.all(sorterAll.map((button) => button.trigger('click')))
expect(wrapper.emitted()).toHaveProperty('sortChange')
})
})
1 change: 0 additions & 1 deletion src/packages/table/table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default defineComponent({
},
sort: () => {
if (isArray(sorter)) {
/* v8 ignore next 4 */
const data = sorter.reduce((pre, value) => {
return { ...pre, [`${value.field}`]: value.order }
}, {})
Expand Down

0 comments on commit d89477a

Please sign in to comment.