fix(ui): 修复登录与并发请求并统一表格、主题和页面展示

验证:868 项单测、ESLint、Prettier、UI 依赖审计和差异检查通过。
This commit is contained in:
zhanjunhao
2026-11-19 18:58:46 +08:00
parent 9f5e0cddfb
commit e70e0d2224
128 changed files with 4672 additions and 5391 deletions
+94
View File
@@ -0,0 +1,94 @@
/*
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';
import {
resolveBrandPalette,
resolveGradientLabel,
} from '../../src/helpers/brandPalette.js';
import { PRESETS } from '../../src/styles/presets.js';
test('brand interactions retain readable contrast in all solid states', () => {
for (const dark of [false, true]) {
const mode = dark ? 'dark' : 'light';
const surface = dark ? '#1b212b' : '#ffffff';
const inputs = [
...Object.values(PRESETS).map((preset) => preset[mode]['brand-primary']),
'#000000',
'#ffffff',
'#eaff00',
'#00ffff',
'#010331',
'#ee00ff',
'#ff552280',
'not-a-color',
];
for (const input of inputs) {
const palette = resolveBrandPalette(input, dark, surface);
for (const state of ['normal', 'hover', 'active']) {
const fill = colord(palette[state]);
assert.equal(fill.alpha(), 1);
assert.ok(
fill.contrast(palette.onSolid) >= 4.5,
[mode, input, state].join(' '),
);
}
assert.ok(
colord(palette.selectionText).contrast(palette.selectionBg) >= 4.5,
);
if (!palette.isPrototype) {
assert.ok(colord(palette.accent).contrast(palette.tintHover) >= 4.5);
assert.ok(colord(palette.tint).contrast(surface) < 1.6);
if (dark)
assert.ok(colord(palette.hover).contrast(palette.onSolid) < 7.1);
}
}
}
});
test('prototype amber retains its selected foreground and surface', () => {
const light = resolveBrandPalette('#B96508', false, '#ffffff');
const dark = resolveBrandPalette('#D1963A', true, '#1b212b');
assert.deepEqual(
[light.selectionBg, light.selectionText],
['#fff3df', '#a45a07'],
);
assert.deepEqual(
[dark.selectionBg, dark.selectionText],
['#382b1b', '#f2ad41'],
);
});
test('preview gradient labels use readable ink or a neutral backing', () => {
assert.deepEqual(resolveGradientLabel(['#d1963a', '#f2ad41'], '#101014'), {
color: '#11151c',
});
assert.deepEqual(resolveGradientLabel(['#0e192a', '#17436b'], '#f6f8fb'), {
color: '#ffffff',
});
assert.deepEqual(
resolveGradientLabel(['#ffffff80', '#ffffff00'], '#010101'),
{
color: '#ffffff',
background: '#010101',
},
);
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"src/pages/AdminOrganizations/index.jsx": 1,
"src/pages/AdminInvoice/index.jsx": 1,
"src/pages/AdminInvoice/index.jsx": 2,
"src/components/settings/DataSecuritySetting.jsx": 4,
"src/pages/Organization/OrgPrivateSkills.jsx": 2,
"src/pages/Organization/OrgSkillAssignments.jsx": 1,
+122
View File
@@ -0,0 +1,122 @@
/*
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 {
consumePostLoginRedirect,
DEFAULT_LOGIN_REDIRECT,
savePostLoginRedirect,
} from '../../src/helpers/data.js';
beforeEach(() => {
const storage = new Map();
globalThis.sessionStorage = {
getItem: (key) => storage.get(key) ?? null,
setItem: (key, value) => storage.set(key, value),
removeItem: (key) => storage.delete(key),
};
});
afterEach(() => delete globalThis.sessionStorage);
test('direct login ignores and consumes an older saved target', () => {
savePostLoginRedirect('/user-center/usage-record');
assert.equal(
consumePostLoginRedirect({ redirect: null }),
DEFAULT_LOGIN_REDIRECT,
);
assert.equal(consumePostLoginRedirect(), DEFAULT_LOGIN_REDIRECT);
savePostLoginRedirect('/org/settings');
assert.equal(
consumePostLoginRedirect({ redirect: null, enterprise: true }),
'/org/workbench',
);
});
test('login drops incompatible and error destinations without bypassing guards', () => {
for (const redirect of [
'/org/settings',
'/Org/settings/',
'/%6frg/settings',
'/foo/../org/settings',
'/forbidden?from=login',
]) {
assert.equal(
consumePostLoginRedirect({ redirect }),
DEFAULT_LOGIN_REDIRECT,
);
}
for (const redirect of [
'/console/setting',
'/Console/setting',
'/forbidden',
]) {
assert.equal(
consumePostLoginRedirect({ redirect, enterprise: true }),
'/org/workbench',
);
assert.equal(consumePostLoginRedirect({ redirect, orgOnly: true }), '/org');
}
});
test('allowed deep links preserve query and hash; OAuth cache is single-use', () => {
const personalLink = '/user-center/usage-record?filter=1#results';
const enterpriseLink = '/org/settings?tab=members#top';
const oauthLink = '/client/authorize?destination=desktop';
assert.equal(
consumePostLoginRedirect({ redirect: personalLink }),
personalLink,
);
assert.equal(
consumePostLoginRedirect({ redirect: enterpriseLink, enterprise: true }),
enterpriseLink,
);
assert.equal(
consumePostLoginRedirect({ redirect: enterpriseLink, orgOnly: true }),
enterpriseLink,
);
assert.equal(
consumePostLoginRedirect({ redirect: '/console/setting' }),
'/console/setting',
);
savePostLoginRedirect(oauthLink);
assert.equal(consumePostLoginRedirect(), oauthLink);
assert.equal(consumePostLoginRedirect(), DEFAULT_LOGIN_REDIRECT);
savePostLoginRedirect(oauthLink);
savePostLoginRedirect(null);
assert.equal(consumePostLoginRedirect(), DEFAULT_LOGIN_REDIRECT);
});
test('malformed, external and authentication targets fall back', () => {
for (const redirect of [
'/\t/another.example',
'/%FF',
'//another.example',
'/LOGIN',
'/org/example/login',
'/user/reset',
]) {
assert.equal(
consumePostLoginRedirect({ redirect }),
DEFAULT_LOGIN_REDIRECT,
);
}
});
+155
View File
@@ -0,0 +1,155 @@
/*
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';
import axios from 'axios';
import { installRequestLifecycle } from '../../src/helpers/requestLifecycle.js';
function fixture() {
const pending = new Map();
const errors = [];
let expirations = 0;
const client = axios.create({
adapter: (config) =>
new Promise((resolve, reject) => {
const abort = () => reject(new axios.CanceledError(undefined, config));
config.signal?.addEventListener('abort', abort, { once: true });
pending.set(config.url, (status = 200) => {
config.signal?.removeEventListener('abort', abort);
const response = { status, config, data: {} };
if (status < 400) resolve(response);
else
reject(
new axios.AxiosError(
`HTTP ${status}`,
'HTTP_ERROR',
config,
null,
response,
),
);
});
}),
});
const retire = installRequestLifecycle(client, {
onError: (error) => errors.push(error.response?.status),
onSessionExpired: () => expirations++,
});
return { client, pending, errors, retire, expirations: () => expirations };
}
test('healthy sessions dispatch independent reads concurrently', async () => {
const { client, pending } = fixture();
const paths = ['/api/org/list', '/api/org/info', '/api/org/project'];
const responses = Promise.all(paths.map((path) => client.get(path)));
await setImmediate();
assert.equal(pending.size, paths.length);
for (const path of paths) pending.get(path)();
assert.deepEqual(
(await responses).map((response) => response.status),
[200, 200, 200],
);
});
test('the first 401 cancels session reads and blocks new ones without canceling public reads or dispatched writes', async () => {
const { client, pending, errors, expirations } = fixture();
const outcomes = Promise.allSettled([
client.get('/api/org/info'),
client.get('/api/org/list'),
client.get('/api/status'),
client.post('/api/org/write', {}),
]);
await setImmediate();
pending.get('/api/org/info')(401);
pending.get('/api/org/list')(401);
await setImmediate();
await assert.rejects(client.get('/api/org/late'), axios.isCancel);
assert.equal(pending.has('/api/org/late'), false);
pending.get('/api/status')();
pending.get('/api/org/write')();
const [first, sibling, publicRead, write] = await outcomes;
assert.equal(first.reason.response.status, 401);
assert.equal(axios.isCancel(sibling.reason), true);
assert.equal(publicRead.status, 'fulfilled');
assert.equal(write.status, 'fulfilled');
assert.equal(expirations(), 1);
assert.deepEqual(errors, []);
});
test('a 500 cancels its explicit group only, preserving standalone reads', async () => {
const { client, pending, errors, expirations } = fixture();
const requestGroup = new AbortController();
const outcomes = Promise.allSettled([
client.get('/api/org/budget', { requestGroup }),
client.get('/api/org/dept', { requestGroup }),
client.get('/api/org/unrelated'),
]);
await setImmediate();
pending.get('/api/org/budget')(500);
await setImmediate();
pending.get('/api/org/unrelated')();
const [first, sibling, other] = await outcomes;
assert.equal(first.reason.response.status, 500);
assert.equal(axios.isCancel(sibling.reason), true);
assert.equal(other.status, 'fulfilled');
assert.equal(expirations(), 0);
assert.deepEqual(errors, [500]);
});
test('caller cancellations, public 401 and locally handled 401 do not invalidate the session', async () => {
const { client, pending, errors, expirations } = fixture();
const controller = new AbortController();
const outcomes = Promise.allSettled([
client.get('/api/org/canceled', { signal: controller.signal }),
client.get('/api/user/self', { skipErrorHandler: true }),
client.post('/api/org/login/direct', {}),
client.get('/api/org/list'),
]);
await setImmediate();
controller.abort();
pending.get('/api/user/self')(401);
pending.get('/api/org/login/direct')(401);
await setImmediate();
pending.get('/api/org/list')();
const [canceled, local, login, read] = await outcomes;
assert.equal(axios.isCancel(canceled.reason), true);
assert.equal(local.reason.response.status, 401);
assert.equal(login.reason.response.status, 401);
assert.equal(read.status, 'fulfilled');
assert.equal(expirations(), 0);
assert.deepEqual(errors, [401]);
});
test('retiring an instance cancels stale reads without affecting a new instance', async () => {
const old = fixture();
const current = fixture();
const outcomes = Promise.allSettled([
old.client.get('/api/org/list'),
current.client.get('/api/org/list'),
]);
await setImmediate();
old.retire();
current.pending.get('/api/org/list')();
const [stale, active] = await outcomes;
assert.equal(axios.isCancel(stale.reason), true);
assert.equal(active.status, 'fulfilled');
assert.equal(old.expirations(), 0);
});
+60
View File
@@ -0,0 +1,60 @@
/*
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 {
formatPercent,
formatRatioPercent,
formatIdReference,
formatUserReference,
toFiniteNumber,
} from '../../src/helpers/safeDisplay.js';
test('toFiniteNumber rejects missing and non-finite display values', () => {
assert.equal(toFiniteNumber(undefined), null);
assert.equal(toFiniteNumber(''), null);
assert.equal(toFiniteNumber('not-a-number'), null);
assert.equal(toFiniteNumber('12.5'), 12.5);
assert.equal(toFiniteNumber(Infinity), null);
});
test('percent formatters never expose invalid values', () => {
assert.equal(formatPercent(undefined), '-');
assert.equal(formatPercent('12.5'), '12.5%');
assert.equal(formatRatioPercent(undefined, 10), '-');
assert.equal(formatRatioPercent(2, 0), '-');
assert.equal(formatRatioPercent(2, 4), '50.0%');
});
test('user references never interpolate an undefined id', () => {
assert.equal(formatUserReference('Alice', undefined), 'Alice');
assert.equal(formatUserReference('', 42), 'User#42');
assert.equal(formatUserReference(undefined, undefined), '-');
assert.equal(
formatUserReference(undefined, 'bad', 'Unknown user'),
'Unknown user',
);
});
test('id references never expose a missing identifier', () => {
assert.equal(formatIdReference(undefined), '-');
assert.equal(formatIdReference(''), '-');
assert.equal(formatIdReference(42), '#42');
});