Files
monkey-ai-web/test/unit/market-name-search.test.js
T
zhanjunhao c492e2b7c0 fix(*): 全量 UI 审查与 undefined 展示异常修复
分析模块:补齐看板、排行、趋势及报表数值兜底
企业与用户中心:修复统计、成员、技能及资金字段展示
充值与交易:修复充值、发票、订单、订阅及支付字段拼接
平台页面:修复渠道、模型、服务监控与状态空值展示
通用能力:新增安全展示工具,补齐九语言文案与回归测试
文档记录:更新修复范围、影响及回滚说明
2026-11-20 10:18:17 +08:00

109 lines
3.5 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: {} },
'../../helpers/safeDisplay': {
formatNumber: (value) => String(value),
toFiniteNumber: (value) =>
Number.isFinite(Number(value)) ? Number(value) : null,
},
},
);
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']);
});