Files
monkey-ai-web/test/unit/market-name-search.test.js
T
zhanjunhao 4f33cfcc0e fix(market): 1.修复模型超市 模糊搜索-模型名称异常的问题
feat(table): 2.新增三中心表格统一策略:

- 覆盖 `/user-center/*`、`/org/*`、`/console/*`,包含系统设置。
- 自动识别最后一列的创建、查看、编辑、测试、详情、删除、设置、弹窗、API 回调等交互。
- 操作列统一显示“操作”,固定在右侧。
- 根据按钮和文字实际宽度测量,保持操作文字单行显示。
- 非操作宽表自动固定右侧末 4 / 3 / 2 / 1 列。
- 保留 Ant Design 官方横向滚动行为,不隐藏滚动条。
2026-11-17 10:10:28 +08:00

104 lines
3.3 KiB
JavaScript

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import assert from 'node:assert/strict';
import test from 'node:test';
import React from 'react';
import { loadFrontendModule } from './helpers/frontendModule.js';
async function search(query, filters = {}) {
const models = [
{
model_name: 'GPT-4o',
vendor_name: 'OpenAI',
description: '聊天模型',
tags: '热门',
enable_groups: ['default'],
},
{
model_name: 'Claude-Sonnet',
vendor_name: 'GPT',
description: 'GPT-4o',
tags: 'GPT',
enable_groups: ['vip'],
},
{
model_name: '中文模型-Pro',
vendor_name: 'other',
enable_groups: ['default'],
},
{ model_name: null, description: 'GPT', enable_groups: [] },
];
let index = 0;
const state = {
0: query,
7: filters.group || 'all',
10: filters.vendor || 'all',
17: models,
};
const react = {
...React,
useState: (initial) => [
Object.hasOwn(state, index) ? state[index++] : (++index, initial),
() => {},
],
useMemo: (fn) => fn(),
useEffect: () => {},
useRef: (initial) => ({ current: initial }),
useContext: () => [{}],
};
const { useModelPricingData: runHook } = await loadFrontendModule(
new URL(
'../../src/hooks/model-pricing/useModelPricingData.jsx',
import.meta.url,
),
{
react,
'../common/useEffectEvent': { useEffectEvent: (callback) => callback },
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
'../../helpers': {
API: { get: assert.fail },
copy: assert.fail,
getCurrencySymbol: () => '$',
showError: assert.fail,
showInfo: assert.fail,
showSuccess: assert.fail,
},
'@/components/ui': { Modal: {} },
'../../context/User': { UserContext: {} },
'../../context/Status': { StatusContext: {} },
},
);
return runHook().filteredModels.map((model) => model.model_name);
}
test('model search matches names only, ignoring case and surrounding spaces', async () => {
assert.deepEqual(await search(' gPt-4 '), ['GPT-4o']);
assert.deepEqual(await search('OpenAI'), []);
assert.deepEqual(await search('热门'), []);
assert.deepEqual(await search('模型'), ['中文模型-Pro']);
});
test('blank and missing names are safe; search still intersects existing filters', async () => {
assert.equal((await search(' ')).length, 4);
assert.deepEqual(await search('gpt', { vendor: 'GPT' }), []);
assert.deepEqual(await search('gpt', { group: 'vip' }), []);
assert.deepEqual(await search('son', { group: 'vip' }), ['Claude-Sonnet']);
});