chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
This commit is contained in:
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { colord } from 'colord';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 i18next from 'i18next';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
|
||||
@@ -1,23 +1,4 @@
|
||||
/*
|
||||
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 assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
|
||||
async function harness(result) {
|
||||
const requests = [];
|
||||
const api = await loadFrontendModule(
|
||||
new URL(
|
||||
'../../src/pages/DemoReservations/reservationsApi.js',
|
||||
import.meta.url,
|
||||
),
|
||||
{
|
||||
'../../helpers/websiteApi': {
|
||||
requestWebsite: async (...args) => {
|
||||
requests.push(args);
|
||||
if (result instanceof Error) throw result;
|
||||
return result;
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
return { ...api, requests };
|
||||
}
|
||||
const response = (extra = {}) => ({
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
total: 1,
|
||||
items: [
|
||||
{
|
||||
id: 4,
|
||||
name: '张晨',
|
||||
contact: '+86 13800000001',
|
||||
companyName: '示例科技',
|
||||
position: '',
|
||||
industry: '',
|
||||
interest: '企业 AI 运营与治理',
|
||||
requirement: '第一行\n第二行',
|
||||
},
|
||||
],
|
||||
...extra,
|
||||
});
|
||||
|
||||
test('uses backend pagination and preserves all business fields and line breaks', async () => {
|
||||
const data = response({ page: 2, page_size: 20, total: 21 });
|
||||
const api = await harness(data);
|
||||
assert.equal(
|
||||
await api.fetchDemoReservations({ page: 2, pageSize: 20 }),
|
||||
data,
|
||||
);
|
||||
const [method, path] = api.requests[0];
|
||||
assert.equal(method, 'get');
|
||||
const url = new URL(path, 'https://example.com');
|
||||
assert.equal(url.pathname, '/api/website/demo-requests');
|
||||
assert.equal(url.searchParams.get('p'), '2');
|
||||
assert.equal(url.searchParams.get('page_size'), '20');
|
||||
assert.equal(url.searchParams.has('pageNum'), false);
|
||||
assert.equal(url.searchParams.has('pageSize'), false);
|
||||
});
|
||||
|
||||
test('encodes three trimmed fuzzy AND filters without losing literal plus and wildcard characters', async () => {
|
||||
const api = await harness(response());
|
||||
await api.fetchDemoReservations({
|
||||
name: ' 张 ',
|
||||
contact: ' +86 138%_!& ',
|
||||
companyName: ' 测试科技 ',
|
||||
});
|
||||
const params = new URL(api.requests[0][1], 'https://example.com')
|
||||
.searchParams;
|
||||
assert.equal(params.get('name'), '张');
|
||||
assert.equal(params.get('contact'), '+86 138%_!&');
|
||||
assert.equal(params.get('companyName'), '测试科技');
|
||||
assert.equal(params.get('p'), '1');
|
||||
assert.equal(params.get('page_size'), '10');
|
||||
});
|
||||
|
||||
test('returns empty matches and out-of-range pages with the actual backend total', async () => {
|
||||
for (const total of [0, 23]) {
|
||||
const data = response({ items: [], total, page: 5 });
|
||||
const api = await harness(data);
|
||||
assert.equal(await api.fetchDemoReservations({ page: 5 }), data);
|
||||
}
|
||||
});
|
||||
|
||||
test('fails visibly on malformed responses or backend errors', async () => {
|
||||
for (const value of [
|
||||
null,
|
||||
{},
|
||||
response({ items: null }),
|
||||
response({ total: -1 }),
|
||||
response({ page: 0 }),
|
||||
]) {
|
||||
const api = await harness(value);
|
||||
await assert.rejects(api.fetchDemoReservations(), /响应格式/);
|
||||
}
|
||||
const api = await harness(new Error('没有平台管理员权限'));
|
||||
await assert.rejects(api.fetchDemoReservations(), /没有平台管理员权限/);
|
||||
});
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { createServer } from 'node:http';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { setImmediate } from 'node:timers/promises';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 React from 'react';
|
||||
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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';
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { getOrgQuotaAvailability } from '../../src/pages/Organization/orgQuotaAvailability.js';
|
||||
|
||||
test('quota availability uses unrounded remaining ratio and includes the 20% boundary', () => {
|
||||
for (const [quota, used_quota, type] of [
|
||||
[110855.34, 19254.66, 'success'],
|
||||
[20.001, 79.999, 'success'],
|
||||
[20, 80, 'warning'],
|
||||
[19.999, 80.001, 'warning'],
|
||||
[1, 99, 'warning'],
|
||||
[1, 0, 'success'],
|
||||
[0, 0, 'danger'],
|
||||
[-1, 100, 'danger'],
|
||||
['20', '80', 'warning'],
|
||||
]) {
|
||||
assert.equal(getOrgQuotaAvailability({ quota, used_quota }).type, type);
|
||||
}
|
||||
});
|
||||
|
||||
test('missing or invalid quota does not claim that credit is sufficient', () => {
|
||||
for (const data of [
|
||||
null,
|
||||
{},
|
||||
{ quota: null },
|
||||
{ quota: '' },
|
||||
{ quota: 'invalid' },
|
||||
{ quota: Infinity },
|
||||
{ quota: 10, used_quota: NaN },
|
||||
{ quota: 10, used_quota: -1 },
|
||||
]) {
|
||||
assert.equal(getOrgQuotaAvailability(data), null);
|
||||
}
|
||||
});
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { normalizeCustomAmount } from '../../src/pages/Organization/customRechargeAmount.js';
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import * as Ant from 'antd';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
import {
|
||||
overlayMask,
|
||||
overlayMaskClosable,
|
||||
} from '../../src/components/ui/overlayPolicy.js';
|
||||
|
||||
test('personal routes allow mask dismissal even when a shared caller disables it', () => {
|
||||
for (const path of [
|
||||
'/market',
|
||||
'/market/',
|
||||
'/skill-market',
|
||||
'/skill-market/',
|
||||
'/user-center',
|
||||
'/user-center/dashboard',
|
||||
'/user-center/key-management',
|
||||
'/user-center/settings/security',
|
||||
]) {
|
||||
for (const configured of [undefined, false, true]) {
|
||||
assert.equal(overlayMaskClosable(configured, path), true, path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('other routes retain their existing mask policy', () => {
|
||||
for (const path of [
|
||||
'',
|
||||
'/console/token',
|
||||
'/org/settings',
|
||||
'/login',
|
||||
'/marketplace',
|
||||
'/skill-market-admin',
|
||||
'/user-center-admin',
|
||||
]) {
|
||||
for (const configured of [undefined, false, true]) {
|
||||
assert.equal(overlayMaskClosable(configured, path), configured, path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('modal, drawer and imperative APIs apply the policy and preserve callbacks', async () => {
|
||||
let pathname = '/user-center/settings';
|
||||
const calls = [];
|
||||
const methods = ['confirm', 'info', 'success', 'warning', 'error'];
|
||||
const Modal = Object.assign(
|
||||
() => null,
|
||||
Object.fromEntries(
|
||||
methods.map((name) => [name, (props) => calls.push(props)]),
|
||||
),
|
||||
);
|
||||
const ui = await loadFrontendModule(
|
||||
new URL('../../src/components/ui/index.jsx', import.meta.url),
|
||||
{
|
||||
react: React,
|
||||
antd: { ...Ant, Modal },
|
||||
'./controls': {},
|
||||
'./pagination': {},
|
||||
'./pagination.css': {},
|
||||
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
|
||||
'./form': {},
|
||||
'./chat': {},
|
||||
'../console/ConsoleContext': { useConsolePage: () => null },
|
||||
'./CenterActionTable': Ant.Table,
|
||||
'../console/ConsolePrimitives': {},
|
||||
'../console/consoleTableAdapter': {},
|
||||
'./overlayPolicy': {
|
||||
overlayMask: (mask, closable) => overlayMask(mask, closable, pathname),
|
||||
overlayMaskClosable: (configured) =>
|
||||
overlayMaskClosable(configured, pathname),
|
||||
},
|
||||
},
|
||||
);
|
||||
const onCancel = () => {};
|
||||
const onOk = () => {};
|
||||
for (const path of ['/market', '/skill-market', '/user-center/settings']) {
|
||||
pathname = path;
|
||||
const props = { visible: true, maskClosable: false, onCancel, onOk };
|
||||
const modal = ui.Modal(props);
|
||||
const drawer = ui.SideSheet(props);
|
||||
assert.equal(modal.props.mask.closable, true);
|
||||
assert.equal(modal.props.onCancel, onCancel);
|
||||
assert.equal(modal.props.onOk, onOk);
|
||||
assert.equal(drawer.props.mask.closable, true);
|
||||
assert.equal(drawer.props.onClose, onCancel);
|
||||
for (const method of methods) {
|
||||
ui.Modal[method](props);
|
||||
const config = calls.at(-1);
|
||||
assert.equal(config.mask.closable, true);
|
||||
assert.equal(config.onCancel, onCancel);
|
||||
assert.equal(config.onOk, onOk);
|
||||
}
|
||||
}
|
||||
pathname = '/console/token';
|
||||
assert.equal(ui.Modal({ maskClosable: false }).props.mask.closable, false);
|
||||
assert.equal(
|
||||
ui.SideSheet({ maskClosable: false }).props.mask.closable,
|
||||
false,
|
||||
);
|
||||
ui.Modal.confirm({ maskClosable: false });
|
||||
assert.equal(calls.at(-1).mask.closable, false);
|
||||
});
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 fs from 'node:fs/promises';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { EventEmitter } from 'node:events';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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, { afterEach, beforeEach } from 'node:test';
|
||||
import {
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { setImmediate } from 'node:timers/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 {
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { readFile, readdir } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { revealActiveSidebarItem } from '../../src/helpers/sidebarScroll.js';
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
|
||||
async function harness(respond) {
|
||||
const calls = [],
|
||||
authErrors = [];
|
||||
const api = await loadFrontendModule(
|
||||
new URL('../../src/helpers/websiteApi.js', import.meta.url),
|
||||
{
|
||||
'./api': {
|
||||
API: Object.fromEntries(
|
||||
['get', 'post'].map((method) => [
|
||||
method,
|
||||
async (...args) => {
|
||||
calls.push({ method, args });
|
||||
return respond();
|
||||
},
|
||||
]),
|
||||
),
|
||||
},
|
||||
'./utils': { showError: (error) => authErrors.push(error) },
|
||||
},
|
||||
);
|
||||
return { ...api, calls, authErrors };
|
||||
}
|
||||
|
||||
test('requires strict business success including when HTTP succeeds', async () => {
|
||||
for (const data of [
|
||||
null,
|
||||
{},
|
||||
{ success: false, message: '权限不足' },
|
||||
{ success: 'true' },
|
||||
]) {
|
||||
const api = await harness(() => ({ data }));
|
||||
await assert.rejects(
|
||||
api.requestWebsite('get', '/api/website/page-config'),
|
||||
/权限不足|请求失败/,
|
||||
);
|
||||
}
|
||||
const api = await harness(() => ({ data: { success: true, data: null } }));
|
||||
assert.equal(
|
||||
await api.requestWebsite('get', '/api/website/page-config'),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
test('uses the authenticated shared API instance and leaves multipart Content-Type unset', async () => {
|
||||
const api = await harness(() => ({
|
||||
data: { success: true, data: { url: 'https://cdn.example.com/qr.png' } },
|
||||
}));
|
||||
const form = new FormData();
|
||||
await api.requestWebsite('post', '/api/customer-service/upload', form);
|
||||
assert.equal(api.calls[0].args[1], form);
|
||||
assert.equal(api.calls[0].args[2].headers, undefined);
|
||||
assert.equal(api.calls[0].args[2].skipErrorHandler, true);
|
||||
assert.equal(api.calls[0].args[2].timeout, 20000);
|
||||
});
|
||||
|
||||
test('handles unauthenticated, rate-limited, non-JSON gateway and network failures', async () => {
|
||||
for (const [response, pattern] of [
|
||||
[{ status: 401 }, /重新登录/],
|
||||
[{ status: 429, data: '<html>Too many requests</html>' }, /过于频繁/],
|
||||
[{ status: 502 }, /读取失败/],
|
||||
[{ status: 400, data: { message: '后端业务错误' } }, /后端业务错误/],
|
||||
[undefined, /读取失败/],
|
||||
]) {
|
||||
const error = Object.assign(new Error('Axios error'), { response });
|
||||
const api = await harness(() => {
|
||||
throw error;
|
||||
});
|
||||
await assert.rejects(
|
||||
api.requestWebsite(
|
||||
'get',
|
||||
'/api/website/page-config',
|
||||
undefined,
|
||||
'读取失败',
|
||||
),
|
||||
pattern,
|
||||
);
|
||||
assert.equal(api.authErrors.length, response?.status === 401 ? 1 : 0);
|
||||
}
|
||||
});
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
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 * as model from '../../src/pages/WebsiteSettings/model.js';
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as model from '../../src/pages/WebsiteSettings/model.js';
|
||||
import * as richTextImages from '../../src/components/common/ui/richTextImages.js';
|
||||
import { loadFrontendModule } from './helpers/frontendModule.js';
|
||||
|
||||
const validValues = () => ({
|
||||
insights: {
|
||||
categories: [{ id: 'news', name: 'News' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
paidCustomers: '200',
|
||||
dailyTokens: '10亿',
|
||||
costReduction: '30',
|
||||
teamMembers: '100',
|
||||
researchRatio: '70',
|
||||
headquarters: '深圳',
|
||||
serviceNetwork: '全国',
|
||||
businessPhone: '0755-12345678',
|
||||
businessEmail: 'contact@example.com',
|
||||
wechatQrCode: 'https://cdn.example.com/qr.png',
|
||||
address: '联调测试地址',
|
||||
});
|
||||
async function harness(...args) {
|
||||
const initial = args.length ? args[0] : null;
|
||||
const requests = [];
|
||||
let stored = initial;
|
||||
let failure;
|
||||
const api = await loadFrontendModule(
|
||||
new URL('../../src/pages/WebsiteSettings/settingsApi.js', import.meta.url),
|
||||
{
|
||||
'../../helpers/websiteApi': {
|
||||
requestWebsite: async (method, path, body) => {
|
||||
requests.push({ method, path, body });
|
||||
if (failure) throw failure;
|
||||
if (path === '/api/customer-service/upload')
|
||||
return { url: 'https://cdn.example.com/new.png' };
|
||||
if (method === 'get') return stored;
|
||||
assert.equal(typeof body.config, 'string');
|
||||
stored = body.config;
|
||||
return null;
|
||||
},
|
||||
},
|
||||
'./model': model,
|
||||
'../../components/common/ui/richTextImages': richTextImages,
|
||||
},
|
||||
);
|
||||
return {
|
||||
...api,
|
||||
requests,
|
||||
fail: (message) => {
|
||||
failure = new Error(message);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('loads an unconfigured site and rejects failed, malformed or invalid JSON reads', async () => {
|
||||
assert.equal(await (await harness()).getWebsiteSettings(), null);
|
||||
for (const value of [
|
||||
undefined,
|
||||
{},
|
||||
'not json',
|
||||
'null',
|
||||
'[]',
|
||||
'{"home":[]}',
|
||||
]) {
|
||||
await assert.rejects((await harness(value)).getWebsiteSettings());
|
||||
}
|
||||
const api = await harness();
|
||||
api.fail('配置读取失败');
|
||||
await assert.rejects(api.getWebsiteSettings(), /配置读取失败/);
|
||||
});
|
||||
|
||||
test('round-trips the complete grouped configuration and preserves unknown fields', async () => {
|
||||
const original = {
|
||||
...model.settingsToConfig(validValues()),
|
||||
extension: { enabled: true },
|
||||
};
|
||||
original.home.futureMetric = 'future';
|
||||
original.insights.extra = { locale: 'zh' };
|
||||
const api = await harness(JSON.stringify(original));
|
||||
const config = await api.getWebsiteSettings();
|
||||
const values = model.settingsFromConfig(config);
|
||||
assert.equal(values.researchRatio, '70');
|
||||
values.teamMembers = '120';
|
||||
values.address = ' 新地址 ';
|
||||
await api.saveWebsiteSettings(model.serializeSettings(values, config));
|
||||
const saved = await api.getWebsiteSettings();
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(saved.extension)), {
|
||||
enabled: true,
|
||||
});
|
||||
assert.equal(saved.home.futureMetric, 'future');
|
||||
assert.equal(saved.insights.extra.locale, 'zh');
|
||||
assert.equal(saved.about.teamMembers, '120');
|
||||
assert.equal(saved.home.teamMembers, undefined);
|
||||
assert.equal(saved.demo.address, '新地址');
|
||||
assert.equal(api.requests[1].path, '/api/website/page-config');
|
||||
assert.equal(api.requests[1].method, 'post');
|
||||
});
|
||||
|
||||
test('rejects incomplete and unserialized configurations before sending', async () => {
|
||||
const api = await harness();
|
||||
await assert.rejects(api.saveWebsiteSettings({}), /JSON 字符串/);
|
||||
await assert.rejects(api.saveWebsiteSettings('{}'), /完整填写/);
|
||||
assert.equal(api.requests.length, 0);
|
||||
});
|
||||
|
||||
test('large configurations are sent because the backend stores LONGTEXT', async () => {
|
||||
const api = await harness();
|
||||
const config = model.settingsToConfig(validValues());
|
||||
config.extension = '中'.repeat(21000);
|
||||
await api.saveWebsiteSettings(JSON.stringify(config));
|
||||
assert.equal(api.requests.at(-1).path, '/api/website/page-config');
|
||||
});
|
||||
|
||||
test('saving errors propagate without reporting success', async () => {
|
||||
const api = await harness();
|
||||
api.fail('没有保存权限');
|
||||
await assert.rejects(
|
||||
api.saveWebsiteSettings(model.serializeSettings(validValues())),
|
||||
/没有保存权限/,
|
||||
);
|
||||
});
|
||||
|
||||
test('an empty article list can be saved for the website empty state', async () => {
|
||||
const api = await harness();
|
||||
const values = { ...validValues(), insights: model.emptySettings().insights };
|
||||
await api.saveWebsiteSettings(model.serializeSettings(values));
|
||||
assert.equal(api.requests.at(-1).path, '/api/website/page-config');
|
||||
});
|
||||
|
||||
test('articles under the all filter are rejected before any request', async () => {
|
||||
const api = await harness();
|
||||
const values = validValues();
|
||||
values.insights.articles[0].category = 'all';
|
||||
await assert.rejects(
|
||||
api.saveWebsiteSettings(model.serializeSettings(values)),
|
||||
/请完整填写并检查官网设置/,
|
||||
);
|
||||
assert.equal(api.requests.length, 0);
|
||||
});
|
||||
|
||||
test('uploads the actual image as multipart file and returns a persistent URL', async () => {
|
||||
const api = await harness();
|
||||
const file = new File(['png'], 'qr.png', { type: 'image/png' });
|
||||
assert.equal(
|
||||
await api.uploadWebsiteQrCode(file),
|
||||
'https://cdn.example.com/new.png',
|
||||
);
|
||||
const { body, method, path } = api.requests[0];
|
||||
assert.equal(method, 'post');
|
||||
assert.equal(path, '/api/customer-service/upload');
|
||||
assert.equal(body.get('file'), file);
|
||||
await assert.rejects(
|
||||
api.uploadWebsiteQrCode(
|
||||
new File(['svg'], 'qr.svg', { type: 'image/svg+xml' }),
|
||||
),
|
||||
/仅支持/,
|
||||
);
|
||||
});
|
||||
|
||||
test('uploads local article images once and stores public URLs instead of base64', async () => {
|
||||
const api = await harness();
|
||||
const config = model.settingsToConfig(validValues());
|
||||
config.insights = {
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'a',
|
||||
title: '测试文章',
|
||||
category: 'news',
|
||||
date: '2026-10-31',
|
||||
summary: '测试摘要',
|
||||
tag: '',
|
||||
body: '<p>正文</p><img src="data:image/png;base64,AQID"><img src="data:image/png;base64,AQID">',
|
||||
related: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = await api.saveWebsiteSettings(JSON.stringify(config));
|
||||
assert.equal(
|
||||
api.requests.filter((item) => item.path === '/api/customer-service/upload')
|
||||
.length,
|
||||
1,
|
||||
);
|
||||
assert.equal(api.requests.at(-1).path, '/api/website/page-config');
|
||||
assert.equal(api.requests.at(-1).body.config.includes('data:image'), false);
|
||||
assert.equal(
|
||||
result.config.insights.articles[0].body.match(
|
||||
/https:\/\/cdn.example.com\/new.png/g,
|
||||
).length,
|
||||
2,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,188 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as model from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
|
||||
const filename = new URL(
|
||||
'../../src/pages/WebsiteSettings/ArticleEditor.jsx',
|
||||
import.meta.url,
|
||||
);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs' },
|
||||
);
|
||||
function harness() {
|
||||
const initial = model.newArticle('company');
|
||||
const states = [],
|
||||
messages = [],
|
||||
confirms = [],
|
||||
applied = [];
|
||||
let stateCursor = 0,
|
||||
mounting = true,
|
||||
tree,
|
||||
closed = false;
|
||||
const Modal = { confirm: (options) => confirms.push(options) };
|
||||
const modules = {
|
||||
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
|
||||
react: {
|
||||
...React,
|
||||
useEffect() {},
|
||||
useState(value) {
|
||||
const index = stateCursor++;
|
||||
if (mounting) states[index] = value;
|
||||
return [
|
||||
states[index],
|
||||
(next) => {
|
||||
states[index] =
|
||||
typeof next === 'function' ? next(states[index]) : next;
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
'@/components/ui': {
|
||||
Button: 'Button',
|
||||
Card: 'Card',
|
||||
Checkbox: 'Checkbox',
|
||||
Form: { Slot: 'Slot' },
|
||||
Image: 'Image',
|
||||
Input: 'Input',
|
||||
Modal,
|
||||
Select: 'Select',
|
||||
SideSheet: 'SideSheet',
|
||||
TextArea: 'TextArea',
|
||||
Typography: { Title: 'Title', Text: 'Text', Paragraph: 'Paragraph' },
|
||||
},
|
||||
'../../helpers': { showError: (message) => messages.push(message) },
|
||||
'./insightsModel': model,
|
||||
'./insightsContent': {
|
||||
sanitizeArticleHtml: (html) => html,
|
||||
articleHeadings: () => [],
|
||||
},
|
||||
'./ArticleRichEditor': { default: 'ArticleRichEditor', __esModule: true },
|
||||
};
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
exports: module.exports,
|
||||
module,
|
||||
require: (name) => {
|
||||
assert.ok(modules[name], name);
|
||||
return modules[name];
|
||||
},
|
||||
});
|
||||
const render = () => {
|
||||
stateCursor = 0;
|
||||
tree = module.exports.default({
|
||||
initial,
|
||||
insights: model.emptyInsights(),
|
||||
onApply: (article) => applied.push(article),
|
||||
onClose: () => {
|
||||
closed = true;
|
||||
},
|
||||
});
|
||||
mounting = false;
|
||||
};
|
||||
const all = (node) =>
|
||||
Array.isArray(node)
|
||||
? node.flatMap(all)
|
||||
: node && typeof node === 'object'
|
||||
? [node, ...all(node.props?.children), ...all(node.props?.footer)]
|
||||
: [];
|
||||
const find = (type, predicate = () => true) =>
|
||||
all(tree).find((node) => node.type === type && predicate(node.props));
|
||||
render();
|
||||
return {
|
||||
render,
|
||||
find,
|
||||
messages,
|
||||
confirms,
|
||||
applied,
|
||||
closed: () => closed,
|
||||
save: () => find('Button', (p) => p.children === '保存').props.onClick(),
|
||||
};
|
||||
}
|
||||
|
||||
test('article editor blocks incomplete drafts, applies valid data and confirms discarding changes', () => {
|
||||
const page = harness();
|
||||
page.save();
|
||||
page.render();
|
||||
assert.equal(page.applied.length, 0);
|
||||
assert.equal(page.messages.length, 0);
|
||||
assert.equal(
|
||||
page.find('Slot', (p) => p.label.text === '文章标题').props.error.error,
|
||||
'请输入文章标题',
|
||||
);
|
||||
assert.equal(
|
||||
page.find('Slot', (p) => p.label.text === '文章描述').props.error.error,
|
||||
'请输入文章描述',
|
||||
);
|
||||
assert.equal(
|
||||
page.find('Slot', (p) => p.label.text === '文章正文').props.error.error,
|
||||
'请输入文章正文',
|
||||
);
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '文章标题')
|
||||
.props.onChange(' 测试标题 ');
|
||||
page.render();
|
||||
page.find('TextArea').props.onChange(' 摘要 ');
|
||||
page.render();
|
||||
page.find('ArticleRichEditor').props.onChange('<h2>章节</h2><p>正文</p>');
|
||||
page.render();
|
||||
page.save();
|
||||
assert.equal(page.applied[0].title, '测试标题');
|
||||
assert.equal(page.applied[0].summary, '摘要');
|
||||
page.find('SideSheet').props.onCancel();
|
||||
assert.equal(page.closed(), false);
|
||||
page.confirms.at(-1).onOk();
|
||||
assert.equal(page.closed(), true);
|
||||
});
|
||||
|
||||
test('article editor removes cover controls and blocks submission while body images are processing', () => {
|
||||
const page = harness();
|
||||
assert.equal(page.find('Image'), undefined);
|
||||
assert.equal(
|
||||
page.find('Slot', (p) => p.label.text === '封面图'),
|
||||
undefined,
|
||||
);
|
||||
page.find('ArticleRichEditor').props.onBusyChange(true);
|
||||
page.render();
|
||||
assert.equal(
|
||||
page.find('Button', (p) => p.children === '图片处理中').props.disabled,
|
||||
true,
|
||||
);
|
||||
page.find('Button', (p) => p.children === '图片处理中').props.onClick();
|
||||
assert.equal(page.applied.length, 0);
|
||||
page.find('ArticleRichEditor').props.onBusyChange(false);
|
||||
page.render();
|
||||
assert.equal(
|
||||
page.find('Button', (p) => p.children === '保存').props.disabled,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('article editor only exposes website fields and real categories', () => {
|
||||
const page = harness();
|
||||
for (const label of ['详情副标题', '卡片摘要'])
|
||||
assert.equal(
|
||||
page.find('Slot', (p) => p.label.text === label),
|
||||
undefined,
|
||||
label,
|
||||
);
|
||||
assert.equal(
|
||||
page.find(
|
||||
'Checkbox',
|
||||
(p) => 'checked' in p && p.children === '根据正文标题自动生成',
|
||||
),
|
||||
undefined,
|
||||
);
|
||||
const options = page
|
||||
.find('Select', (p) => p['aria-label'] === '所属分类')
|
||||
.props.optionList.map((o) => o.value);
|
||||
assert.deepEqual(options, ['company', 'product', 'industry']);
|
||||
assert.ok(page.find('Slot', (p) => p.label.text === '文章描述'));
|
||||
assert.ok(page.find('Slot', (p) => p.label.text === '角标标签'));
|
||||
assert.ok(page.find('Slot', (p) => p.label.text === '发布日期'));
|
||||
});
|
||||
@@ -0,0 +1,196 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
articleErrors,
|
||||
categoryError,
|
||||
emptyInsights,
|
||||
filterArticles,
|
||||
moveArticle,
|
||||
newArticle,
|
||||
normalizeInsights,
|
||||
removeArticle,
|
||||
validateInsights,
|
||||
} from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
|
||||
const article = (id, extra = {}) => ({
|
||||
...newArticle('company'),
|
||||
id,
|
||||
title: `文章 ${id}`,
|
||||
summary: '文章描述',
|
||||
body: '<h2>章节</h2><p>正文</p>',
|
||||
...extra,
|
||||
});
|
||||
|
||||
test('category names reject blanks, duplicates, reserved names and excessive length', () => {
|
||||
const { categories } = emptyInsights();
|
||||
for (const name of [
|
||||
'',
|
||||
' ',
|
||||
'公司动态',
|
||||
'全部内容',
|
||||
'全部分类',
|
||||
'字'.repeat(13),
|
||||
])
|
||||
assert.ok(categoryError(name, categories));
|
||||
assert.equal(categoryError('公司动态', categories, 'company'), '');
|
||||
assert.equal(categoryError('新分类', categories), '');
|
||||
});
|
||||
|
||||
test('article validation covers required content, limits and related references', () => {
|
||||
const value = { ...emptyInsights(), articles: [article('a'), article('b')] };
|
||||
assert.deepEqual(
|
||||
articleErrors(article('c', { related: ['a', 'b'] }), value),
|
||||
{},
|
||||
);
|
||||
for (const [key, bad] of [
|
||||
['title', ' '],
|
||||
['title', '字'.repeat(81)],
|
||||
['summary', ''],
|
||||
['summary', '字'.repeat(201)],
|
||||
['tag', '字'.repeat(13)],
|
||||
['category', 'missing'],
|
||||
['category', 'all'],
|
||||
['category', ''],
|
||||
['date', ''],
|
||||
['date', '2026-02-30'],
|
||||
['date', '2026-11-14 10:00:00'],
|
||||
['date', '2026-11-14 10:00'],
|
||||
['date', '2025-02-29'],
|
||||
['date', '2026/11/14'],
|
||||
['date', '2026-11-14T10:00:00'],
|
||||
['body', '<p><br></p>'],
|
||||
['body', '<p> </p>'],
|
||||
['body', '<img src="x" onerror="alert(1)">'],
|
||||
['body', '<script>alert(1)</script>'],
|
||||
['body', '<img src="data:image/svg+xml;base64,AAAA">'],
|
||||
['related', ['a', 'a']],
|
||||
['related', ['missing']],
|
||||
['related', ['c']],
|
||||
]) {
|
||||
assert.ok(articleErrors(article('c', { [key]: bad }), value)[key], key);
|
||||
}
|
||||
for (const good of ['2026-11-14', '2024-02-29'])
|
||||
assert.equal(
|
||||
articleErrors(article('c', { date: good }), value).date,
|
||||
undefined,
|
||||
good,
|
||||
);
|
||||
const more = {
|
||||
...value,
|
||||
articles: ['a', 'b', 'd', 'e'].map((id) => article(id)),
|
||||
};
|
||||
assert.ok(
|
||||
articleErrors(article('c', { related: ['a', 'b', 'd', 'e'] }), more)
|
||||
.related,
|
||||
);
|
||||
});
|
||||
|
||||
test('new articles carry only website fields and never default to the all filter', () => {
|
||||
const draft = newArticle('company');
|
||||
assert.deepEqual(Object.keys(draft).sort(), [
|
||||
'body',
|
||||
'category',
|
||||
'date',
|
||||
'id',
|
||||
'related',
|
||||
'summary',
|
||||
'tag',
|
||||
'title',
|
||||
]);
|
||||
assert.equal(draft.category, 'company');
|
||||
assert.equal(newArticle('all').category, '');
|
||||
assert.equal(newArticle().category, '');
|
||||
assert.match(draft.date, /^\d{4}-\d{2}-\d{2}$/);
|
||||
});
|
||||
|
||||
test('deleting an article clears all related references without mutating source', () => {
|
||||
const value = {
|
||||
...emptyInsights(),
|
||||
articles: [article('a'), article('b', { related: ['a'] })],
|
||||
};
|
||||
const next = removeArticle(value, 'a');
|
||||
assert.deepEqual(next.articles[0].related, []);
|
||||
assert.deepEqual(value.articles[1].related, ['a']);
|
||||
});
|
||||
|
||||
test('search combines category and case-insensitive title or summary filtering in list order', () => {
|
||||
const value = {
|
||||
...emptyInsights(),
|
||||
articles: [
|
||||
article('a', { title: 'AI 模型' }),
|
||||
article('b', { summary: 'AI 平台' }),
|
||||
article('c', { title: 'AI 新闻', category: 'industry' }),
|
||||
],
|
||||
};
|
||||
assert.deepEqual(
|
||||
filterArticles(value, ' ai ', 'company').map((a) => a.id),
|
||||
['a', 'b'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
filterArticles(value, '', 'all').map((a) => a.id),
|
||||
['a', 'b', 'c'],
|
||||
);
|
||||
assert.equal(filterArticles(value, 'missing', 'all').length, 0);
|
||||
});
|
||||
|
||||
test('moving an article swaps neighbours and ignores out-of-range moves', () => {
|
||||
const value = {
|
||||
...emptyInsights(),
|
||||
articles: [article('a'), article('b'), article('c')],
|
||||
};
|
||||
const ids = (insights) => insights.articles.map((a) => a.id);
|
||||
assert.deepEqual(ids(moveArticle(value, 'b', -1)), ['b', 'a', 'c']);
|
||||
assert.deepEqual(ids(moveArticle(value, 'b', 1)), ['a', 'c', 'b']);
|
||||
assert.equal(moveArticle(value, 'a', -1), value);
|
||||
assert.equal(moveArticle(value, 'c', 1), value);
|
||||
assert.equal(moveArticle(value, 'missing', 1), value);
|
||||
assert.deepEqual(ids(value), ['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
test('normalization keeps only the article schema with trimmed values', () => {
|
||||
const value = {
|
||||
...emptyInsights(),
|
||||
extension: 'keep',
|
||||
articles: [
|
||||
article('a', { title: ' 标题 ', date: ' 2026-10-31 ', extra: 'drop' }),
|
||||
],
|
||||
};
|
||||
const normalized = normalizeInsights(value);
|
||||
const [first] = normalized.articles;
|
||||
assert.equal(first.title, '标题');
|
||||
assert.equal(first.date, '2026-10-31');
|
||||
assert.equal('extra' in first, false);
|
||||
assert.equal(normalized.extension, 'keep');
|
||||
assert.deepEqual(Object.keys(first).sort(), [
|
||||
'body',
|
||||
'category',
|
||||
'date',
|
||||
'id',
|
||||
'related',
|
||||
'summary',
|
||||
'tag',
|
||||
'title',
|
||||
]);
|
||||
assert.equal(validateInsights(normalized), '');
|
||||
assert.ok(validateInsights({ ...value, categories: [] }));
|
||||
assert.ok(
|
||||
validateInsights({ ...value, articles: [article('a'), article('a')] }),
|
||||
);
|
||||
const fresh = emptyInsights();
|
||||
fresh.categories[0].name = 'changed';
|
||||
assert.equal(emptyInsights().categories[0].name, '公司动态');
|
||||
assert.equal(validateInsights({ ...emptyInsights(), articles: [] }), '');
|
||||
});
|
||||
|
||||
test('required article errors use Chinese control-specific prompts', () => {
|
||||
const errors = articleErrors(newArticle(), emptyInsights());
|
||||
assert.equal(errors.title, '请输入文章标题');
|
||||
assert.equal(errors.summary, '请输入文章描述');
|
||||
assert.equal(errors.body, '请输入文章正文');
|
||||
assert.equal(errors.category, '请选择所属分类');
|
||||
assert.equal(
|
||||
articleErrors({ ...newArticle(), date: '' }, emptyInsights()).date,
|
||||
'请选择发布日期',
|
||||
);
|
||||
assert.equal(errors.date, undefined);
|
||||
});
|
||||
@@ -0,0 +1,326 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as model from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
|
||||
const filename = new URL(
|
||||
'../../src/pages/WebsiteSettings/InsightsPanel.jsx',
|
||||
import.meta.url,
|
||||
);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs' },
|
||||
);
|
||||
|
||||
function harness(initial = model.emptyInsights()) {
|
||||
const states = [];
|
||||
const confirms = [];
|
||||
const messages = [];
|
||||
let value = initial;
|
||||
let cursor = 0;
|
||||
let mounting = true;
|
||||
let tree;
|
||||
const Modal = Object.assign(() => {}, {
|
||||
confirm: (options) => confirms.push(options),
|
||||
});
|
||||
const modules = {
|
||||
'react-i18next': { useTranslation: () => ({ t: (key) => key }) },
|
||||
react: {
|
||||
...React,
|
||||
useState(initialState) {
|
||||
const index = cursor++;
|
||||
if (mounting)
|
||||
states[index] =
|
||||
typeof initialState === 'function' ? initialState() : initialState;
|
||||
return [
|
||||
states[index],
|
||||
(next) => {
|
||||
states[index] =
|
||||
typeof next === 'function' ? next(states[index]) : next;
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
'@/components/ui': {
|
||||
Button: 'Button',
|
||||
Card: 'Card',
|
||||
Empty: 'Empty',
|
||||
Input: 'Input',
|
||||
Modal,
|
||||
Select: 'Select',
|
||||
Typography: { Paragraph: 'Paragraph', Text: 'Text', Title: 'Title' },
|
||||
},
|
||||
'@/components/ui/icons': {
|
||||
IconPlus: 'IconPlus',
|
||||
IconSearch: 'IconSearch',
|
||||
IconEdit: 'IconEdit',
|
||||
IconClose: 'IconClose',
|
||||
},
|
||||
'../../components/common/ui/CardTable': {
|
||||
default: 'CardTable',
|
||||
__esModule: true,
|
||||
},
|
||||
'../../components/common/table/TableEmpty': {
|
||||
default: 'TableEmpty',
|
||||
__esModule: true,
|
||||
},
|
||||
'../../components/common/table/TableToolbar': {
|
||||
default: 'TableToolbar',
|
||||
__esModule: true,
|
||||
},
|
||||
'../../components/console/ConsoleModuleFilters': {
|
||||
ConsoleFilterField: 'ConsoleFilterField',
|
||||
},
|
||||
'../../helpers/utils': {
|
||||
createCardProPagination: (props) =>
|
||||
React.createElement('Pagination', props),
|
||||
},
|
||||
'../../hooks/common/useIsMobile': { useIsMobile: () => false },
|
||||
'../../helpers': {
|
||||
showError: (message) => messages.push(message),
|
||||
showInfo: (message) => messages.push(message),
|
||||
},
|
||||
'./insightsModel': model,
|
||||
'./ArticleEditor': { default: 'ArticleEditor', __esModule: true },
|
||||
};
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
exports: module.exports,
|
||||
module,
|
||||
require: (name) => {
|
||||
assert.ok(modules[name], name);
|
||||
return modules[name];
|
||||
},
|
||||
});
|
||||
const render = () => {
|
||||
cursor = 0;
|
||||
tree = module.exports.default({
|
||||
value,
|
||||
onChange: (next) => {
|
||||
value = next;
|
||||
},
|
||||
disabled: false,
|
||||
});
|
||||
mounting = false;
|
||||
};
|
||||
const all = (node) =>
|
||||
Array.isArray(node)
|
||||
? node.flatMap(all)
|
||||
: node && typeof node === 'object'
|
||||
? [node, ...all(node.props?.children)]
|
||||
: [];
|
||||
const find = (type, predicate = () => true) =>
|
||||
all(tree).find((node) => node.type === type && predicate(node.props));
|
||||
const button = (label) => find('Button', (props) => props.children === label);
|
||||
const modal = () =>
|
||||
find(
|
||||
Modal,
|
||||
(props) =>
|
||||
props.visible && ['新增分类', '编辑分类'].includes(props.title),
|
||||
);
|
||||
render();
|
||||
return {
|
||||
render,
|
||||
find,
|
||||
button,
|
||||
modal,
|
||||
confirms,
|
||||
messages,
|
||||
value: () => value,
|
||||
};
|
||||
}
|
||||
|
||||
const actionsOf = (page, item) =>
|
||||
page.find('CardTable').props.columns.at(-1).render(null, item).props.children;
|
||||
const action = (page, item, label) =>
|
||||
actionsOf(page, item).find((button) => button.props.children === label);
|
||||
|
||||
const article = (id, extra = {}) => ({
|
||||
...model.newArticle('company'),
|
||||
id,
|
||||
title: `文章 ${id}`,
|
||||
summary: 'AI 内容',
|
||||
body: '<p>正文</p>',
|
||||
...extra,
|
||||
});
|
||||
|
||||
test('category modal creates, rejects duplicates and edits the bound configuration', () => {
|
||||
const page = harness();
|
||||
page.button('新增分类').props.onClick();
|
||||
page.render();
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '分类名称')
|
||||
.props.onChange('公司动态');
|
||||
page.render();
|
||||
page.modal().props.onOk();
|
||||
page.render();
|
||||
assert.equal(page.value().categories.length, 3);
|
||||
assert.ok(page.find('Text', (p) => p.role === 'alert'));
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '分类名称')
|
||||
.props.onChange('客户案例');
|
||||
page.render();
|
||||
page.modal().props.onOk();
|
||||
page.render();
|
||||
assert.equal(page.value().categories.at(-1).name, '客户案例');
|
||||
page
|
||||
.find('Button', (p) => p['aria-label'] === '编辑客户案例')
|
||||
.props.onClick();
|
||||
page.render();
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '分类名称')
|
||||
.props.onChange('实践案例');
|
||||
page.render();
|
||||
page.modal().props.onOk();
|
||||
page.render();
|
||||
assert.equal(page.value().categories.at(-1).name, '实践案例');
|
||||
});
|
||||
|
||||
test('article deletion cleans references and occupied category deletion is blocked', () => {
|
||||
const page = harness({
|
||||
...model.emptyInsights(),
|
||||
articles: [article('a'), article('b', { related: ['a'] })],
|
||||
});
|
||||
page
|
||||
.find('Button', (p) => p['aria-label'] === '删除公司动态')
|
||||
.props.onClick();
|
||||
assert.equal(page.confirms.length, 0);
|
||||
assert.ok(page.messages[0].includes('仍有文章'));
|
||||
action(page, page.value().articles[0], '删除').props.onClick();
|
||||
page.confirms.at(-1).onOk();
|
||||
page.render();
|
||||
assert.equal(page.value().articles.length, 1);
|
||||
assert.deepEqual(page.value().articles[0].related, []);
|
||||
page
|
||||
.find('Button', (p) => p['aria-label'] === '删除产品更新')
|
||||
.props.onClick();
|
||||
page.confirms.at(-1).onOk();
|
||||
page.render();
|
||||
assert.ok(!page.value().categories.some((c) => c.id === 'product'));
|
||||
});
|
||||
|
||||
test('article row link actions open the editor and confirm deletion', () => {
|
||||
const initial = article('a', { related: ['b'] });
|
||||
const page = harness({
|
||||
...model.emptyInsights(),
|
||||
articles: [initial, article('b')],
|
||||
});
|
||||
const actions = actionsOf(page, initial);
|
||||
assert.deepEqual(
|
||||
Array.from(actions, (button) => button.props.children),
|
||||
['编辑', '上移', '下移', '删除'],
|
||||
);
|
||||
for (const button of actions) {
|
||||
assert.equal(button.props.type, 'link');
|
||||
assert.equal(button.props.size, 'small');
|
||||
}
|
||||
assert.equal(action(page, initial, '删除').props.danger, true);
|
||||
action(page, initial, '编辑').props.onClick();
|
||||
page.render();
|
||||
assert.deepEqual(
|
||||
JSON.parse(JSON.stringify(page.find('ArticleEditor').props.initial)),
|
||||
initial,
|
||||
);
|
||||
assert.notEqual(
|
||||
page.find('ArticleEditor').props.initial.related,
|
||||
initial.related,
|
||||
);
|
||||
action(page, initial, '删除').props.onClick();
|
||||
assert.equal(page.value().articles.length, 2);
|
||||
assert.equal(page.confirms.at(-1).title, '删除文章');
|
||||
page.confirms.at(-1).onOk();
|
||||
assert.equal(page.value().articles.length, 1);
|
||||
});
|
||||
|
||||
test('local fuzzy search and category filtering display all matches without pagination', () => {
|
||||
const page = harness({
|
||||
...model.emptyInsights(),
|
||||
articles: Array.from({ length: 23 }, (_, i) => article(`a${i}`)),
|
||||
});
|
||||
assert.equal(page.find('CardTable').props.dataSource.length, 23);
|
||||
assert.equal(page.find('CardTable').props.hidePagination, true);
|
||||
assert.equal(page.find('Pagination'), undefined);
|
||||
assert.equal(page.find('ConsoleFilterField').props.label, '文章标题');
|
||||
assert.equal(
|
||||
page.find('Input', (p) => p['aria-label'] === '搜索文章标题或摘要').props
|
||||
.showClear,
|
||||
true,
|
||||
);
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '搜索文章标题或摘要')
|
||||
.props.onChange('a22');
|
||||
page.render();
|
||||
assert.equal(page.find('Pagination'), undefined);
|
||||
assert.equal(page.find('CardTable').props.dataSource.length, 1);
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '搜索文章标题或摘要')
|
||||
.props.onChange('');
|
||||
page.render();
|
||||
assert.equal(page.find('CardTable').props.dataSource.length, 23);
|
||||
page.find('Select').props.onChange('industry');
|
||||
page.render();
|
||||
assert.equal(page.find('CardTable').props.dataSource.length, 0);
|
||||
page.button('新增文章').props.onClick();
|
||||
page.render();
|
||||
assert.equal(page.find('ArticleEditor').props.initial.category, 'industry');
|
||||
page
|
||||
.find('ArticleEditor')
|
||||
.props.onApply(article('', { title: '新文章', category: 'industry' }));
|
||||
page.render();
|
||||
assert.equal(page.value().articles.length, 24);
|
||||
assert.equal(page.value().articles[0].title, '新文章');
|
||||
});
|
||||
|
||||
test('without categories new articles are blocked with a hint', () => {
|
||||
const page = harness({ categories: [], articles: [] });
|
||||
assert.equal(page.button('新增文章').props.disabled, true);
|
||||
assert.ok(
|
||||
page.find('Paragraph', (p) =>
|
||||
String(p.children).includes('请先新增内容分类'),
|
||||
),
|
||||
);
|
||||
assert.deepEqual(
|
||||
Array.from(page.find('CardTable').props.columns, (column) => column.title),
|
||||
['文章标题', '所属分类', '角标', '发布日期', '操作'],
|
||||
);
|
||||
});
|
||||
|
||||
test('articles reorder only in the unfiltered list, which is the website order', () => {
|
||||
const page = harness({
|
||||
...model.emptyInsights(),
|
||||
articles: [
|
||||
article('a'),
|
||||
article('b'),
|
||||
article('c', { category: 'product' }),
|
||||
],
|
||||
});
|
||||
const first = page.value().articles[0];
|
||||
assert.equal(action(page, first, '上移').props.disabled, true);
|
||||
action(page, first, '下移').props.onClick();
|
||||
page.render();
|
||||
assert.deepEqual(
|
||||
page.value().articles.map((a) => a.id),
|
||||
['b', 'a', 'c'],
|
||||
);
|
||||
const last = page.value().articles.at(-1);
|
||||
assert.equal(action(page, last, '下移').props.disabled, true);
|
||||
page.find('Select').props.onChange('company');
|
||||
page.render();
|
||||
assert.equal(
|
||||
action(page, page.value().articles[1], '上移').props.disabled,
|
||||
true,
|
||||
);
|
||||
page.find('Select').props.onChange('all');
|
||||
page
|
||||
.find('Input', (p) => p['aria-label'] === '搜索文章标题或摘要')
|
||||
.props.onChange('a');
|
||||
page.render();
|
||||
assert.equal(
|
||||
action(page, page.value().articles[1], '上移').props.disabled,
|
||||
true,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,237 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
TABS,
|
||||
emptySettings,
|
||||
normalizeSettings,
|
||||
serializeSettings,
|
||||
sanitizeMetricInput,
|
||||
splitAmount,
|
||||
joinAmount,
|
||||
metricPreview,
|
||||
validateField,
|
||||
validateSettings,
|
||||
validateImageFile,
|
||||
resolveImageUrl,
|
||||
} from '../../src/pages/WebsiteSettings/model.js';
|
||||
|
||||
const validValues = () => ({
|
||||
insights: {
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
paidCustomers: '300',
|
||||
dailyTokens: '500亿',
|
||||
costReduction: '20',
|
||||
teamMembers: '50',
|
||||
researchRatio: '60',
|
||||
headquarters: '珠海 / 广州',
|
||||
serviceNetwork: '辐射全国',
|
||||
businessPhone: '020-88888888',
|
||||
businessEmail: 'business@example.com',
|
||||
wechatQrCode: 'https://cdn.example.com/qr.png',
|
||||
address: '广州市天河区示例路 1 号',
|
||||
});
|
||||
|
||||
test('final save serializes rich text and structured insights exactly once', () => {
|
||||
const settings = {
|
||||
...validValues(),
|
||||
insights: {
|
||||
categories: [{ id: 'company', name: '公司动态' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'news',
|
||||
title: ' 标题 ',
|
||||
category: 'company',
|
||||
date: '2026-10-31',
|
||||
summary: '摘要',
|
||||
tag: '',
|
||||
body: '<h2>章节</h2><p><strong>正文</strong></p>',
|
||||
related: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const serialized = serializeSettings(settings);
|
||||
assert.equal(typeof serialized, 'string');
|
||||
const decoded = JSON.parse(serialized);
|
||||
assert.equal(decoded.insights.articles[0].title, '标题');
|
||||
assert.equal(
|
||||
decoded.insights.articles[0].body,
|
||||
settings.insights.articles[0].body,
|
||||
);
|
||||
assert.ok(Array.isArray(decoded.insights.articles));
|
||||
assert.ok(Array.isArray(decoded.insights.articles[0].related));
|
||||
assert.equal(settings.insights.articles[0].title, ' 标题 ');
|
||||
});
|
||||
|
||||
test('backend upload mode rejects local preview data URLs', () => {
|
||||
assert.ok(validateField('wechatQrCode', 'data:image/png;base64,AAAA'));
|
||||
assert.ok(validateField('wechatQrCode', 'data:text/html;base64,AAAA'));
|
||||
assert.ok(validateField('wechatQrCode', 'data:image/svg+xml;base64,AAAA'));
|
||||
});
|
||||
|
||||
test('validates all tabs using a flat payload with one shared team count', () => {
|
||||
assert.deepEqual(validateSettings(validValues()), {});
|
||||
assert.equal(Object.keys(validateSettings(emptySettings())).length, 11);
|
||||
assert.equal(validateSettings(emptySettings()).insights, undefined);
|
||||
assert.ok(TABS[0].fields.includes('teamMembers'));
|
||||
assert.ok(TABS[1].fields.includes('teamMembers'));
|
||||
assert.equal(
|
||||
Object.keys(emptySettings()).filter((key) => key === 'teamMembers').length,
|
||||
1,
|
||||
);
|
||||
const values = validValues();
|
||||
values.address = ' ';
|
||||
assert.ok(validateSettings(values).address);
|
||||
});
|
||||
|
||||
test('global saving allows an empty article list for the website empty state', () => {
|
||||
assert.deepEqual(
|
||||
validateSettings({
|
||||
...validValues(),
|
||||
insights: emptySettings().insights,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
assert.ok(
|
||||
validateSettings({
|
||||
...validValues(),
|
||||
insights: {
|
||||
...emptySettings().insights,
|
||||
articles: [{ ...validValues().insights.articles[0], category: 'all' }],
|
||||
},
|
||||
}).insights,
|
||||
);
|
||||
assert.deepEqual(validateSettings(validValues()), {});
|
||||
});
|
||||
|
||||
test('metrics store plain numbers and reject units typed by hand', () => {
|
||||
for (const value of ['1', '50', '300'])
|
||||
assert.equal(validateField('teamMembers', value), '');
|
||||
for (const value of ['-1', '0', '01', '1.2', 'abc', '50+'])
|
||||
assert.ok(validateField('teamMembers', value));
|
||||
for (const value of ['500亿', '0.5万', '12.25亿'])
|
||||
assert.equal(validateField('dailyTokens', value), '');
|
||||
for (const value of [
|
||||
'0亿',
|
||||
'500',
|
||||
'-3亿',
|
||||
'500亿abc',
|
||||
'500亿+',
|
||||
'05亿',
|
||||
'1.234亿',
|
||||
])
|
||||
assert.ok(validateField('dailyTokens', value));
|
||||
for (const value of ['0', '100', '99.99', '0.5'])
|
||||
assert.equal(validateField('researchRatio', value), '');
|
||||
for (const value of ['101', '-1', '60.123', '↓20', '20%', '007'])
|
||||
assert.ok(validateField('costReduction', value));
|
||||
});
|
||||
|
||||
test('metric helpers sanitize input, split units and preview the website text', () => {
|
||||
assert.equal(sanitizeMetricInput(' 300+ '), '300');
|
||||
assert.equal(sanitizeMetricInput('12。5%'), '12.5');
|
||||
assert.equal(sanitizeMetricInput('1,000'), '1000');
|
||||
assert.deepEqual(splitAmount('500万'), { number: '500', unit: '万' });
|
||||
assert.deepEqual(splitAmount(''), { number: '', unit: '亿' });
|
||||
assert.equal(joinAmount('500', '亿'), '500亿');
|
||||
assert.equal(joinAmount('', '万'), '');
|
||||
assert.equal(metricPreview('paidCustomers', '300'), '300+');
|
||||
assert.equal(metricPreview('dailyTokens', '500亿'), '500亿+');
|
||||
assert.equal(metricPreview('costReduction', '20'), '↓20%');
|
||||
assert.equal(metricPreview('researchRatio', '60'), '60%');
|
||||
assert.equal(metricPreview('teamMembers', '50+'), '');
|
||||
assert.equal(metricPreview('headquarters', '珠海'), '');
|
||||
});
|
||||
|
||||
test('checks business telephone and email formats', () => {
|
||||
for (const value of [
|
||||
'13800138000',
|
||||
'+86 13800138000',
|
||||
'020-88888888',
|
||||
'01088888888转123',
|
||||
'400-123-4567',
|
||||
])
|
||||
assert.equal(validateField('businessPhone', value), '');
|
||||
for (const value of ['123', 'abcdefgh', '138001380001', '100-123-4567'])
|
||||
assert.ok(validateField('businessPhone', value));
|
||||
for (const value of ['sales@example.com', 'sales+demo@sub.example.cn'])
|
||||
assert.equal(validateField('businessEmail', value), '');
|
||||
for (const value of [
|
||||
'sales',
|
||||
'sales@',
|
||||
'@example.com',
|
||||
'a b@example.com',
|
||||
'a..b@example.com',
|
||||
'.ab@example.com',
|
||||
'ab.@example.com',
|
||||
'ab@-example.com',
|
||||
])
|
||||
assert.ok(validateField('businessEmail', value));
|
||||
});
|
||||
|
||||
test('clear values remove every field and normalization keeps only the flat schema', () => {
|
||||
assert.ok(
|
||||
Object.entries(emptySettings())
|
||||
.filter(([key]) => key !== 'insights')
|
||||
.every(([, value]) => value === ''),
|
||||
);
|
||||
assert.deepEqual(emptySettings().insights.articles, []);
|
||||
const result = normalizeSettings({
|
||||
...validValues(),
|
||||
address: ' 地址 ',
|
||||
home: { extra: true },
|
||||
});
|
||||
assert.equal(result.address, '地址');
|
||||
assert.equal(result.home, undefined);
|
||||
assert.equal(Object.keys(result).length, 12);
|
||||
});
|
||||
|
||||
test('restricts uploads to supported image types and at most 2 MB', () => {
|
||||
assert.equal(
|
||||
validateImageFile({ type: 'image/png', size: 2 * 1024 * 1024 }),
|
||||
'',
|
||||
);
|
||||
for (const type of ['image/jpeg', 'image/webp'])
|
||||
assert.equal(validateImageFile({ type, size: 100 }), '');
|
||||
for (const size of [0, 2 * 1024 * 1024 + 1])
|
||||
assert.ok(validateImageFile({ type: 'image/png', size }));
|
||||
for (const type of ['image/svg+xml', 'image/gif', 'text/plain'])
|
||||
assert.ok(validateImageFile({ type, size: 100 }));
|
||||
});
|
||||
|
||||
test('requires permanent HTTP(S) resource URLs and an explicit base for relative paths', () => {
|
||||
assert.equal(
|
||||
resolveImageUrl('https://cdn.example.com/qr.png'),
|
||||
'https://cdn.example.com/qr.png',
|
||||
);
|
||||
assert.equal(
|
||||
resolveImageUrl('/uploads/qr.png', 'https://cdn.example.com'),
|
||||
'https://cdn.example.com/uploads/qr.png',
|
||||
);
|
||||
for (const url of [
|
||||
'/uploads/qr.png',
|
||||
'blob:https://example.com/id',
|
||||
'data:image/png;base64,123',
|
||||
'javascript:alert(1)',
|
||||
'https://user:pass@example.com/qr.png',
|
||||
]) {
|
||||
assert.throws(() => resolveImageUrl(url));
|
||||
assert.ok(validateField('wechatQrCode', url));
|
||||
}
|
||||
assert.throws(() =>
|
||||
resolveImageUrl('//unknown.example/qr.png', 'https://cdn.example.com'),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,530 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import React from 'react';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
import * as model from '../../src/pages/WebsiteSettings/model.js';
|
||||
|
||||
const filename = new URL(
|
||||
'../../src/pages/WebsiteSettings/index.jsx',
|
||||
import.meta.url,
|
||||
);
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(filename, 'utf8'),
|
||||
filename.pathname,
|
||||
{ loader: 'jsx', format: 'cjs' },
|
||||
);
|
||||
|
||||
// Exercise actual page callbacks and state transitions without a DOM or network.
|
||||
async function createHarness({
|
||||
config = null,
|
||||
load = async () => config,
|
||||
} = {}) {
|
||||
const states = [];
|
||||
const warnings = [];
|
||||
const requests = [];
|
||||
const messages = [];
|
||||
const effects = [];
|
||||
const pendingEffects = [];
|
||||
let cursor = 0;
|
||||
let mounting = true;
|
||||
let tree;
|
||||
let respond = async () => ({ saved: true });
|
||||
const modules = {
|
||||
react: {
|
||||
...React,
|
||||
useEffect(callback, deps) {
|
||||
const index = cursor++;
|
||||
const previous = effects[index];
|
||||
if (
|
||||
!previous ||
|
||||
deps.some((dep, i) => !Object.is(dep, previous.deps[i]))
|
||||
) {
|
||||
pendingEffects.push(() => {
|
||||
previous?.cleanup?.();
|
||||
effects[index] = { deps, cleanup: callback() };
|
||||
});
|
||||
}
|
||||
},
|
||||
useRef(value) {
|
||||
const index = cursor++;
|
||||
if (mounting) states[index] = { current: value };
|
||||
return states[index];
|
||||
},
|
||||
useState(initial) {
|
||||
const index = cursor++;
|
||||
if (mounting)
|
||||
states[index] = typeof initial === 'function' ? initial() : initial;
|
||||
return [
|
||||
states[index],
|
||||
(next) => {
|
||||
states[index] =
|
||||
typeof next === 'function' ? next(states[index]) : next;
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
'@/components/ui': {
|
||||
Spin: 'Spin',
|
||||
Banner: 'Banner',
|
||||
Button: 'Button',
|
||||
Card: 'Card',
|
||||
Divider: 'Divider',
|
||||
Form: 'Form',
|
||||
Tabs: Object.assign(() => {}, { TabPane: 'TabPane' }),
|
||||
Typography: { Title: 'Title', Paragraph: 'Paragraph', Text: 'Text' },
|
||||
Modal: { warning: (options) => warnings.push(options) },
|
||||
},
|
||||
'react-i18next': {
|
||||
useTranslation: () => ({
|
||||
t: (value, options) =>
|
||||
value.replace(/{{(\w+)}}/g, (_, key) => options?.[key] ?? ''),
|
||||
}),
|
||||
},
|
||||
'../../helpers': Object.fromEntries(
|
||||
['showInfo', 'showError', 'showSuccess', 'showWarning'].map((name) => [
|
||||
name,
|
||||
(message) => messages.push({ name, message }),
|
||||
]),
|
||||
),
|
||||
'./model': model,
|
||||
'./WebsiteSettings.css': {},
|
||||
'./settingsApi': {
|
||||
getWebsiteSettings: load,
|
||||
saveWebsiteSettings: async (payload) => {
|
||||
assert.equal(typeof payload, 'string');
|
||||
requests.push(JSON.parse(payload));
|
||||
return respond();
|
||||
},
|
||||
},
|
||||
'./WebsiteField': { default: 'WebsiteField', __esModule: true },
|
||||
'./QrCodeUpload': { default: 'QrCodeUpload', __esModule: true },
|
||||
'./InsightsPanel': { default: 'InsightsPanel', __esModule: true },
|
||||
};
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
window: { addEventListener() {}, removeEventListener() {} },
|
||||
exports: module.exports,
|
||||
module,
|
||||
require: (name) => {
|
||||
assert.ok(modules[name], name);
|
||||
return modules[name];
|
||||
},
|
||||
});
|
||||
const render = () => {
|
||||
cursor = 0;
|
||||
tree = module.exports.default();
|
||||
mounting = false;
|
||||
pendingEffects.splice(0).forEach((effect) => effect());
|
||||
return tree;
|
||||
};
|
||||
function all(node) {
|
||||
if (Array.isArray(node)) return node.flatMap((child) => all(child));
|
||||
if (!node || typeof node !== 'object') return [];
|
||||
return [node, ...all(node.props?.children)];
|
||||
}
|
||||
const find = (type, predicate = () => true) =>
|
||||
all(tree).find((node) => node.type === type && predicate(node.props));
|
||||
const switchTab = (key) => {
|
||||
find(modules['@/components/ui'].Tabs).props.onChange(key);
|
||||
render();
|
||||
};
|
||||
render();
|
||||
await new Promise(setImmediate);
|
||||
render();
|
||||
return {
|
||||
render,
|
||||
find,
|
||||
switchTab,
|
||||
warnings,
|
||||
requests,
|
||||
messages,
|
||||
field: (name) => find('WebsiteField', (props) => props.name === name),
|
||||
save: () => find('Form').props.onSubmit(),
|
||||
setRespond: (next) => {
|
||||
respond = next;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function fillAll(page) {
|
||||
const values = {
|
||||
paidCustomers: '300',
|
||||
dailyTokens: '500亿',
|
||||
costReduction: '20',
|
||||
teamMembers: '50',
|
||||
researchRatio: '60',
|
||||
headquarters: '珠海',
|
||||
serviceNetwork: '全国',
|
||||
businessPhone: '13800138000',
|
||||
businessEmail: 'sales@example.com',
|
||||
wechatQrCode: 'https://cdn.example.com/qr.png',
|
||||
address: ' 广州 ',
|
||||
};
|
||||
for (const tab of model.TABS) {
|
||||
if (tab.key === 'insights') continue;
|
||||
page.switchTab(tab.key);
|
||||
for (const name of tab.fields) {
|
||||
page.field(name).props.onChange(values[name]);
|
||||
page.render();
|
||||
}
|
||||
}
|
||||
page.switchTab('insights');
|
||||
page.find('InsightsPanel').props.onChange({
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
});
|
||||
page.switchTab('demo');
|
||||
}
|
||||
|
||||
test('saving marks all fields inline and emits one ordered summary per hidden invalid tab', async () => {
|
||||
const page = await createHarness();
|
||||
page.switchTab('insights');
|
||||
await page.save();
|
||||
page.render();
|
||||
assert.equal(page.requests.length, 0);
|
||||
assert.equal(page.warnings.length, 0);
|
||||
assert.deepEqual(
|
||||
page.messages.map((item) => item.message),
|
||||
['请完善首页的配置', '请完善关于微词元的配置', '请完善预约演示的配置'],
|
||||
);
|
||||
page.switchTab('home');
|
||||
assert.equal(page.field('paidCustomers').props.error, '请输入付费企业客户');
|
||||
page.switchTab('demo');
|
||||
assert.equal(page.field('wechatQrCode').props.error, '请上传企业微信二维码');
|
||||
});
|
||||
|
||||
test('team count is shared across tabs and clear removes every value and error', async () => {
|
||||
const page = await createHarness();
|
||||
page.field('teamMembers').props.onChange('88');
|
||||
page.switchTab('about');
|
||||
assert.equal(page.field('teamMembers').props.value, '88');
|
||||
await page.save();
|
||||
page.render();
|
||||
page.find('Button', (props) => props.children === '清空').props.onClick();
|
||||
page.render();
|
||||
for (const tab of model.TABS) {
|
||||
page.switchTab(tab.key);
|
||||
if (tab.key === 'insights') {
|
||||
assert.equal(page.find('InsightsPanel').props.value.articles.length, 0);
|
||||
assert.equal(page.find('InsightsPanel').props.error, undefined);
|
||||
continue;
|
||||
}
|
||||
for (const name of tab.fields) {
|
||||
assert.equal(page.field(name).props.value, '');
|
||||
assert.equal(page.field(name).props.error, undefined);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('submits all tabs in the documented groups and reports success after persistence', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 1);
|
||||
assert.equal(Object.keys(page.requests[0]).length, 4);
|
||||
assert.equal(page.requests[0].demo.address, '广州');
|
||||
assert.equal(page.requests[0].about.teamMembers, '50');
|
||||
assert.ok(
|
||||
page.messages.some(
|
||||
(item) =>
|
||||
item.name === 'showSuccess' && item.message === '官网设置已保存',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('upload in progress blocks saving and request failure preserves form contents', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.find('QrCodeUpload').props.onBusyChange(true);
|
||||
page.render();
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 0);
|
||||
page.find('QrCodeUpload').props.onBusyChange(false);
|
||||
page.render();
|
||||
page.setRespond(async () => {
|
||||
throw new Error('测试请求失败');
|
||||
});
|
||||
await page.save();
|
||||
page.render();
|
||||
assert.equal(page.field('address').props.value, ' 广州 ');
|
||||
assert.ok(page.messages.some((item) => item.name === 'showError'));
|
||||
});
|
||||
|
||||
test('insights configuration survives tab changes and is included in the single payload', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('insights');
|
||||
const insights = {
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
};
|
||||
page.find('InsightsPanel').props.onChange(insights);
|
||||
page.switchTab('home');
|
||||
page.switchTab('insights');
|
||||
assert.deepEqual(page.find('InsightsPanel').props.value, insights);
|
||||
await page.save();
|
||||
assert.deepEqual(page.requests[0].insights, insights);
|
||||
});
|
||||
|
||||
test('invalid hidden insights configuration emits a single summary and keeps the current tab', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('insights');
|
||||
page
|
||||
.find('InsightsPanel')
|
||||
.props.onChange({ categories: [], articles: [{ id: 'invalid' }] });
|
||||
page.switchTab('home');
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 0);
|
||||
page.render();
|
||||
assert.ok(page.field('paidCustomers'));
|
||||
assert.deepEqual(
|
||||
page.messages.map((item) => item.message),
|
||||
['请完善动态与洞察的配置'],
|
||||
);
|
||||
assert.equal(page.warnings.length, 0);
|
||||
page.switchTab('insights');
|
||||
assert.ok(page.find('InsightsPanel').props.error);
|
||||
});
|
||||
|
||||
for (const activeTab of ['home', 'about', 'demo']) {
|
||||
test(`saving empty ${activeTab} reports hidden tabs in navigation order`, async () => {
|
||||
const page = await createHarness();
|
||||
page.switchTab(activeTab);
|
||||
await page.save();
|
||||
page.render();
|
||||
assert.equal(page.requests.length, 0);
|
||||
assert.deepEqual(
|
||||
page.messages.map((item) => item.message),
|
||||
model.TABS.filter(
|
||||
(tab) => tab.key !== activeTab && tab.key !== 'insights',
|
||||
).map((tab) => `请完善${tab.label}的配置`),
|
||||
);
|
||||
page.switchTab('insights');
|
||||
assert.equal(page.find('InsightsPanel').props.error, undefined);
|
||||
});
|
||||
|
||||
test(`saving ${activeTab} allows an empty article list and validates added articles`, async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('insights');
|
||||
page.find('InsightsPanel').props.onChange(model.emptySettings().insights);
|
||||
page.switchTab(activeTab);
|
||||
await page.save();
|
||||
page.render();
|
||||
assert.equal(page.requests.length, 1);
|
||||
assert.deepEqual(page.requests[0].insights.articles, []);
|
||||
assert.ok(
|
||||
page.field(model.TABS.find((tab) => tab.key === activeTab).fields[0]),
|
||||
);
|
||||
|
||||
page.switchTab('insights');
|
||||
page.find('InsightsPanel').props.onChange({
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
});
|
||||
page.switchTab(activeTab);
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 2);
|
||||
});
|
||||
}
|
||||
|
||||
test('home team preview shows the current research ratio after edits in about', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('home');
|
||||
assert.equal(page.field('teamMembers').props.preview, '50+ · 研发占比 60%');
|
||||
page.switchTab('about');
|
||||
assert.equal(page.field('teamMembers').props.preview, undefined);
|
||||
page.field('researchRatio').props.onChange('75');
|
||||
page.switchTab('home');
|
||||
assert.equal(page.field('teamMembers').props.preview, '50+ · 研发占比 75%');
|
||||
page.switchTab('about');
|
||||
page.field('researchRatio').props.onChange('');
|
||||
page.switchTab('home');
|
||||
assert.equal(
|
||||
page.field('teamMembers').props.preview,
|
||||
'50+ · 研发占比 未配置',
|
||||
);
|
||||
page.field('teamMembers').props.onChange('abc');
|
||||
page.render();
|
||||
assert.equal(page.field('teamMembers').props.preview, '');
|
||||
});
|
||||
|
||||
test('only the active invalid tab uses inline messages without summary popups', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('home');
|
||||
page.field('paidCustomers').props.onChange('');
|
||||
page.render();
|
||||
await page.save();
|
||||
page.render();
|
||||
assert.equal(page.field('paidCustomers').props.error, '请输入付费企业客户');
|
||||
assert.equal(page.messages.length, 0);
|
||||
assert.equal(page.requests.length, 0);
|
||||
});
|
||||
|
||||
test('a shared invalid field still flags its hidden tab exactly once', async () => {
|
||||
const page = await createHarness();
|
||||
fillAll(page);
|
||||
page.switchTab('home');
|
||||
page.field('teamMembers').props.onChange('');
|
||||
page.render();
|
||||
await page.save();
|
||||
assert.deepEqual(
|
||||
page.messages.map((item) => item.message),
|
||||
['请完善关于微词元的配置'],
|
||||
);
|
||||
});
|
||||
|
||||
test('initial loading populates all tabs and saving retains root and grouped extension fields', async () => {
|
||||
const config = {
|
||||
insights: {
|
||||
categories: [{ id: 'news', name: '新闻' }],
|
||||
articles: [
|
||||
{
|
||||
id: 'article-1',
|
||||
title: 'News',
|
||||
summary: 'Summary',
|
||||
category: 'news',
|
||||
date: '2026-11-10',
|
||||
body: '<p>Content</p>',
|
||||
related: [],
|
||||
tag: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
home: {
|
||||
payingCustomers: '200',
|
||||
dailyTokenCalls: '10亿',
|
||||
monthlyAiCostReduction: '30',
|
||||
extra: 'keep',
|
||||
},
|
||||
about: {
|
||||
teamMembers: '100',
|
||||
researchStaffRatio: '70',
|
||||
headquarters: '深圳',
|
||||
serviceNetwork: '全国',
|
||||
},
|
||||
demo: {
|
||||
businessPhone: '0755-12345678',
|
||||
businessEmail: 'demo@example.com',
|
||||
wechatQrCode: 'https://cdn.example.com/qr.png',
|
||||
address: '深圳地址',
|
||||
},
|
||||
extension: { version: 2 },
|
||||
};
|
||||
const page = await createHarness({ config });
|
||||
assert.equal(page.field('paidCustomers').props.value, '200');
|
||||
assert.equal(page.field('teamMembers').props.value, '100');
|
||||
page.switchTab('about');
|
||||
assert.equal(page.field('researchRatio').props.value, '70');
|
||||
page.field('teamMembers').props.onChange('120');
|
||||
page.switchTab('demo');
|
||||
assert.equal(
|
||||
page.field('wechatQrCode').props.value,
|
||||
config.demo.wechatQrCode,
|
||||
);
|
||||
await page.save();
|
||||
assert.equal(page.requests[0].about.teamMembers, '120');
|
||||
assert.equal(page.requests[0].home.extra, 'keep');
|
||||
assert.deepEqual(page.requests[0].extension, { version: 2 });
|
||||
});
|
||||
|
||||
test('normal loaded state does not render the redundant unconfigured banner', async () => {
|
||||
const page = await createHarness({ config: null });
|
||||
assert.equal(
|
||||
page.find('Banner', (props) =>
|
||||
String(props.description).includes('官网尚未配置'),
|
||||
),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
test('failed initial loading shows an inline error without retry and blocks edits and saving', async () => {
|
||||
const page = await createHarness({
|
||||
load: async () => {
|
||||
throw new Error('配置读取失败');
|
||||
},
|
||||
});
|
||||
assert.equal(page.field('paidCustomers').props.disabled, true);
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 0);
|
||||
assert.equal(page.find('Banner').props.description, '配置读取失败');
|
||||
assert.equal(page.find('Banner').props.type, 'danger');
|
||||
assert.equal(
|
||||
page.find('Banner').props.className,
|
||||
'website-settings-load-error',
|
||||
);
|
||||
assert.equal(page.find('Banner').props.children, undefined);
|
||||
assert.equal(
|
||||
page.find('Button', (props) => props.children === '重新加载'),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
test('pending initial reads and duplicate save clicks never send unintended writes', async () => {
|
||||
let resolveLoad;
|
||||
const page = await createHarness({
|
||||
load: () =>
|
||||
new Promise((resolve) => {
|
||||
resolveLoad = resolve;
|
||||
}),
|
||||
});
|
||||
assert.equal(page.field('paidCustomers').props.disabled, true);
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 0);
|
||||
resolveLoad(null);
|
||||
await new Promise(setImmediate);
|
||||
page.render();
|
||||
fillAll(page);
|
||||
let resolveSave;
|
||||
page.setRespond(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
resolveSave = resolve;
|
||||
}),
|
||||
);
|
||||
const first = page.save();
|
||||
await page.save();
|
||||
assert.equal(page.requests.length, 1);
|
||||
assert.equal(page.messages.length, 0);
|
||||
resolveSave({ saved: true });
|
||||
await first;
|
||||
assert.equal(page.messages[0].name, 'showSuccess');
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
articleImageSource,
|
||||
ARTICLE_IMAGE_LIMIT,
|
||||
} from '../../src/components/common/ui/richTextImages.js';
|
||||
import {
|
||||
articleErrors,
|
||||
emptyInsights,
|
||||
newArticle,
|
||||
} from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
import {
|
||||
emptySettings,
|
||||
serializeSettings,
|
||||
} from '../../src/pages/WebsiteSettings/model.js';
|
||||
|
||||
const png =
|
||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=';
|
||||
|
||||
test('pasted images survive article validation and final JSON serialization without a cover field', () => {
|
||||
const article = {
|
||||
...newArticle('company'),
|
||||
id: 'pasted',
|
||||
title: '图文粘贴',
|
||||
summary: '摘要',
|
||||
body: `<h2>图文标题</h2><p>正文<img src="${png}"></p>`,
|
||||
};
|
||||
const insights = { ...emptyInsights(), articles: [article] };
|
||||
assert.deepEqual(articleErrors(article, insights), {});
|
||||
const restored = JSON.parse(
|
||||
serializeSettings({ ...emptySettings(), insights }),
|
||||
);
|
||||
assert.equal(restored.insights.articles[0].body, article.body);
|
||||
assert.equal('cover' in restored.insights.articles[0], false);
|
||||
});
|
||||
|
||||
test('image sources accept public URLs and bounded raster data, rejecting unsafe or temporary sources', () => {
|
||||
assert.equal(articleImageSource(png), png);
|
||||
assert.equal(
|
||||
articleImageSource('https://cdn.example.com/a.png'),
|
||||
'https://cdn.example.com/a.png',
|
||||
);
|
||||
for (const source of [
|
||||
'javascript:alert(1)',
|
||||
'blob:https://example.com/id',
|
||||
'/private/a.png',
|
||||
'file:///tmp/a.png',
|
||||
'https://user:pass@example.com/a.png',
|
||||
'data:image/svg+xml;base64,PHN2Zz4=',
|
||||
'data:text/html;base64,AAAA',
|
||||
'data:image/png;base64,notbase64!',
|
||||
])
|
||||
assert.equal(articleImageSource(source), '', source);
|
||||
const maximum = 'A'.repeat(Math.ceil(ARTICLE_IMAGE_LIMIT / 3) * 4 - 1) + '=';
|
||||
assert.ok(articleImageSource(`data:image/png;base64,${maximum}`));
|
||||
assert.equal(
|
||||
articleImageSource(
|
||||
`data:image/png;base64,${'A'.repeat(maximum.length + 4)}`,
|
||||
),
|
||||
'',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import Delta from 'quill-delta';
|
||||
import {
|
||||
ARTICLE_BODY_LIMIT,
|
||||
countArticleHtml,
|
||||
countRichText,
|
||||
limitRichTextChange,
|
||||
} from '../../src/components/common/ui/richTextLength.js';
|
||||
import {
|
||||
articleErrors,
|
||||
emptyInsights,
|
||||
newArticle,
|
||||
} from '../../src/pages/WebsiteSettings/insightsModel.js';
|
||||
|
||||
const bounded = (old, change) =>
|
||||
old.compose(new Delta(limitRichTextChange(old, change, ARTICLE_BODY_LIMIT)));
|
||||
const text = (delta) =>
|
||||
delta.ops
|
||||
.map((op) => (typeof op.insert === 'string' ? op.insert : ''))
|
||||
.join('');
|
||||
|
||||
test('counts visible Unicode characters and entities, excluding whitespace, markup and images', () => {
|
||||
assert.equal(countRichText('中 A😀\n\t'), 3);
|
||||
assert.equal(
|
||||
countArticleHtml(
|
||||
'<p>中 &😀 </p><img src="https://example.com/a.png">',
|
||||
),
|
||||
3,
|
||||
);
|
||||
});
|
||||
|
||||
test('typing and long paste respect the limit without deleting text after the caret', () => {
|
||||
const old = new Delta().insert('甲'.repeat(19998) + '尾\n');
|
||||
const next = bounded(old, new Delta().retain(19998).insert('新增文字'));
|
||||
assert.equal(text(next), '甲'.repeat(19998) + '新尾\n');
|
||||
assert.equal(countRichText(text(next)), 20000);
|
||||
assert.deepEqual(bounded(next, new Delta().retain(20000).insert('多')), next);
|
||||
});
|
||||
|
||||
test('selection replacement, deletion, formatting, emoji and images remain usable at the limit', () => {
|
||||
const old = new Delta().insert('甲'.repeat(20000) + '\n');
|
||||
const next = bounded(
|
||||
old,
|
||||
new Delta()
|
||||
.retain(10)
|
||||
.delete(2)
|
||||
.insert('😀乙丙', { bold: true })
|
||||
.insert({ image: 'https://example.com/a.png' }),
|
||||
);
|
||||
assert.equal(countRichText(text(next)), 20000);
|
||||
assert.ok(text(next).includes('😀乙'));
|
||||
assert.ok(next.ops.some((op) => op.insert.image));
|
||||
assert.ok(next.ops.some((op) => op.attributes?.bold));
|
||||
assert.equal(countRichText(text(bounded(old, new Delta().delete(1)))), 19999);
|
||||
});
|
||||
|
||||
test('article validation accepts 20000 characters and blocks oversized existing drafts', () => {
|
||||
const article = {
|
||||
...newArticle(),
|
||||
title: '标题',
|
||||
summary: '摘要',
|
||||
body: `<p>${'中'.repeat(20000)}</p>`,
|
||||
};
|
||||
assert.equal(articleErrors(article, emptyInsights()).body, undefined);
|
||||
article.body = `<p>${'中'.repeat(20001)}</p>`;
|
||||
assert.equal(
|
||||
articleErrors(article, emptyInsights()).body,
|
||||
'文章正文不能超过 20000 字',
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user