chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -32,37 +32,37 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Personal,
|
||||
};
|
||||
|
||||
// 个人空间应该有查看权限
|
||||
// Personal space should have viewing permission
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 个人空间应该有编辑信息权限
|
||||
// Personal space should have permission to edit information
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(true);
|
||||
|
||||
// 个人空间应该有删除权限
|
||||
// Personal space should have deletion permission
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(true);
|
||||
|
||||
// 个人空间应该有发布权限
|
||||
// Personal space should have publishing permission
|
||||
expect(calcPermission(EProjectPermission.PUBLISH, params)).toBe(true);
|
||||
|
||||
// 个人空间应该有创建资源权限
|
||||
// Personal space should have permission to create resources
|
||||
expect(calcPermission(EProjectPermission.CREATE_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 个人空间应该有复制资源权限
|
||||
// Personal space should have permission to copy resources
|
||||
expect(calcPermission(EProjectPermission.COPY_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 个人空间应该有复制项目权限
|
||||
// Personal space should have permission to copy items
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 个人空间应该有测试运行插件权限
|
||||
// Personal space should have test run plug-in permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_PLUGIN, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 个人空间应该有测试运行工作流权限
|
||||
// Personal space should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
@@ -75,12 +75,12 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Personal,
|
||||
};
|
||||
|
||||
// 个人空间不应该有添加协作者权限
|
||||
// Personal Spaces should not have Add Collaborators permissions
|
||||
expect(calcPermission(EProjectPermission.ADD_COLLABORATOR, params)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
// 个人空间不应该有删除协作者权限
|
||||
// Personal space should not have permission to delete collaborators
|
||||
expect(
|
||||
calcPermission(EProjectPermission.DELETE_COLLABORATOR, params),
|
||||
).toBe(false);
|
||||
@@ -95,47 +95,47 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 项目所有者应该有查看权限
|
||||
// The project owner should have viewing rights
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 项目所有者应该有编辑信息权限
|
||||
// The project owner should have permission to edit the information
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(true);
|
||||
|
||||
// 项目所有者应该有删除权限
|
||||
// The project owner should have delete permissions
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(true);
|
||||
|
||||
// 项目所有者应该有发布权限
|
||||
// The project owner should have publishing rights
|
||||
expect(calcPermission(EProjectPermission.PUBLISH, params)).toBe(true);
|
||||
|
||||
// 项目所有者应该有创建资源权限
|
||||
// The project owner should have the Create Resource permission
|
||||
expect(calcPermission(EProjectPermission.CREATE_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目所有者应该有复制资源权限
|
||||
// The project owner should have permission to copy the resource
|
||||
expect(calcPermission(EProjectPermission.COPY_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目所有者应该有复制项目权限
|
||||
// The project owner should have permission to copy the project
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 项目所有者应该有测试运行插件权限
|
||||
// The project owner should have test run plug-in permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_PLUGIN, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目所有者应该有测试运行工作流权限
|
||||
// The project owner should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目所有者应该有添加协作者权限
|
||||
// The project owner should have permission to add collaborators
|
||||
expect(calcPermission(EProjectPermission.ADD_COLLABORATOR, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目所有者应该有删除协作者权限
|
||||
// The project owner should have the Delete Collaborator permission
|
||||
expect(
|
||||
calcPermission(EProjectPermission.DELETE_COLLABORATOR, params),
|
||||
).toBe(true);
|
||||
@@ -148,47 +148,47 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 项目编辑者应该有查看权限
|
||||
// Project editors should have viewing rights
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 项目编辑者应该有编辑信息权限
|
||||
// Project editors should have permission to edit information
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(true);
|
||||
|
||||
// 项目编辑者应该有创建资源权限
|
||||
// Project editors should have the Create Resource permission
|
||||
expect(calcPermission(EProjectPermission.CREATE_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目编辑者应该有复制资源权限
|
||||
// Project editors should have permission to copy resources
|
||||
expect(calcPermission(EProjectPermission.COPY_RESOURCE, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目编辑者应该有复制项目权限
|
||||
// The project editor should have permission to copy the project
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 项目编辑者应该有测试运行插件权限
|
||||
// Project editors should have test run plug-in permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_PLUGIN, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目编辑者应该有测试运行工作流权限
|
||||
// The project editor should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目编辑者应该有添加协作者权限
|
||||
// Project editors should have Add Collaborators permission
|
||||
expect(calcPermission(EProjectPermission.ADD_COLLABORATOR, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 项目编辑者不应该有删除权限
|
||||
// Project editors should not have delete permissions
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(false);
|
||||
|
||||
// 项目编辑者不应该有发布权限
|
||||
// Project editors should not have permission to publish
|
||||
expect(calcPermission(EProjectPermission.PUBLISH, params)).toBe(false);
|
||||
|
||||
// 项目编辑者不应该有删除协作者权限
|
||||
// Project editors should not have permission to delete collaborators
|
||||
expect(
|
||||
calcPermission(EProjectPermission.DELETE_COLLABORATOR, params),
|
||||
).toBe(false);
|
||||
@@ -203,47 +203,47 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 空间成员应该有查看权限
|
||||
// Space members should have viewing rights
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 空间成员应该有复制项目权限
|
||||
// Space members should have permission to copy items
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 空间成员应该有测试运行工作流权限
|
||||
// Space members should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// 空间成员不应该有编辑信息权限
|
||||
// Space members should not have permission to edit information
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(false);
|
||||
|
||||
// 空间成员不应该有删除权限
|
||||
// Space members should not have delete permissions
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(false);
|
||||
|
||||
// 空间成员不应该有发布权限
|
||||
// Space members should not have publishing privileges
|
||||
expect(calcPermission(EProjectPermission.PUBLISH, params)).toBe(false);
|
||||
|
||||
// 空间成员不应该有创建资源权限
|
||||
// Space members should not have permission to create resources
|
||||
expect(calcPermission(EProjectPermission.CREATE_RESOURCE, params)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
// 空间成员不应该有复制资源权限
|
||||
// Space members should not have permission to copy resources
|
||||
expect(calcPermission(EProjectPermission.COPY_RESOURCE, params)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
// 空间成员不应该有测试运行插件权限
|
||||
// Space members should not have test run plug-in permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_PLUGIN, params)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
// 空间成员不应该有添加协作者权限
|
||||
// Space members should not have Add Collaborator permissions
|
||||
expect(calcPermission(EProjectPermission.ADD_COLLABORATOR, params)).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
// 空间成员不应该有删除协作者权限
|
||||
// Space members should not have permission to delete collaborators
|
||||
expect(
|
||||
calcPermission(EProjectPermission.DELETE_COLLABORATOR, params),
|
||||
).toBe(false);
|
||||
@@ -256,13 +256,13 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 空间所有者应该有查看权限
|
||||
// Space owners should have viewing rights
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 空间所有者应该有复制项目权限
|
||||
// The space owner should have permission to copy items
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 空间所有者应该有测试运行工作流权限
|
||||
// Space owners should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
@@ -275,13 +275,13 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 空间管理员应该有查看权限
|
||||
// The space administrator should have viewing rights
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
|
||||
// 空间管理员应该有复制项目权限
|
||||
// The space administrator should have permission to copy items
|
||||
expect(calcPermission(EProjectPermission.COPY, params)).toBe(true);
|
||||
|
||||
// 空间管理员应该有测试运行工作流权限
|
||||
// The space administrator should have test run workflow permissions
|
||||
expect(calcPermission(EProjectPermission.TEST_RUN_WORKFLOW, params)).toBe(
|
||||
true,
|
||||
);
|
||||
@@ -294,7 +294,7 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 默认角色不应该有任何权限
|
||||
// The default role should not have any permissions
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(false);
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(false);
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(false);
|
||||
@@ -329,7 +329,7 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 应该有项目编辑者的所有权限
|
||||
// Should have all the permissions of the project editor
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(true);
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(true);
|
||||
expect(calcPermission(EProjectPermission.CREATE_RESOURCE, params)).toBe(
|
||||
@@ -349,7 +349,7 @@ describe('Project Calc Permission', () => {
|
||||
true,
|
||||
);
|
||||
|
||||
// 不应该有项目编辑者没有的权限
|
||||
// There should be no permissions that the project editor does not have
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(false);
|
||||
expect(calcPermission(EProjectPermission.PUBLISH, params)).toBe(false);
|
||||
expect(
|
||||
@@ -364,7 +364,7 @@ describe('Project Calc Permission', () => {
|
||||
spaceType: SpaceType.Team,
|
||||
};
|
||||
|
||||
// 没有角色不应该有任何权限
|
||||
// No role should have no permissions
|
||||
expect(calcPermission(EProjectPermission.View, params)).toBe(false);
|
||||
expect(calcPermission(EProjectPermission.EDIT_INFO, params)).toBe(false);
|
||||
expect(calcPermission(EProjectPermission.DELETE, params)).toBe(false);
|
||||
|
||||
@@ -24,28 +24,28 @@ import {
|
||||
describe('Project Constants', () => {
|
||||
describe('ProjectRoleType', () => {
|
||||
it('应该定义所有必要的角色类型', () => {
|
||||
// 验证所有角色类型都已定义
|
||||
// Verify that all role types are defined
|
||||
expect(ProjectRoleType.Owner).toBeDefined();
|
||||
expect(ProjectRoleType.Editor).toBeDefined();
|
||||
|
||||
// 验证角色类型的值
|
||||
// Validate the value of the role type
|
||||
expect(ProjectRoleType.Owner).toBe('owner');
|
||||
expect(ProjectRoleType.Editor).toBe('editor');
|
||||
});
|
||||
|
||||
it('应该包含正确数量的角色类型', () => {
|
||||
// 验证角色类型的数量
|
||||
// Number of validation role types
|
||||
const roleTypeCount = Object.keys(ProjectRoleType).filter(key =>
|
||||
isNaN(Number(key)),
|
||||
).length;
|
||||
|
||||
expect(roleTypeCount).toBe(2); // Owner 和 Editor
|
||||
expect(roleTypeCount).toBe(2); // Owner and Editor
|
||||
});
|
||||
});
|
||||
|
||||
describe('EProjectPermission', () => {
|
||||
it('应该定义所有必要的权限点', () => {
|
||||
// 验证所有权限点都已定义
|
||||
// Verify that all permission spots are defined
|
||||
expect(EProjectPermission.View).toBeDefined();
|
||||
expect(EProjectPermission.EDIT_INFO).toBeDefined();
|
||||
expect(EProjectPermission.DELETE).toBeDefined();
|
||||
@@ -60,17 +60,17 @@ describe('Project Constants', () => {
|
||||
});
|
||||
|
||||
it('应该为每个权限点分配唯一的值', () => {
|
||||
// 创建一个集合来存储所有权限点的值
|
||||
// Create a collection to store the values of all permission spots
|
||||
const permissionValues = new Set();
|
||||
|
||||
// 获取所有权限点的值
|
||||
// Get values for all permission spots
|
||||
Object.values(EProjectPermission)
|
||||
.filter(value => typeof value === 'number')
|
||||
.forEach(value => {
|
||||
permissionValues.add(value);
|
||||
});
|
||||
|
||||
// 验证权限点的数量与唯一值的数量相同
|
||||
// The number of validation permission spots is the same as the number of unique values
|
||||
const numericKeys = Object.keys(EProjectPermission).filter(
|
||||
key => !isNaN(Number(key)),
|
||||
).length;
|
||||
@@ -79,12 +79,12 @@ describe('Project Constants', () => {
|
||||
});
|
||||
|
||||
it('应该包含正确数量的权限点', () => {
|
||||
// 验证权限点的数量
|
||||
// Number of permission spots verified
|
||||
const permissionCount = Object.keys(EProjectPermission).filter(key =>
|
||||
isNaN(Number(key)),
|
||||
).length;
|
||||
|
||||
expect(permissionCount).toBe(12); // 11个权限点
|
||||
expect(permissionCount).toBe(12); // 11 permission spots
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -143,20 +143,20 @@ describe('Project Auth Store', () => {
|
||||
const projectId = 'test-project-1';
|
||||
const roles = [ProjectRoleType.Owner];
|
||||
|
||||
// 设置初始数据
|
||||
// Set initial data
|
||||
await act(() => {
|
||||
result.current.setRoles(projectId, roles);
|
||||
result.current.setIsReady(projectId, true);
|
||||
});
|
||||
|
||||
// 验证数据已设置
|
||||
// Verify that the data is set
|
||||
expect(result.current.roles[projectId]).toEqual(roles);
|
||||
expect(result.current.isReady[projectId]).toBe(true);
|
||||
|
||||
// 销毁数据
|
||||
// Destroy data
|
||||
result.current.destory(projectId);
|
||||
|
||||
// 验证数据已清除
|
||||
// Verify that the data has been cleared
|
||||
expect(result.current.roles[projectId]).toEqual([]);
|
||||
expect(result.current.isReady[projectId]).toBe(false);
|
||||
});
|
||||
@@ -171,16 +171,16 @@ describe('Project Auth Store', () => {
|
||||
const roles1 = [ProjectRoleType.Owner];
|
||||
const roles2 = [ProjectRoleType.Editor];
|
||||
|
||||
// 设置初始数据
|
||||
// Set initial data
|
||||
result.current.setRoles(projectId1, roles1);
|
||||
result.current.setRoles(projectId2, roles2);
|
||||
result.current.setIsReady(projectId1, true);
|
||||
result.current.setIsReady(projectId2, true);
|
||||
|
||||
// 销毁项目1的数据
|
||||
// Destruction of data for item 1
|
||||
result.current.destory(projectId1);
|
||||
|
||||
// 验证项目1的数据已清除,项目2的数据保持不变
|
||||
// Verify that the data for item 1 has been cleared and that the data for item 2 remains unchanged
|
||||
expect(result.current.roles[projectId1]).toEqual([]);
|
||||
expect(result.current.isReady[projectId1]).toBe(false);
|
||||
expect(result.current.roles[projectId2]).toEqual(roles2);
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
|
||||
// 模拟 React 的 useEffect
|
||||
// The useEffect of React
|
||||
const cleanupFns = new Map();
|
||||
vi.mock('react', () => ({
|
||||
useEffect: vi.fn((fn, deps) => {
|
||||
// 执行 effect 函数并获取清理函数
|
||||
// Execute the effect function and get the cleanup function
|
||||
const cleanup = fn();
|
||||
// 存储清理函数,以便在 unmount 时调用
|
||||
// Store the cleanup function to call when unmounted
|
||||
cleanupFns.set(fn, cleanup);
|
||||
// 返回清理函数
|
||||
// Return cleanup function
|
||||
return cleanup;
|
||||
}),
|
||||
}));
|
||||
@@ -33,7 +33,7 @@ vi.mock('react', () => ({
|
||||
import { useDestoryProject } from '../../src/project/use-destory-project';
|
||||
import { useProjectAuthStore } from '../../src/project/store';
|
||||
|
||||
// 模拟 useProjectAuthStore
|
||||
// emulation useProjectAuthStore
|
||||
vi.mock('../../src/project/store', () => {
|
||||
const destorySpy = vi.fn();
|
||||
return {
|
||||
@@ -41,19 +41,19 @@ vi.mock('../../src/project/store', () => {
|
||||
};
|
||||
});
|
||||
|
||||
// 创建一个包装函数,确保在 unmount 时调用清理函数
|
||||
// Create a wrapper function to ensure that the cleanup function is called when unmounted
|
||||
function renderHookWithCleanup(callback, options = {}) {
|
||||
const result = renderHook(callback, options);
|
||||
const originalUnmount = result.unmount;
|
||||
|
||||
result.unmount = () => {
|
||||
// 调用所有清理函数
|
||||
// Call all cleanup functions
|
||||
cleanupFns.forEach(cleanup => {
|
||||
if (typeof cleanup === 'function') {
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
// 调用原始的 unmount
|
||||
// Call the original unmount
|
||||
originalUnmount();
|
||||
};
|
||||
|
||||
@@ -70,21 +70,21 @@ describe('useDestoryProject', () => {
|
||||
const projectId = 'test-project-id';
|
||||
const destorySpy = vi.fn();
|
||||
|
||||
// 模拟 useProjectAuthStore 返回 destorySpy
|
||||
// Emulate useProjectAuthStore returns destorySpy
|
||||
(useProjectAuthStore as any).mockReturnValue(destorySpy);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { unmount } = renderHookWithCleanup(() =>
|
||||
useDestoryProject(projectId),
|
||||
);
|
||||
|
||||
// 验证初始状态下 destory 未被调用
|
||||
// Verify that destory is not called in the initial state
|
||||
expect(destorySpy).not.toHaveBeenCalled();
|
||||
|
||||
// 卸载组件
|
||||
// uninstall components
|
||||
unmount();
|
||||
|
||||
// 验证 destory 被调用,且参数正确
|
||||
// Verify that destory is called and the parameters are correct
|
||||
expect(destorySpy).toHaveBeenCalledTimes(1);
|
||||
expect(destorySpy).toHaveBeenCalledWith(projectId);
|
||||
});
|
||||
@@ -93,18 +93,18 @@ describe('useDestoryProject', () => {
|
||||
const projectId1 = 'test-project-id-1';
|
||||
const destorySpy = vi.fn();
|
||||
|
||||
// 模拟 useProjectAuthStore 返回 destorySpy
|
||||
// Emulate useProjectAuthStore returns destorySpy
|
||||
(useProjectAuthStore as any).mockReturnValue(destorySpy);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { unmount } = renderHookWithCleanup(() =>
|
||||
useDestoryProject(projectId1),
|
||||
);
|
||||
|
||||
// 卸载组件
|
||||
// uninstall components
|
||||
unmount();
|
||||
|
||||
// 验证 destory 被调用,且参数为 projectId1
|
||||
// Verify that destory is called with the parameter projectId1.
|
||||
expect(destorySpy).toHaveBeenCalledTimes(1);
|
||||
expect(destorySpy).toHaveBeenCalledWith(projectId1);
|
||||
});
|
||||
@@ -113,22 +113,22 @@ describe('useDestoryProject', () => {
|
||||
const projectId2 = 'test-project-id-2';
|
||||
const destorySpy = vi.fn();
|
||||
|
||||
// 清除之前的所有模拟和清理函数
|
||||
// Clear all previous simulation and cleanup functions
|
||||
vi.clearAllMocks();
|
||||
cleanupFns.clear();
|
||||
|
||||
// 模拟 useProjectAuthStore 返回 destorySpy
|
||||
// Emulate useProjectAuthStore returns destorySpy
|
||||
(useProjectAuthStore as any).mockReturnValue(destorySpy);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { unmount } = renderHookWithCleanup(() =>
|
||||
useDestoryProject(projectId2),
|
||||
);
|
||||
|
||||
// 卸载组件
|
||||
// uninstall components
|
||||
unmount();
|
||||
|
||||
// 验证 destory 被调用,且参数为 projectId2
|
||||
// Verify that destory is called with the parameter projectId2.
|
||||
expect(destorySpy).toHaveBeenCalledTimes(1);
|
||||
expect(destorySpy).toHaveBeenCalledWith(projectId2);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
} from '../../src/project/constants';
|
||||
import { calcPermission } from '../../src/project/calc-permission';
|
||||
|
||||
// 模拟依赖
|
||||
// simulated dependency
|
||||
vi.mock('@coze-arch/foundation-sdk', () => ({
|
||||
useSpace: vi.fn(),
|
||||
}));
|
||||
@@ -54,94 +54,94 @@ describe('useProjectAuth', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// 模拟 useSpace 返回空间信息
|
||||
// Simulating useSpace returns spatial information
|
||||
(useSpace as any).mockReturnValue({
|
||||
space_type: SpaceType.Team,
|
||||
});
|
||||
|
||||
// 模拟 useSpaceRole 返回空间角色
|
||||
// Simulate useSpaceRole Return Space Role
|
||||
(useSpaceRole as any).mockReturnValue([SpaceRoleType.Member]);
|
||||
|
||||
// 模拟 useProjectRole 返回项目角色
|
||||
// Simulate useProjectRole Return project role
|
||||
(useProjectRole as any).mockReturnValue([ProjectRoleType.Editor]);
|
||||
|
||||
// 模拟 calcPermission 返回权限结果
|
||||
// Simulate calcPermission return permission result
|
||||
(calcPermission as any).mockReturnValue(true);
|
||||
});
|
||||
|
||||
it('应该调用 calcPermission 并返回正确的权限结果', () => {
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() =>
|
||||
useProjectAuth(permissionKey, projectId, spaceId),
|
||||
);
|
||||
|
||||
// 验证 useSpace 被调用
|
||||
// Verify that useSpace is called
|
||||
expect(useSpace).toHaveBeenCalledWith(spaceId);
|
||||
|
||||
// 验证 useSpaceRole 被调用
|
||||
// Verify useSpaceRole is called
|
||||
expect(useSpaceRole).toHaveBeenCalledWith(spaceId);
|
||||
|
||||
// 验证 useProjectRole 被调用
|
||||
// Verify useProjectRole is called
|
||||
expect(useProjectRole).toHaveBeenCalledWith(projectId);
|
||||
|
||||
// 验证 calcPermission 被调用,且参数正确
|
||||
// Verify that calcPermission is called and the parameters are correct
|
||||
expect(calcPermission).toHaveBeenCalledWith(permissionKey, {
|
||||
projectRoles: [ProjectRoleType.Editor],
|
||||
spaceRoles: [SpaceRoleType.Member],
|
||||
spaceType: SpaceType.Team,
|
||||
});
|
||||
|
||||
// 验证返回值
|
||||
// Validate the return value
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('应该在 calcPermission 返回 false 时返回 false', () => {
|
||||
// 模拟 calcPermission 返回 false
|
||||
// simulated calcPermission returns false
|
||||
(calcPermission as any).mockReturnValue(false);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() =>
|
||||
useProjectAuth(permissionKey, projectId, spaceId),
|
||||
);
|
||||
|
||||
// 验证返回值
|
||||
// Validate the return value
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('应该在空间类型不存在时抛出错误', () => {
|
||||
// 模拟 useSpace 返回没有 space_type 的对象
|
||||
// Mock useSpace returns objects without space_type
|
||||
(useSpace as any).mockReturnValue({});
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证抛出错误
|
||||
// validation throws error
|
||||
expect(() => {
|
||||
const { result } = renderHook(() =>
|
||||
useProjectAuth(permissionKey, projectId, spaceId),
|
||||
);
|
||||
// 强制访问 result.current 触发错误
|
||||
// Force access result.current trigger error
|
||||
console.log(result.current);
|
||||
}).toThrow('useSpaceAuth must be used after space list has been pulled.');
|
||||
});
|
||||
|
||||
it('应该在空间为 null 时抛出错误', () => {
|
||||
// 模拟 useSpace 返回 null
|
||||
// Simulate useSpace returns null
|
||||
(useSpace as any).mockReturnValue(null);
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证抛出错误
|
||||
// validation throws error
|
||||
expect(() => {
|
||||
const { result } = renderHook(() =>
|
||||
useProjectAuth(permissionKey, projectId, spaceId),
|
||||
);
|
||||
// 强制访问 result.current 触发错误
|
||||
// Force access result.current trigger error
|
||||
console.log(result.current);
|
||||
}).toThrow('useSpaceAuth must be used after space list has been pulled.');
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ import { useProjectRole } from '../../src/project/use-project-role';
|
||||
import { useProjectAuthStore } from '../../src/project/store';
|
||||
import { ProjectRoleType } from '../../src/project/constants';
|
||||
|
||||
// 模拟依赖
|
||||
// simulated dependency
|
||||
vi.mock('../../src/project/store', () => ({
|
||||
useProjectAuthStore: vi.fn(),
|
||||
}));
|
||||
@@ -36,38 +36,38 @@ describe('useProjectRole', () => {
|
||||
it('应该返回正确的项目角色', () => {
|
||||
const expectedRoles = [ProjectRoleType.Owner];
|
||||
|
||||
// 模拟 useProjectAuthStore 返回项目角色和 ready 状态
|
||||
// Mock useProjectAuthStore returns project role and ready state
|
||||
(useProjectAuthStore as any).mockReturnValue({
|
||||
isReady: true,
|
||||
role: expectedRoles,
|
||||
});
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useProjectRole(projectId));
|
||||
|
||||
// 验证 useProjectAuthStore 被调用
|
||||
// Verify useProjectAuthStore is called
|
||||
expect(useProjectAuthStore).toHaveBeenCalled();
|
||||
|
||||
// 验证返回值
|
||||
// Validate the return value
|
||||
expect(result.current).toEqual(expectedRoles);
|
||||
});
|
||||
|
||||
it('应该在项目未准备好时抛出错误', () => {
|
||||
// 模拟 useProjectAuthStore 返回未准备好的状态
|
||||
// Simulate useProjectAuthStore returns an unprepared state
|
||||
(useProjectAuthStore as any).mockReturnValue({
|
||||
isReady: false,
|
||||
role: [],
|
||||
});
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证抛出错误
|
||||
// validation throws error
|
||||
expect(() => {
|
||||
const { result } = renderHook(() => useProjectRole(projectId));
|
||||
// 强制访问 result.current 触发错误
|
||||
// Force access result.current trigger error
|
||||
console.log(result.current);
|
||||
}).toThrow(
|
||||
'useProjectAuth must be used after useInitProjectRole has been completed.',
|
||||
@@ -75,32 +75,32 @@ describe('useProjectRole', () => {
|
||||
});
|
||||
|
||||
it('应该在角色为 undefined 时返回空数组', () => {
|
||||
// 模拟 useProjectAuthStore 返回 undefined 角色
|
||||
// Emulate useProjectAuthStore returns undefined role
|
||||
(useProjectAuthStore as any).mockReturnValue({
|
||||
isReady: true,
|
||||
role: undefined,
|
||||
});
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useProjectRole(projectId));
|
||||
|
||||
// 验证返回值为空数组
|
||||
// Verify that the return value is an empty array
|
||||
expect(result.current).toEqual([]);
|
||||
});
|
||||
|
||||
it('应该处理多种角色类型', () => {
|
||||
const expectedRoles = [ProjectRoleType.Owner, ProjectRoleType.Editor];
|
||||
|
||||
// 模拟 useProjectAuthStore 返回多种角色
|
||||
// Emulate useProjectAuthStore returns multiple roles
|
||||
(useProjectAuthStore as any).mockReturnValue({
|
||||
isReady: true,
|
||||
role: expectedRoles,
|
||||
});
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useProjectRole(projectId));
|
||||
|
||||
// 验证返回值
|
||||
// Validate the return value
|
||||
expect(result.current).toEqual(expectedRoles);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,146 +23,146 @@ import { calcPermission } from '../../src/space/calc-permission';
|
||||
describe('Space Calc Permission', () => {
|
||||
describe('calcPermission', () => {
|
||||
it('应该为 Owner 角色返回正确的权限', () => {
|
||||
// Owner 应该有更新空间的权限
|
||||
// Owner should have permission to update the space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [SpaceRoleType.Owner]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有删除空间的权限
|
||||
// Owner should have permission to delete space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.DeleteSpace, [SpaceRoleType.Owner]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有添加成员的权限
|
||||
// Owner should have permission to add members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.AddBotSpaceMember, [
|
||||
SpaceRoleType.Owner,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有移除成员的权限
|
||||
// Owner should have permission to remove members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.RemoveSpaceMember, [
|
||||
SpaceRoleType.Owner,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有转移所有权的权限
|
||||
// Owner should have the right to transfer ownership
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.TransferSpace, [SpaceRoleType.Owner]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有更新成员的权限
|
||||
// Owner should have permission to update members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpaceMember, [
|
||||
SpaceRoleType.Owner,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Owner 应该有管理 API 的权限
|
||||
// Owner should have permission to manage the API
|
||||
expect(calcPermission(ESpacePermisson.API, [SpaceRoleType.Owner])).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('应该为 Admin 角色返回正确的权限', () => {
|
||||
// Admin 应该有添加成员的权限
|
||||
// Admin should have permission to add members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.AddBotSpaceMember, [
|
||||
SpaceRoleType.Admin,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Admin 应该有移除成员的权限
|
||||
// Admin should have permission to remove members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.RemoveSpaceMember, [
|
||||
SpaceRoleType.Admin,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Admin 应该有退出空间的权限
|
||||
// Admin should have permission to exit the space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.ExitSpace, [SpaceRoleType.Admin]),
|
||||
).toBe(true);
|
||||
|
||||
// Admin 应该有更新成员的权限
|
||||
// Admin should have permission to update members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpaceMember, [
|
||||
SpaceRoleType.Admin,
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// Admin 不应该有更新空间的权限
|
||||
// Admin should not have permission to update the space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [SpaceRoleType.Admin]),
|
||||
).toBe(false);
|
||||
|
||||
// Admin 不应该有删除空间的权限
|
||||
// Admin should not have permission to delete space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.DeleteSpace, [SpaceRoleType.Admin]),
|
||||
).toBe(false);
|
||||
|
||||
// Admin 不应该有转移所有权的权限
|
||||
// Admin should not have permission to transfer ownership
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.TransferSpace, [SpaceRoleType.Admin]),
|
||||
).toBe(false);
|
||||
|
||||
// Admin 不应该有管理 API 的权限
|
||||
// Admin should not have permission to manage APIs
|
||||
expect(calcPermission(ESpacePermisson.API, [SpaceRoleType.Admin])).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('应该为 Member 角色返回正确的权限', () => {
|
||||
// Member 应该有退出空间的权限
|
||||
// Members should have permission to exit the space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.ExitSpace, [SpaceRoleType.Member]),
|
||||
).toBe(true);
|
||||
|
||||
// Member 不应该有更新空间的权限
|
||||
// Members should not have permission to update space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [SpaceRoleType.Member]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有删除空间的权限
|
||||
// Members should not have permission to delete space
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.DeleteSpace, [SpaceRoleType.Member]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有添加成员的权限
|
||||
// Members should not have permission to add members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.AddBotSpaceMember, [
|
||||
SpaceRoleType.Member,
|
||||
]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有移除成员的权限
|
||||
// Members should not have permission to remove members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.RemoveSpaceMember, [
|
||||
SpaceRoleType.Member,
|
||||
]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有转移所有权的权限
|
||||
// Members should not have permission to transfer ownership
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.TransferSpace, [SpaceRoleType.Member]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有更新成员的权限
|
||||
// Members should not have permission to update members
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpaceMember, [
|
||||
SpaceRoleType.Member,
|
||||
]),
|
||||
).toBe(false);
|
||||
|
||||
// Member 不应该有管理 API 的权限
|
||||
// Members should not have permission to manage APIs
|
||||
expect(calcPermission(ESpacePermisson.API, [SpaceRoleType.Member])).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('应该为 Default 角色返回正确的权限', () => {
|
||||
// Default 不应该有任何权限
|
||||
// Default should not have any permissions
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [SpaceRoleType.Default]),
|
||||
).toBe(false);
|
||||
@@ -196,7 +196,7 @@ describe('Space Calc Permission', () => {
|
||||
});
|
||||
|
||||
it('应该处理多个角色的情况', () => {
|
||||
// 当用户同时拥有 Member 和 Admin 角色时,应该有两个角色的所有权限
|
||||
// When a user has both the Member and Admin roles, they should have all the permissions of both roles
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.ExitSpace, [
|
||||
SpaceRoleType.Member,
|
||||
@@ -211,7 +211,7 @@ describe('Space Calc Permission', () => {
|
||||
]),
|
||||
).toBe(true);
|
||||
|
||||
// 即使其中一个角色没有权限,只要有一个角色有权限,就应该返回 true
|
||||
// Even if one of the roles has no permissions, it should return true as long as one of the roles has permissions.
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [
|
||||
SpaceRoleType.Member,
|
||||
@@ -221,13 +221,13 @@ describe('Space Calc Permission', () => {
|
||||
});
|
||||
|
||||
it('应该处理空角色数组', () => {
|
||||
// 当没有角色时,应该返回 false
|
||||
// When there is no role, it should return false.
|
||||
expect(calcPermission(ESpacePermisson.UpdateSpace, [])).toBe(false);
|
||||
expect(calcPermission(ESpacePermisson.ExitSpace, [])).toBe(false);
|
||||
});
|
||||
|
||||
it('应该处理未知角色', () => {
|
||||
// 当角色未知时,应该返回 false
|
||||
// When the character is unknown, it should return false.
|
||||
expect(
|
||||
calcPermission(ESpacePermisson.UpdateSpace, [
|
||||
'UnknownRole' as unknown as SpaceRoleType,
|
||||
|
||||
@@ -22,7 +22,7 @@ import { ESpacePermisson } from '../../src/space/constants';
|
||||
describe('Space Constants', () => {
|
||||
describe('ESpacePermisson', () => {
|
||||
it('应该定义所有必要的权限点', () => {
|
||||
// 验证所有权限点都已定义
|
||||
// Verify that all permission spots are defined
|
||||
expect(ESpacePermisson.UpdateSpace).toBeDefined();
|
||||
expect(ESpacePermisson.DeleteSpace).toBeDefined();
|
||||
expect(ESpacePermisson.AddBotSpaceMember).toBeDefined();
|
||||
@@ -34,17 +34,17 @@ describe('Space Constants', () => {
|
||||
});
|
||||
|
||||
it('应该为每个权限点分配唯一的值', () => {
|
||||
// 创建一个集合来存储所有权限点的值
|
||||
// Create a collection to store the values of all permission spots
|
||||
const permissionValues = new Set();
|
||||
|
||||
// 获取所有权限点的值
|
||||
// Get values for all permission spots
|
||||
Object.values(ESpacePermisson)
|
||||
.filter(value => typeof value === 'number')
|
||||
.forEach(value => {
|
||||
permissionValues.add(value);
|
||||
});
|
||||
|
||||
// 验证权限点的数量与唯一值的数量相同
|
||||
// The number of validation permission spots is the same as the number of unique values
|
||||
const numericKeys = Object.keys(ESpacePermisson).filter(
|
||||
key => !isNaN(Number(key)),
|
||||
).length;
|
||||
@@ -55,10 +55,10 @@ describe('Space Constants', () => {
|
||||
|
||||
describe('SpaceRoleType', () => {
|
||||
it('应该正确导出 SpaceRoleType', () => {
|
||||
// 验证 SpaceRoleType 已正确导出
|
||||
// Verify that SpaceRoleType has been exported correctly
|
||||
expect(SpaceRoleType).toBeDefined();
|
||||
|
||||
// 验证 SpaceRoleType 包含必要的角色
|
||||
// Verify that SpaceRoleType contains the necessary roles
|
||||
expect(SpaceRoleType.Owner).toBeDefined();
|
||||
expect(SpaceRoleType.Admin).toBeDefined();
|
||||
expect(SpaceRoleType.Member).toBeDefined();
|
||||
|
||||
@@ -18,18 +18,18 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { renderHook, act } from '@testing-library/react-hooks';
|
||||
import { SpaceRoleType } from '@coze-arch/idl/developer_api';
|
||||
|
||||
// 模拟全局变量
|
||||
// simulated global variable
|
||||
vi.stubGlobal('IS_DEV_MODE', true);
|
||||
|
||||
describe('Space Auth Store', () => {
|
||||
beforeEach(() => {
|
||||
// 重置模块缓存,确保每个测试都使用新的 store 实例
|
||||
// Reset the module cache to ensure that each test uses a new store instance
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
describe('setRoles', () => {
|
||||
it('应该正确设置空间角色', async () => {
|
||||
// 动态导入 store 模块,确保每次测试都获取新的实例
|
||||
// Dynamically import the store module to ensure that each test gets a new instance
|
||||
const { useSpaceAuthStore } = await vi.importActual(
|
||||
'../../src/space/store',
|
||||
);
|
||||
@@ -137,22 +137,22 @@ describe('Space Auth Store', () => {
|
||||
const { result } = renderHook(() => useSpaceAuthStore());
|
||||
const roles = [SpaceRoleType.Owner];
|
||||
|
||||
// 设置初始数据
|
||||
// Set initial data
|
||||
await act(() => {
|
||||
result.current.setRoles('space1', roles);
|
||||
result.current.setIsReady('space1', true);
|
||||
});
|
||||
|
||||
// 验证数据已设置
|
||||
// Verify that the data is set
|
||||
expect(result.current.roles.space1).toEqual(roles);
|
||||
expect(result.current.isReady.space1).toBe(true);
|
||||
|
||||
// 销毁数据
|
||||
// Destroy data
|
||||
await act(() => {
|
||||
result.current.destory('space1');
|
||||
});
|
||||
|
||||
// 验证数据已清除
|
||||
// Verify that the data has been cleared
|
||||
expect(result.current.roles.space1).toEqual([]);
|
||||
expect(result.current.isReady.space1).toBeUndefined();
|
||||
});
|
||||
@@ -163,7 +163,7 @@ describe('Space Auth Store', () => {
|
||||
);
|
||||
const { result } = renderHook(() => useSpaceAuthStore());
|
||||
|
||||
// 设置两个空间的数据
|
||||
// Set data for two spaces
|
||||
await act(() => {
|
||||
result.current.setRoles('space1', [SpaceRoleType.Owner]);
|
||||
result.current.setIsReady('space1', true);
|
||||
@@ -171,16 +171,16 @@ describe('Space Auth Store', () => {
|
||||
result.current.setIsReady('space2', true);
|
||||
});
|
||||
|
||||
// 只销毁 space1 的数据
|
||||
// Only destroy space1 data
|
||||
await act(() => {
|
||||
result.current.destory('space1');
|
||||
});
|
||||
|
||||
// 验证 space1 的数据已清除
|
||||
// Verify that Space1's data has been cleared
|
||||
expect(result.current.roles.space1).toEqual([]);
|
||||
expect(result.current.isReady.space1).toBeUndefined();
|
||||
|
||||
// 验证 space2 的数据保持不变
|
||||
// Verify that Space2's data remains unchanged
|
||||
expect(result.current.roles.space2).toEqual([SpaceRoleType.Member]);
|
||||
expect(result.current.isReady.space2).toBe(true);
|
||||
});
|
||||
@@ -193,14 +193,14 @@ describe('Space Auth Store', () => {
|
||||
);
|
||||
const { result } = renderHook(() => useSpaceAuthStore());
|
||||
|
||||
// 重置 store 确保测试环境干净
|
||||
// Reset store to ensure testing environment is clean
|
||||
await act(() => {
|
||||
Object.keys(result.current.roles).forEach(spaceId => {
|
||||
result.current.destory(spaceId);
|
||||
});
|
||||
});
|
||||
|
||||
// 验证初始状态
|
||||
// Verify the initial state
|
||||
expect(result.current.roles).toEqual({});
|
||||
expect(result.current.isReady).toEqual({});
|
||||
});
|
||||
|
||||
@@ -17,38 +17,38 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
|
||||
// 模拟 React 的 useEffect
|
||||
// The useEffect of React
|
||||
const cleanupFns = new Map();
|
||||
vi.mock('react', () => ({
|
||||
useEffect: vi.fn((fn, deps) => {
|
||||
// 执行 effect 函数并获取清理函数
|
||||
// Execute the effect function and get the cleanup function
|
||||
const cleanup = fn();
|
||||
// 存储清理函数,以便在 unmount 时调用
|
||||
// Store the cleanup function to call when unmounted
|
||||
cleanupFns.set(fn, cleanup);
|
||||
// 返回清理函数
|
||||
// Return cleanup function
|
||||
return cleanup;
|
||||
}),
|
||||
}));
|
||||
|
||||
// 模拟 store
|
||||
// Simulated store
|
||||
const mockDestory = vi.fn();
|
||||
vi.mock('../../src/space/store', () => ({
|
||||
useSpaceAuthStore: vi.fn(selector => selector({ destory: mockDestory })),
|
||||
}));
|
||||
|
||||
// 创建一个包装函数,确保在 unmount 时调用清理函数
|
||||
// Create a wrapper function to ensure that the cleanup function is called when unmounted
|
||||
function renderHookWithCleanup(callback, options = {}) {
|
||||
const result = renderHook(callback, options);
|
||||
const originalUnmount = result.unmount;
|
||||
|
||||
result.unmount = () => {
|
||||
// 调用所有清理函数
|
||||
// Call all cleanup functions
|
||||
cleanupFns.forEach(cleanup => {
|
||||
if (typeof cleanup === 'function') {
|
||||
cleanup();
|
||||
}
|
||||
});
|
||||
// 调用原始的 unmount
|
||||
// Call the original unmount
|
||||
originalUnmount();
|
||||
};
|
||||
|
||||
@@ -66,16 +66,16 @@ describe('useDestorySpace', () => {
|
||||
it('应该在组件卸载时调用 destory 方法', () => {
|
||||
const spaceId = 'test-space-id';
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { unmount } = renderHookWithCleanup(() => useDestorySpace(spaceId));
|
||||
|
||||
// 初始时不应调用 destory
|
||||
// Destory should not be called initially
|
||||
expect(mockDestory).not.toHaveBeenCalled();
|
||||
|
||||
// 模拟组件卸载
|
||||
// Simulate component uninstall
|
||||
unmount();
|
||||
|
||||
// 卸载时应调用 destory 并传入正确的 spaceId
|
||||
// When uninstalling, call destory and pass in the correct spaceId.
|
||||
expect(mockDestory).toHaveBeenCalledTimes(1);
|
||||
expect(mockDestory).toHaveBeenCalledWith(spaceId);
|
||||
});
|
||||
@@ -84,25 +84,25 @@ describe('useDestorySpace', () => {
|
||||
const spaceId1 = 'space-id-1';
|
||||
const spaceId2 = 'space-id-2';
|
||||
|
||||
// 渲染第一个 hook 实例
|
||||
// Render the first hook instance
|
||||
const { unmount: unmount1 } = renderHookWithCleanup(() =>
|
||||
useDestorySpace(spaceId1),
|
||||
);
|
||||
|
||||
// 渲染第二个 hook 实例
|
||||
// Render the second hook instance
|
||||
const { unmount: unmount2 } = renderHookWithCleanup(() =>
|
||||
useDestorySpace(spaceId2),
|
||||
);
|
||||
|
||||
// 卸载第一个实例
|
||||
// Uninstall the first instance
|
||||
unmount1();
|
||||
expect(mockDestory).toHaveBeenCalledWith(spaceId1);
|
||||
|
||||
// 卸载第二个实例
|
||||
// Uninstall the second instance
|
||||
unmount2();
|
||||
expect(mockDestory).toHaveBeenCalledWith(spaceId2);
|
||||
|
||||
// 总共应调用两次
|
||||
// It should be called twice in total.
|
||||
expect(mockDestory).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,12 +20,12 @@ import { SpaceRoleType } from '@coze-arch/idl/developer_api';
|
||||
|
||||
import { ESpacePermisson } from '../../src/space/constants';
|
||||
|
||||
// 模拟 useSpaceRole
|
||||
// Simulation useSpaceRole
|
||||
vi.mock('../../src/space/use-space-role', () => ({
|
||||
useSpaceRole: vi.fn(),
|
||||
}));
|
||||
|
||||
// 模拟 calcPermission
|
||||
// simulated calcPermission
|
||||
vi.mock('../../src/space/calc-permission', () => ({
|
||||
calcPermission: vi.fn(),
|
||||
}));
|
||||
@@ -40,26 +40,26 @@ describe('useSpaceAuth', () => {
|
||||
const permissionKey = ESpacePermisson.UpdateSpace;
|
||||
const mockRoles = [SpaceRoleType.Owner];
|
||||
|
||||
// 模拟 useSpaceRole 返回角色
|
||||
// Simulate useSpaceRole return role
|
||||
(useSpaceRole as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockRoles,
|
||||
);
|
||||
|
||||
// 模拟 calcPermission 返回权限结果
|
||||
// Simulate calcPermission return permission result
|
||||
(calcPermission as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
true,
|
||||
);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useSpaceAuth(permissionKey, spaceId));
|
||||
|
||||
// 验证 useSpaceRole 被调用,并传入正确的 spaceId
|
||||
// Verify that useSpaceRole is called, passing in the correct spaceId.
|
||||
expect(useSpaceRole).toHaveBeenCalledWith(spaceId);
|
||||
|
||||
// 验证 calcPermission 被调用,并传入正确的参数
|
||||
// Verify that calcPermission is called, passing in the correct parameters
|
||||
expect(calcPermission).toHaveBeenCalledWith(permissionKey, mockRoles);
|
||||
|
||||
// 验证返回值与 calcPermission 的返回值一致
|
||||
// Verify that the return value is consistent with the return value of calcPermission
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
@@ -68,20 +68,20 @@ describe('useSpaceAuth', () => {
|
||||
const permissionKey = ESpacePermisson.UpdateSpace;
|
||||
const mockRoles = [SpaceRoleType.Member];
|
||||
|
||||
// 模拟 useSpaceRole 返回角色
|
||||
// Simulate useSpaceRole return role
|
||||
(useSpaceRole as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockRoles,
|
||||
);
|
||||
|
||||
// 模拟 calcPermission 返回权限结果
|
||||
// Simulate calcPermission return permission result
|
||||
(calcPermission as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
false,
|
||||
);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useSpaceAuth(permissionKey, spaceId));
|
||||
|
||||
// 验证返回值与 calcPermission 的返回值一致
|
||||
// Verify that the return value is consistent with the return value of calcPermission
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
@@ -90,23 +90,23 @@ describe('useSpaceAuth', () => {
|
||||
const permissionKey = ESpacePermisson.UpdateSpace;
|
||||
const mockRoles: SpaceRoleType[] = [];
|
||||
|
||||
// 模拟 useSpaceRole 返回空角色数组
|
||||
// Simulate useSpaceRole returns an empty character array
|
||||
(useSpaceRole as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockRoles,
|
||||
);
|
||||
|
||||
// 模拟 calcPermission 返回权限结果
|
||||
// Simulate calcPermission return permission result
|
||||
(calcPermission as unknown as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
false,
|
||||
);
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useSpaceAuth(permissionKey, spaceId));
|
||||
|
||||
// 验证 calcPermission 被调用,并传入正确的参数
|
||||
// Verify that calcPermission is called, passing in the correct parameters
|
||||
expect(calcPermission).toHaveBeenCalledWith(permissionKey, mockRoles);
|
||||
|
||||
// 验证返回值与 calcPermission 的返回值一致
|
||||
// Verify that the return value is consistent with the return value of calcPermission
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,23 +20,23 @@ import { SpaceRoleType } from '@coze-arch/idl/developer_api';
|
||||
|
||||
import { useSpaceAuthStore } from '../../src/space/store';
|
||||
|
||||
// 模拟 zustand
|
||||
// Analog zustand
|
||||
vi.mock('zustand/react/shallow', () => ({
|
||||
useShallow: fn => fn,
|
||||
}));
|
||||
|
||||
// 模拟 foundation-sdk
|
||||
// Simulation foundation-sdk
|
||||
const mockUseSpace = vi.fn();
|
||||
vi.mock('@coze-arch/foundation-sdk', () => ({
|
||||
useSpace: (...args) => mockUseSpace(...args),
|
||||
}));
|
||||
|
||||
// 模拟 store
|
||||
// Simulated store
|
||||
vi.mock('../../src/space/store', () => ({
|
||||
useSpaceAuthStore: vi.fn(),
|
||||
}));
|
||||
|
||||
// 导入实际模块,确保在模拟之后导入
|
||||
// Import the actual module, make sure to import it after simulation
|
||||
import { useSpaceRole } from '../../src/space/use-space-role';
|
||||
|
||||
describe('useSpaceRole', () => {
|
||||
@@ -49,40 +49,40 @@ describe('useSpaceRole', () => {
|
||||
const mockSpace = { id: spaceId, name: 'Test Space' };
|
||||
const mockRoles = [SpaceRoleType.Owner];
|
||||
|
||||
// 模拟 useSpace 返回 space 对象
|
||||
// Simulate useSpace Return space object
|
||||
mockUseSpace.mockReturnValue(mockSpace);
|
||||
|
||||
// 模拟 useSpaceAuthStore 返回 isReady 和 role
|
||||
// Emulate useSpaceAuthStore returns isReady and role
|
||||
(useSpaceAuthStore as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
||||
isReady: true,
|
||||
role: mockRoles,
|
||||
});
|
||||
|
||||
// 渲染 hook
|
||||
// Render hook
|
||||
const { result } = renderHook(() => useSpaceRole(spaceId));
|
||||
|
||||
// 验证 useSpace 被调用,并传入正确的 spaceId
|
||||
// Verify that useSpace is called, passing in the correct spaceId.
|
||||
expect(mockUseSpace).toHaveBeenCalledWith(spaceId);
|
||||
|
||||
// 验证 useSpaceAuthStore 被调用,并传入正确的选择器
|
||||
// Verify that useSpaceAuthStore is called, passing in the correct selector
|
||||
expect(useSpaceAuthStore).toHaveBeenCalled();
|
||||
|
||||
// 验证返回值与预期一致
|
||||
// Verify that the return value is as expected
|
||||
expect(result.current).toEqual(mockRoles);
|
||||
});
|
||||
|
||||
it('应该在 space 不存在时抛出错误', () => {
|
||||
const spaceId = 'test-space-id';
|
||||
|
||||
// 模拟 useSpace 返回 null
|
||||
// Simulate useSpace returns null
|
||||
mockUseSpace.mockReturnValue(null);
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证渲染 hook 时抛出错误
|
||||
// Error thrown while validating render hook
|
||||
expect(() => useSpaceRole(spaceId)).toThrow(
|
||||
'useSpaceAuth must be used after space list has been pulled.',
|
||||
);
|
||||
@@ -92,21 +92,21 @@ describe('useSpaceRole', () => {
|
||||
const spaceId = 'test-space-id';
|
||||
const mockSpace = { id: spaceId, name: 'Test Space' };
|
||||
|
||||
// 模拟 useSpace 返回 space 对象
|
||||
// Simulate useSpace Return space object
|
||||
mockUseSpace.mockReturnValue(mockSpace);
|
||||
|
||||
// 模拟 useSpaceAuthStore 返回 isReady 为 false
|
||||
// Emulate useSpaceAuthStore returns isReady to false
|
||||
(useSpaceAuthStore as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
||||
isReady: false,
|
||||
role: null,
|
||||
});
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证渲染 hook 时抛出错误
|
||||
// Error thrown while validating render hook
|
||||
expect(() => useSpaceRole(spaceId)).toThrow(
|
||||
'useSpaceAuth must be used after useInitSpaceRole has been completed.',
|
||||
);
|
||||
@@ -116,21 +116,21 @@ describe('useSpaceRole', () => {
|
||||
const spaceId = 'test-space-id';
|
||||
const mockSpace = { id: spaceId, name: 'Test Space' };
|
||||
|
||||
// 模拟 useSpace 返回 space 对象
|
||||
// Simulate useSpace Return space object
|
||||
mockUseSpace.mockReturnValue(mockSpace);
|
||||
|
||||
// 模拟 useSpaceAuthStore 返回 isReady 为 true,但 role 为 null
|
||||
// Emulate useSpaceAuthStore returns isReady as true, but role as null
|
||||
(useSpaceAuthStore as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
||||
isReady: true,
|
||||
role: null,
|
||||
});
|
||||
|
||||
// 使用 vi.spyOn 监听 console.error 以防止测试输出错误信息
|
||||
// Use vi.spyOn to listen to console.error to prevent test output error messages
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {
|
||||
// 空实现,防止错误输出
|
||||
// Empty implementation to prevent error output
|
||||
});
|
||||
|
||||
// 验证渲染 hook 时抛出错误
|
||||
// Error thrown while validating render hook
|
||||
expect(() => useSpaceRole(spaceId)).toThrow(
|
||||
`Can not get space role of space: ${spaceId}`,
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// TODO: 替换成Project接口导出的idl
|
||||
// TODO: replace with idl exported by Project interface
|
||||
export enum ProjectRoleType {
|
||||
Owner = 'owner',
|
||||
Editor = 'editor',
|
||||
@@ -22,51 +22,51 @@ export enum ProjectRoleType {
|
||||
|
||||
export enum EProjectPermission {
|
||||
/**
|
||||
* 访问/查看project
|
||||
* Visit/view projects
|
||||
*/
|
||||
View,
|
||||
/**
|
||||
* 编辑project基础信息
|
||||
* Edit project basic information
|
||||
*/
|
||||
EDIT_INFO,
|
||||
/**
|
||||
* 删除project
|
||||
* Delete project
|
||||
*/
|
||||
DELETE,
|
||||
/**
|
||||
* 发布project
|
||||
* Publish project
|
||||
*/
|
||||
PUBLISH,
|
||||
/**
|
||||
* 创建project内资源
|
||||
* Create project resources
|
||||
*/
|
||||
CREATE_RESOURCE,
|
||||
/**
|
||||
* 在project内复制资源
|
||||
* Copy resources within the project
|
||||
*/
|
||||
COPY_RESOURCE,
|
||||
/**
|
||||
* 复制project/创建副本
|
||||
* Copy project/create copy
|
||||
*/
|
||||
COPY,
|
||||
/**
|
||||
* 试运行plugin
|
||||
* Practice running plugins
|
||||
*/
|
||||
TEST_RUN_PLUGIN,
|
||||
/**
|
||||
* 试运行workflow
|
||||
* Practice running workflow
|
||||
*/
|
||||
TEST_RUN_WORKFLOW,
|
||||
/**
|
||||
* 添加project协作者
|
||||
* Add project collaborators
|
||||
*/
|
||||
ADD_COLLABORATOR,
|
||||
/**
|
||||
* 删除project协作者
|
||||
* Delete project collaborator
|
||||
*/
|
||||
DELETE_COLLABORATOR,
|
||||
/**
|
||||
* 回滚 APP 版本
|
||||
* Roll back the APP version
|
||||
*/
|
||||
ROLLBACK,
|
||||
}
|
||||
|
||||
@@ -20,26 +20,26 @@ import { create } from 'zustand';
|
||||
import { type ProjectRoleType } from './constants';
|
||||
|
||||
interface ProjectAuthStoreState {
|
||||
// 每一个Project的角色数据
|
||||
// Role Data for Each Project
|
||||
roles: {
|
||||
[projectId: string]: ProjectRoleType[];
|
||||
};
|
||||
// 每一个Project的角色数据的初始化状态,是否完成初始化。
|
||||
// The initialization status of each Project's role data, and whether the initialization has been completed.
|
||||
isReady: {
|
||||
[projectId: string]: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface SpaceAuthStoreAction {
|
||||
// 设置projectId对应的Project的角色
|
||||
// Set the role of the Project corresponding to the projectId
|
||||
setRoles: (projectId: string, role: ProjectRoleType[]) => void;
|
||||
// 设置projectId对应的Project的数据是否ready
|
||||
// Set whether the data of the Project corresponding to the projectId is ready
|
||||
setIsReady: (projectId: string, isReady: boolean) => void;
|
||||
// 回收Project数据
|
||||
// Recovering Project Data
|
||||
destory: (projectId) => void;
|
||||
}
|
||||
/**
|
||||
* ProjectAuthStore设计成支持多Project切换,维护多个Project的数据,防止因为Project切换时序导致的bug。
|
||||
* ProjectAuthStore is designed to support multi-project switching, maintain data of multiple projects, and prevent bugs caused by project switching timing.
|
||||
*/
|
||||
export const useProjectAuthStore = create<
|
||||
ProjectAuthStoreState & SpaceAuthStoreAction
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useDestoryProject(projectId: string) {
|
||||
|
||||
return useEffect(
|
||||
() => () => {
|
||||
// 空间组件销毁时,清空对应space数据
|
||||
// When the space component is destroyed, empty the corresponding space data
|
||||
destorySpace(projectId);
|
||||
},
|
||||
[],
|
||||
|
||||
@@ -26,7 +26,7 @@ export function useProjectAuth(
|
||||
projectId: string,
|
||||
spaceId: string,
|
||||
) {
|
||||
// 获取space类型信息
|
||||
// Get space type information
|
||||
const space = useSpace(spaceId);
|
||||
|
||||
if (!space?.space_type) {
|
||||
@@ -35,13 +35,13 @@ export function useProjectAuth(
|
||||
);
|
||||
}
|
||||
|
||||
// 获取space role信息
|
||||
// Get space role information
|
||||
const spaceRoles = useSpaceRole(spaceId);
|
||||
|
||||
// 获取project role信息
|
||||
// Get project role information
|
||||
const projectRoles = useProjectRole(projectId);
|
||||
|
||||
// 计算权限点
|
||||
// Calculate permission spot
|
||||
return calcPermission(key, {
|
||||
projectRoles,
|
||||
spaceRoles,
|
||||
|
||||
@@ -15,44 +15,44 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 空间相关的权限点枚举
|
||||
* Spatially dependent permission spot enumeration
|
||||
*/
|
||||
export enum ESpacePermisson {
|
||||
/**
|
||||
* 更新空间
|
||||
* update space
|
||||
*/
|
||||
UpdateSpace,
|
||||
/**
|
||||
* 删除空间
|
||||
* delete space
|
||||
*/
|
||||
DeleteSpace,
|
||||
/**
|
||||
* 添加成员
|
||||
* Add member
|
||||
*/
|
||||
AddBotSpaceMember,
|
||||
/**
|
||||
* 移除空间成员
|
||||
* Remove space member
|
||||
*/
|
||||
RemoveSpaceMember,
|
||||
/**
|
||||
* 退出空间
|
||||
* exit space
|
||||
*/
|
||||
ExitSpace,
|
||||
/**
|
||||
* 转移owner权限
|
||||
* Transfer owner permissions
|
||||
*/
|
||||
TransferSpace,
|
||||
/**
|
||||
* 更新成员
|
||||
* update member
|
||||
*/
|
||||
UpdateSpaceMember,
|
||||
/**
|
||||
* 管理API-KEY
|
||||
* Manage API-KEY
|
||||
*/
|
||||
API,
|
||||
}
|
||||
|
||||
/**
|
||||
* 空间角色枚举
|
||||
* Spatial Role Enumeration
|
||||
*/
|
||||
export { SpaceRoleType } from '@coze-arch/idl/developer_api';
|
||||
|
||||
@@ -19,26 +19,26 @@ import { create } from 'zustand';
|
||||
import { type SpaceRoleType } from '@coze-arch/idl/developer_api';
|
||||
|
||||
interface SpaceAuthStoreState {
|
||||
// 每一个空间的角色数据
|
||||
// Role data for each space
|
||||
roles: {
|
||||
[spaceId: string]: SpaceRoleType[];
|
||||
};
|
||||
// 每一个空间的角色数据的初始化状态,是否完成初始化。
|
||||
// The initialization status of the character data in each space, and whether the initialization is completed.
|
||||
isReady: {
|
||||
[spaceId: string]: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface SpaceAuthStoreAction {
|
||||
// 设置spaceId对应的空间的角色
|
||||
// Set the role of the space corresponding to the spaceId
|
||||
setRoles: (spaceId: string, roles: SpaceRoleType[]) => void;
|
||||
// 设置spaceId对应的空间的数据是否ready
|
||||
// Set whether the data of the space corresponding to the spaceId is ready
|
||||
setIsReady: (spaceId: string, isReady: boolean) => void;
|
||||
// 回收空间数据
|
||||
// Recovering spatial data
|
||||
destory: (spaceId) => void;
|
||||
}
|
||||
/**
|
||||
* SpaceAuthStore设计成支持多空间切换,维护多个空间的数据,位置因为空间切换时序导致的bug。
|
||||
* SpaceAuthStore is designed to support multi-space switching and maintain data in multiple spaces. The location is due to bugs caused by the timing of space switching.
|
||||
*/
|
||||
export const useSpaceAuthStore = create<
|
||||
SpaceAuthStoreState & SpaceAuthStoreAction
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useDestorySpace(spaceId: string) {
|
||||
|
||||
return useEffect(
|
||||
() => () => {
|
||||
// 空间组件销毁时,清空对应space数据
|
||||
// When the space component is destroyed, empty the corresponding space data
|
||||
destorySpace(spaceId);
|
||||
},
|
||||
[],
|
||||
|
||||
@@ -19,8 +19,8 @@ import { type ESpacePermisson } from './constants';
|
||||
import { calcPermission } from './calc-permission';
|
||||
|
||||
export function useSpaceAuth(key: ESpacePermisson, spaceId: string) {
|
||||
// 获取space role信息
|
||||
// Get space role information
|
||||
const role = useSpaceRole(spaceId);
|
||||
// 计算权限点
|
||||
// Calculate permission spot
|
||||
return calcPermission(key, role);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { useSpace } from '@coze-arch/foundation-sdk';
|
||||
import { useSpaceAuthStore } from './store';
|
||||
|
||||
export function useSpaceRole(spaceId: string) {
|
||||
// 获取space信息,已有hook。
|
||||
// Get space information, there are hooks.
|
||||
const space = useSpace(spaceId);
|
||||
|
||||
if (!space) {
|
||||
|
||||
@@ -20,9 +20,9 @@ export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
test: {
|
||||
// 全局测试超时时间(毫秒)
|
||||
testTimeout: 10000, // 10秒
|
||||
// Hook 超时时间(毫秒)
|
||||
hookTimeout: 10000, // 10秒
|
||||
// Global test timeout (milliseconds)
|
||||
testTimeout: 10000, // 10 seconds
|
||||
// Hook timeout in milliseconds
|
||||
hookTimeout: 10000, // 10 seconds
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user