fix(table): 统一筛选交互并补齐移动视口覆盖

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 471d7843de
commit 2cbbf0839b
83 changed files with 2094 additions and 1355 deletions
+4
View File
@@ -3,6 +3,7 @@ import test from 'node:test';
import React from 'react';
import * as Ant from 'antd';
import dayjs from 'dayjs';
import * as consoleConstants from '../../src/constants/console.constants.js';
import * as pagination from '../../src/components/ui/pagination.js';
import * as overlayPolicy from '../../src/components/ui/overlayPolicy.js';
import { loadFrontendModule } from './frontend-module.js';
@@ -17,6 +18,9 @@ const controls = await loadFrontendModule(
react: { ...React, useId: () => 'generated-control-id' },
antd: Ant,
dayjs,
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
'../../constants/console.constants': consoleConstants,
'../common/table/table-filter-range.css': {},
'../console/ConsoleContext': context,
},
);
+41 -12
View File
@@ -11,8 +11,7 @@ async function fixture(kind) {
{ length: 24 },
(_, i) => 'aa-' + String(i + 1).padStart(2, '0'),
);
const states =
kind === 'Missing' ? [5, false, models, 'AA', 2] : [5, {}, 2, 'AA'];
const states = kind === 'Missing' ? [5, false, models, 2] : [5, {}, 2];
let cursor = 0;
const react = {
...React,
@@ -51,6 +50,22 @@ async function fixture(kind) {
react,
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
'@/components/ui': ui,
'@/hooks/common/useLocalTableFilters': {
useLocalTableFilters: () => ({
draft: { searchKeyword: 'AA' },
applied: { searchKeyword: 'AA' },
changeFilters: ({ searchKeyword }) =>
calls.push(['search', searchKeyword]),
submitSearch: () => {},
resetFilters: () => {},
}),
},
'@/hooks/common/useFilteredTableRows': {
useFilteredTableRows: (rows, matches) => rows.filter(matches),
},
'@/hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
'../../../../hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
@@ -105,11 +120,12 @@ for (const kind of ['Missing', 'Upstream']) {
assert.equal(table.pagination.total, 24);
assert.equal(table.pagination.pageSize, 5);
assert.equal(table.pagination.currentPage, 2);
assert.equal(table.pagination.preservePage, true);
},
);
test(
kind +
': search and size changes reset the current page without network calls',
': search retains the page and size changes reset it without network calls',
async () => {
const { calls, table, input } = await fixture(kind);
table.pagination.onPageSizeChange(20);
@@ -117,8 +133,7 @@ for (const kind of ['Missing', 'Upstream']) {
assert.ok(calls.some(([, value]) => value === 20));
calls.length = 0;
input.onChange('aa-24');
assert.ok(calls.some(([, value]) => value === 'aa-24'));
assert.ok(calls.some(([, value]) => value === 1));
assert.deepEqual(calls, [['search', 'aa-24']]);
},
);
}
@@ -135,6 +150,24 @@ async function modelTestFixture() {
react: {
...React,
useState: () => [5, (value) => calls.push(['size', value])],
useEffect: () => {},
useMemo: (fn) => fn(),
useCallback: (fn) => fn,
},
'@/hooks/common/useEffectEvent': {
useEffectEvent: (callback) => callback,
},
'@/hooks/common/useLocalTableFilters': {
useLocalTableFilters: () => ({
draft: { keyword: 'AA' },
applied: { keyword: 'AA' },
changeFilters: ({ keyword }) => calls.push(['search', keyword]),
submitSearch: () => {},
resetFilters: () => {},
}),
},
'@/hooks/common/useFilteredTableRows': {
useFilteredTableRows: (rows, matches) => rows.filter(matches),
},
antd: {
...Object.fromEntries(
@@ -154,13 +187,11 @@ async function modelTestFixture() {
);
const tree = Component({
currentTestChannel: { id: 7, name: 'channel', models: models.join(',') },
modelSearchKeyword: 'AA',
modelTablePage: 2,
selectedModelKeys: [],
modelTestResults: {},
testingModels: new Set(),
setModelTablePage: (value) => calls.push(['page', value]),
setModelSearchKeyword: (value) => calls.push(['search', value]),
t: (key) => key,
});
const find = (type, node = tree) =>
@@ -187,6 +218,7 @@ test('Model test dialog passes the complete filtered list to local table paginat
models,
);
assert.equal(table.pagination.total, undefined);
assert.equal(table.pagination.preservePage, true);
assert.equal(table.pagination.current, 2);
assert.equal(table.pagination.pageSize, 5);
const html = renderToStaticMarkup(React.createElement(AntTable, table));
@@ -197,7 +229,7 @@ test('Model test dialog passes the complete filtered list to local table paginat
);
});
test('Model test dialog preserves page changes and resets after search or size changes', async () => {
test('Model test dialog retains the page after search and resets after size changes', async () => {
const { calls, table, input } = await modelTestFixture();
table.pagination.onChange(3, 5);
assert.deepEqual(calls.splice(0), [
@@ -210,8 +242,5 @@ test('Model test dialog preserves page changes and resets after search or size c
['size', 20],
]);
input.onChange({ target: { value: 'aa-24' } });
assert.deepEqual(calls, [
['search', 'aa-24'],
['page', 1],
]);
assert.deepEqual(calls, [['search', 'aa-24']]);
});
+20 -6
View File
@@ -73,10 +73,20 @@ async function exercise(
seqRef: { current: 0 },
orgRef: { current: 77 },
fetchSeqRef: { current: 0 },
request: { current: 0 },
searchKeyword: 'pagination-fixture',
appliedKeyword: 'pagination-fixture',
appliedOrderId: 42,
appliedUserId: 7,
appliedStatus: '',
appliedPaymentMethod: '',
appliedDateRange: [],
appliedFilters: {
planTypes: [],
tiers: [],
statuses: [],
endDateRange: null,
},
statusFilter: '',
paymentMethodFilter: '',
dateRange: [],
@@ -184,6 +194,7 @@ for (const cfg of [
file: 'src/pages/AdminInvoice/index.jsx',
fn: 'fetchInvoices',
expectedPath: '/api/invoice/list',
args: [new AbortController().signal],
},
{
file: 'src/pages/UserCenter/Invoice.jsx',
@@ -326,12 +337,11 @@ for (const cfg of [
{
file: 'src/pages/Organization/datasecurity/OrgDsHitLogs.jsx',
fn: 'fetchLogs',
args: [3, false],
args: [new AbortController().signal],
expectedPath: '/api/org/data-security/logs',
pageKey: 'page',
values: {
logsSeqRef: { current: 0 },
lastAttemptedPageRef: { current: 1 },
query: { page: 3, sensitiveOnly: false },
headers: {},
},
},
@@ -537,10 +547,13 @@ test('Multi-key read pagination preserves existing POST action and response fiel
channel: { id: 7 },
currentPage: 3,
pageSize: 50,
statusFilter: 1,
AbortController,
appliedStatus: { current: 1 },
activeRequest: { current: null },
cancelQuery: () => {},
API: {
post: async (path, data) => {
calls.push({ path, data });
post: async (path, data, options) => {
calls.push({ path, data, options });
return {
data: {
success: true,
@@ -580,6 +593,7 @@ test('Multi-key read pagination preserves existing POST action and response fiel
assert.equal(calls[0].data.action, 'get_key_status');
assert.equal(calls[0].data.page, 3);
assert.equal(calls[0].data.page_size, 50);
assert.ok(calls[0].options.signal instanceof AbortSignal);
assert.equal(states.total, 156);
assert.equal(states.rows[0], sentinel);
assert.equal(states.loading, false);
+14 -3
View File
@@ -128,13 +128,17 @@ test('targets and run directories reject ambiguous or unsafe values', () => {
});
test('mobile retains UA, touch and DPR while using the requested CSS viewport', () => {
assert.equal(projectViewports.length, 8);
assert.equal(projectViewports.length, 9);
const mobile = contextOptions('mobile');
assert.deepEqual(mobile.viewport, { width: 360, height: 800 });
assert.equal(mobile.deviceScaleFactor, 2.75);
assert.equal(mobile.hasTouch, true);
assert.equal(mobile.isMobile, true);
assert.match(mobile.userAgent, /Mobile/);
assert.deepEqual(contextOptions('mobile-393'), {
...mobile,
viewport: { width: 393, height: 851 },
});
assert.equal(contextOptions('tablet').hasTouch, false);
});
@@ -163,8 +167,15 @@ test('config isolates HTML, JUnit and traces and supports extended projects', ()
PW_WORKERS: '1',
PW_TARGET: 'local-dev',
});
assert.equal(base.projects.length, 2);
assert.equal(ci.projects.length, 8);
assert.deepEqual(
base.projects.map(({ name }) => name),
['chrome-desktop', 'chrome-mobile', 'chrome-mobile-393'],
);
assert.deepEqual(
base.projects.find(({ name }) => name === 'chrome-mobile').use.viewport,
{ width: 360, height: 800 },
);
assert.equal(ci.projects.length, 9);
assert.equal(base.use.headless, false);
assert.equal(ci.use.headless, true);
assert.ok(