build-flow.api/tests/BuildFlow.Workflow.Tests/Form/NodeFieldPermissionTests.cs
xiangning 74e99850e5 feat(workflow): 添加钉钉式节点级字段权限和依次审批功能
- 实现钉钉式节点级字段权限:从审批节点config解析fieldPermissions进行表单校验
- 添加依次审批模式支持:按顺序逐个创建审批任务并推进流程
- 扩展工作流定义实体:新增DefinitionTree字段存储钉式审批流树JSON
- 更新表单验证器:支持节点级字段权限配置影响必填校验逻辑
- 重构后台服务:修复OperationCanceledException处理防止进程崩溃
- 扩展脚本执行服务:支持加载各模块Application/Domain程序集
- 更新菜单配置:调整组件管理和脚本函数菜单顺序
- 完善工作流引擎:修复实例图加载和任务完成逻辑
2026-07-17 17:05:35 +08:00

80 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using FluentAssertions;
using Workflow.Application.Form.Schema;
using Xunit;
namespace BuildFlow.Workflow.Tests.Form;
/// <summary>
/// 钉钉式节点级字段权限的纯单元测试。
/// 验证 FieldPermissionEvaluator.GetHiddenFieldsByNodePermission 正确按节点 config 的
/// fieldPermissions(字段 path → 动作)计算出 hidden 字段集合。
/// </summary>
public class NodeFieldPermissionTests
{
private static readonly IReadOnlyList<FieldSummary> SampleFields = new[]
{
new FieldSummary("amount", "number", "InputNumber", false, "金额", [], [], [], null),
new FieldSummary("reason", "string", "Input", true, "事由", [], [], [], null),
new FieldSummary("attachment", "array", "Upload", false, "附件", [], [], [], null),
};
[Fact]
public void NullPermissions_ReturnsEmpty()
{
var hidden = FieldPermissionEvaluator.GetHiddenFieldsByNodePermission(SampleFields, null);
hidden.Should().BeEmpty();
}
[Fact]
public void EmptyPermissions_ReturnsEmpty()
{
var hidden = FieldPermissionEvaluator.GetHiddenFieldsByNodePermission(SampleFields, new Dictionary<string, string>());
hidden.Should().BeEmpty();
}
[Fact]
public void HiddenFields_AreCollected()
{
var perms = new Dictionary<string, string>
{
["amount"] = "editable",
["reason"] = "hidden",
["attachment"] = "visible",
};
var hidden = FieldPermissionEvaluator.GetHiddenFieldsByNodePermission(SampleFields, perms);
hidden.Should().ContainSingle().Which.Should().Be("reason");
}
[Fact]
public void UnknownPath_IsIgnored()
{
// 权限配置里写了表单不存在的字段路径,应被忽略(不误伤、不报错)
var perms = new Dictionary<string, string>
{
["nonExistent"] = "hidden",
["amount"] = "hidden",
};
var hidden = FieldPermissionEvaluator.GetHiddenFieldsByNodePermission(SampleFields, perms);
hidden.Should().ContainSingle().Which.Should().Be("amount");
}
[Fact]
public void AllHidden_AllFieldsCollected()
{
var perms = new Dictionary<string, string>
{
["amount"] = "hidden",
["reason"] = "hidden",
["attachment"] = "hidden",
};
var hidden = FieldPermissionEvaluator.GetHiddenFieldsByNodePermission(SampleFields, perms);
hidden.Should().HaveCount(3);
}
}