Merge branch 'next' into develop

This commit is contained in:
nocobase[bot]
2025-05-18 10:59:59 +00:00
4 changed files with 79 additions and 2 deletions
@@ -51,7 +51,7 @@ export class RouterManager {
protected routes: Record<string, RouteType> = {};
protected options: RouterOptions;
public app: Application;
private router;
public router;
get basename() {
return this.router.basename;
}
@@ -0,0 +1,69 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { createMockDatabase, Database } from '@nocobase/database';
import { InputInterface } from '../../interfaces/input-interface';
describe('input interface', () => {
let db: Database;
beforeEach(async () => {
db = await createMockDatabase();
await db.clean({ drop: true });
});
afterEach(async () => {
await db.close();
});
describe('validate', () => {
it('should validate string values', () => {
const inputInterface = new InputInterface({});
expect(inputInterface.validate('test string')).toBe(true);
expect(inputInterface.validate('')).toBe(true);
});
it('should validate number values', () => {
const inputInterface = new InputInterface({});
expect(inputInterface.validate(123)).toBe(true);
expect(inputInterface.validate(0)).toBe(true);
expect(inputInterface.validate(-10.5)).toBe(true);
});
it('should reject non-string and non-number values', () => {
const inputInterface = new InputInterface({});
expect(inputInterface.validate(null)).toBe(false);
expect(inputInterface.validate(undefined)).toBe(false);
expect(inputInterface.validate({})).toBe(false);
expect(inputInterface.validate([])).toBe(false);
expect(inputInterface.validate(true)).toBe(false);
});
});
describe('toValue', () => {
it('should convert valid values to string', () => {
const inputInterface = new InputInterface({});
expect(inputInterface.toValue('test')).toBe('test');
expect(inputInterface.toValue(123)).toBe('123');
expect(inputInterface.toValue(-10.5)).toBe('-10.5');
});
it('should handle null and undefined values by returning null', () => {
const inputInterface = new InputInterface({});
expect(inputInterface.toValue(null)).toBeNull();
expect(inputInterface.toValue(undefined)).toBeUndefined();
});
it('should throw error for object values', () => {
const inputInterface = new InputInterface({});
expect(() => inputInterface.toValue({})).toThrow('Invalid value, expected string');
expect(() => inputInterface.toValue([])).toThrow('Invalid value, expected string');
});
});
});
@@ -12,6 +12,10 @@ import { BaseInterface } from './base-interface';
export class InputInterface extends BaseInterface {
toValue(value) {
if (value === null || value === undefined || typeof value === 'string') {
return value;
}
if (this.validate(value)) {
return value.toString();
}
@@ -23,7 +23,11 @@ function removeStringIfStartsWith(text: string, prefix: string): string {
export function useScanner({ onScannerSizeChanged, elementId, onScanSuccess }) {
const app = useApp();
const mobileManager = app.pm.get(MobileManager);
const basename = mobileManager.mobileRouter.basename.replace(/\/+$/, '');
const { mobileRouter } = mobileManager;
const appRouter = app.router;
const rawBasename = mobileRouter?.router ? mobileRouter?.basename : appRouter.basename;
const basename = rawBasename.replace(/\/+$/, '');
const [scanner, setScanner] = useState<Html5Qrcode>();