fix(pagination): 统一表格分页与密钥查询交互

统一各中心表格的分页样式与切换行为,保留密钥筛选条件和兑换码搜索分页。

验证:871 项单测、ESLint、Prettier 和本地浏览器验收通过。
This commit is contained in:
zhanjunhao
2026-11-20 12:52:45 +08:00
parent b7755187e3
commit ccde35d22e
32 changed files with 416 additions and 401 deletions
+13 -33
View File
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { paginationEvents } from '../src/components/ui/pagination.js';
import { centerPaginationEvents } from '../src/components/ui/pagination.js';
import test from 'node:test';
import { runInNewContext } from 'node:vm';
import React from 'react';
@@ -48,18 +48,14 @@ const { createCardProPagination } = loadUtils({
const loadUsersPage = await compile('../src/components/table/users/index.jsx');
function paginationProps(element) {
const pagination = React.Children.toArray(element.props.children).find(
(child) => child.type === 'antd-pagination',
);
assert.ok(pagination, 'The helper must render Ant Design Pagination');
return pagination.props;
assert.equal(element.type, 'antd-pagination');
return element.props;
}
function foundationFor(props) {
const events = paginationEvents(props);
const events = centerPaginationEvents(props);
return {
changePageSize: (size) => {
events.onShowSizeChange(props.currentPage, size);
events.onChange(props.currentPage, size);
},
goPage: (page) => events.onChange(page, props.pageSize),
@@ -70,7 +66,7 @@ for (const option of [{}, { preventPageChangeOnPageSizeChange: false }]) {
const mode = Object.hasOwn(option, 'preventPageChangeOnPageSizeChange')
? 'explicit false'
: 'default';
test(`other tables retain existing resize page callback: ${mode}`, () => {
test(`other tables avoid a second page callback on resize: ${mode}`, () => {
const calls = [];
const props = paginationProps(
createCardProPagination({
@@ -85,11 +81,7 @@ for (const option of [{}, { preventPageChangeOnPageSizeChange: false }]) {
foundationFor(props).changePageSize(20);
assert.deepEqual(calls, [
['size', 20],
['page', 2],
]);
assert.equal(props.preventPageChangeOnPageSizeChange, false);
assert.deepEqual(calls, [['size', 20]]);
});
}
@@ -130,10 +122,8 @@ for (const isMobile of [false, true]) {
foundationFor(props).changePageSize(20);
assert.deepEqual(calls, [['size', 20]]);
assert.equal(props.preventPageChangeOnPageSizeChange, true);
assert.equal(props.onPageSizeChange, usersData.handlePageSizeChange);
assert.equal(props.onPageChange, usersData.handlePageChange);
assert.equal(props.size, isMobile ? 'small' : 'default');
// The hook owns the reset; verify navigation after its next render.
usersData.activePage = 1;
@@ -176,28 +166,18 @@ for (const [name, render] of [
],
['Pagination', (props) => React.createElement(Pagination, props)],
]) {
test(`${name} renders legacy boolean showTotal without crashing`, () => {
test(`${name} renders the standard translated total`, () => {
const element = render({ total: 25, pageSize: 10, showTotal: true });
const html = renderToStaticMarkup(element);
assert.match(html, /class="ant-pagination-total-text">25<\/li>/);
assert.match(html, /class="ant-pagination-total-text"/);
});
test(`${name} preserves a custom total renderer and its range arguments`, () => {
const showTotal = (total, range) => `${range.join('-')} of ${total}`;
const element = render({ total: 25, pageSize: 10, showTotal });
const props = name === 'Table' ? element.props.pagination : element.props;
assert.equal(props.showTotal, showTotal);
assert.match(renderToStaticMarkup(element), /1-10 of 25/);
test(`${name} uses the same total appearance even with legacy overrides`, () => {
const expected = renderToStaticMarkup(render({ total: 25, pageSize: 10 }));
for (const showTotal of [false, () => 'custom range']) {
assert.equal(renderToStaticMarkup(render({ total: 25, pageSize: 10, showTotal })), expected);
}
});
for (const showTotal of [false, undefined]) {
test(`${name} hides the total when showTotal is ${showTotal}`, () => {
const html = renderToStaticMarkup(
render({ total: 25, pageSize: 10, showTotal }),
);
assert.doesNotMatch(html, /ant-pagination-total-text/);
});
}
}
test('Table keeps pagination disabled for settings tables without pagination', () => {