From d89477af1153ca9c739cd83ff85130b66e78ba4a Mon Sep 17 00:00:00 2001 From: cole Date: Thu, 27 Jun 2024 14:33:28 +0800 Subject: [PATCH] test: sorter multiple --- src/packages/table/__tests__/Table.test.jsx | 39 ++++++++++++++++++++- src/packages/table/table/index.jsx | 1 - 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/packages/table/__tests__/Table.test.jsx b/src/packages/table/__tests__/Table.test.jsx index 8899bb2..237fe25 100644 --- a/src/packages/table/__tests__/Table.test.jsx +++ b/src/packages/table/__tests__/Table.test.jsx @@ -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', () => { @@ -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 () => { @@ -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') + }) }) diff --git a/src/packages/table/table/index.jsx b/src/packages/table/table/index.jsx index 69d4bf7..dfdfd71 100644 --- a/src/packages/table/table/index.jsx +++ b/src/packages/table/table/index.jsx @@ -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 } }, {})