chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -58,7 +58,7 @@ describe('useAlign', () => {
|
||||
act(() => {
|
||||
result.current.alignLeft();
|
||||
});
|
||||
// 由于没有 canvas,不应该有任何操作发生
|
||||
// Since there is no canvas, no operation should occur
|
||||
});
|
||||
|
||||
it('应该在选中对象少于 2 个时不执行任何操作', () => {
|
||||
|
||||
@@ -88,11 +88,11 @@ describe('useBackground', () => {
|
||||
},
|
||||
);
|
||||
|
||||
// 更新 schema
|
||||
// Update schema
|
||||
const newSchema = createMockSchema('#000000');
|
||||
rerender({ currentSchema: newSchema });
|
||||
|
||||
// 等待 debounce
|
||||
// Waiting to debounce
|
||||
await vi.runAllTimers();
|
||||
|
||||
expect(result.current.backgroundColor).toBe('#000000');
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('useCanvasChange', () => {
|
||||
const createMockCanvas = () => {
|
||||
const mockCanvas = {
|
||||
on: vi.fn((event: string, callback: (event: any) => void) =>
|
||||
// 返回一个清理函数
|
||||
// Returns a cleaning function
|
||||
() => {
|
||||
mockCanvas.off(event, callback);
|
||||
},
|
||||
@@ -121,7 +121,7 @@ describe('useCanvasChange', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 验证是否监听了所有默认事件
|
||||
// Verify that all default events are being listened for
|
||||
expect(mockCanvas.on).toHaveBeenCalledWith(
|
||||
'object:modified',
|
||||
expect.any(Function),
|
||||
@@ -157,12 +157,12 @@ describe('useCanvasChange', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 获取 object:modified 事件的回调函数
|
||||
// Get the callback function for the object: modified event
|
||||
const modifiedCallback = (mockCanvas.on as any).mock.calls.find(
|
||||
(call: [string, Function]) => call[0] === 'object:modified',
|
||||
)?.[1];
|
||||
|
||||
// 模拟事件触发
|
||||
// simulated event firing
|
||||
modifiedCallback?.();
|
||||
|
||||
expect(mockCanvas.toObject).toHaveBeenCalledWith(saveProps);
|
||||
@@ -194,15 +194,15 @@ describe('useCanvasChange', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 获取 object:removed 事件的回调函数
|
||||
// Get the callback function for the object: removed event
|
||||
const removedCallback = (mockCanvas.on as any).mock.calls.find(
|
||||
(call: [string, Function]) => call[0] === 'object:removed',
|
||||
)?.[1];
|
||||
|
||||
// 模拟删除事件
|
||||
// mock delete event
|
||||
removedCallback?.();
|
||||
|
||||
// 验证只保留了存在对象的引用
|
||||
// Validation only keeps references to existing objects
|
||||
expect(mockOnChange).toHaveBeenCalledWith({
|
||||
...mockSchema,
|
||||
customVariableRefs: [
|
||||
@@ -296,7 +296,7 @@ describe('useCanvasChange', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 更新已存在的引用
|
||||
// Update existing references
|
||||
act(() => {
|
||||
result.current.updateRefByObjectId({
|
||||
objectId: 'obj1',
|
||||
@@ -309,7 +309,7 @@ describe('useCanvasChange', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// 添加新的引用
|
||||
// Add a new reference
|
||||
act(() => {
|
||||
result.current.updateRefByObjectId({
|
||||
objectId: 'obj2',
|
||||
@@ -322,14 +322,14 @@ describe('useCanvasChange', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// 删除引用
|
||||
// delete reference
|
||||
act(() => {
|
||||
result.current.updateRefByObjectId({
|
||||
objectId: 'obj1',
|
||||
});
|
||||
});
|
||||
|
||||
// 验证最终的引用关系
|
||||
// Verify the final reference relationship
|
||||
expect(mockCanvas.toObject().customVariableRefs).toEqual([
|
||||
{ objectId: 'obj2', variableId: 'var3', variableName: 'var3' },
|
||||
]);
|
||||
|
||||
@@ -110,12 +110,12 @@ describe('useCanvasClip', () => {
|
||||
useCanvasClip({ canvas: mockCanvas, schema }),
|
||||
);
|
||||
|
||||
// 先添加裁剪区域
|
||||
// Add the clipping area first
|
||||
act(() => {
|
||||
result.current.addClip();
|
||||
});
|
||||
|
||||
// 移除裁剪区域
|
||||
// Remove clipping area
|
||||
act(() => {
|
||||
result.current.removeClip();
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('useGroup', () => {
|
||||
add: vi.fn(),
|
||||
remove: vi.fn(),
|
||||
getObjects: vi.fn(),
|
||||
// 添加必要的 fabric.Object 属性
|
||||
// Add the necessary fabric. Object properties
|
||||
noScaleCache: false,
|
||||
lockMovementX: false,
|
||||
lockMovementY: false,
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('useInitCanvas', () => {
|
||||
const mockRequestRenderAll = vi.fn();
|
||||
const mockDispose = vi.fn();
|
||||
const mockOn = vi.fn(() => () => {
|
||||
// 清理函数
|
||||
// cleanup function
|
||||
});
|
||||
let mockCanvas: any;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('useMousePosition', () => {
|
||||
const createMockCanvas = () => {
|
||||
const mockCanvas = {
|
||||
on: vi.fn((event: string, callback: (event: any) => void) =>
|
||||
// 返回一个清理函数
|
||||
// Returns a cleaning function
|
||||
() => {
|
||||
mockCanvas.off(event, callback);
|
||||
},
|
||||
@@ -85,10 +85,10 @@ describe('useMousePosition', () => {
|
||||
useMousePosition({ canvas: mockCanvas }),
|
||||
);
|
||||
|
||||
// 初始位置
|
||||
// initial position
|
||||
expect(result.current.mousePosition).toEqual({ left: 0, top: 0 });
|
||||
|
||||
// 模拟鼠标移动
|
||||
// Simulate mouse movement
|
||||
act(() => {
|
||||
moveCallback({
|
||||
e: { clientX: 100, clientY: 200 },
|
||||
@@ -135,12 +135,12 @@ describe('useMousePosition', () => {
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
// 更新 canvas
|
||||
// Update canvas
|
||||
rerender({ canvas: mockCanvas2 });
|
||||
|
||||
// 应该清理旧的事件监听
|
||||
// Old event listeners should be cleaned up
|
||||
expect(cleanupSpy).toHaveBeenCalled();
|
||||
// 应该设置新的事件监听
|
||||
// New event listeners should be set up
|
||||
expect(mockCanvas2.on).toHaveBeenCalledWith(
|
||||
'mouse:move',
|
||||
expect.any(Function),
|
||||
|
||||
@@ -54,7 +54,7 @@ describe('useSnapMove', () => {
|
||||
const createMockCanvas = () => {
|
||||
const mockCanvas = {
|
||||
on: vi.fn((event: string, callback: (event: any) => void) =>
|
||||
// 返回一个清理函数
|
||||
// Returns a cleaning function
|
||||
() => {
|
||||
mockCanvas.off(event, callback);
|
||||
},
|
||||
@@ -114,12 +114,12 @@ describe('useSnapMove', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 获取 mouse:down 事件的回调函数
|
||||
// Get the callback function for the mouse: down event
|
||||
const mouseDownCallback = (mockCanvas.on as any).mock.calls.find(
|
||||
(call: [string, Function]) => call[0] === 'mouse:down',
|
||||
)?.[1];
|
||||
|
||||
// 模拟事件触发
|
||||
// simulated event firing
|
||||
mouseDownCallback?.({ target: { id: 'test-object' } });
|
||||
|
||||
expect(snap.resetAllObjectsPosition).toHaveBeenCalledWith({
|
||||
@@ -157,12 +157,12 @@ describe('useSnapMove', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 获取 mouse:up 事件的回调函数
|
||||
// Get the callback function for the mouse: up event
|
||||
const mouseUpCallback = (mockCanvas.on as any).mock.calls.find(
|
||||
(call: [string, Function]) => call[0] === 'mouse:up',
|
||||
)?.[1];
|
||||
|
||||
// 模拟事件触发
|
||||
// simulated event firing
|
||||
mouseUpCallback?.({ target: { id: 'test-object' } });
|
||||
|
||||
expect(mockSnap.reset).toHaveBeenCalled();
|
||||
@@ -198,12 +198,12 @@ describe('useSnapMove', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// 获取 object:moving 事件的回调函数
|
||||
// Get the callback function for the object: moving event
|
||||
const movingCallback = (mockCanvas.on as any).mock.calls.find(
|
||||
(call: [string, Function]) => call[0] === 'object:moving',
|
||||
)?.[1];
|
||||
|
||||
// 模拟事件触发
|
||||
// simulated event firing
|
||||
movingCallback?.({ target: { id: 'test-object' } });
|
||||
|
||||
expect(mockSnap.move).toHaveBeenCalledWith({ id: 'test-object' });
|
||||
@@ -259,7 +259,7 @@ describe('useSnapMove', () => {
|
||||
},
|
||||
);
|
||||
|
||||
// 更新 scale
|
||||
// Update scale
|
||||
rerender({ scale: 2 });
|
||||
|
||||
expect(snap.helpline.resetScale).toHaveBeenCalledWith(2);
|
||||
|
||||
Reference in New Issue
Block a user