Files
EasyDesignCollection/test/station_test.dart
T
admin fe5e0be131 feat(flow): 泳道拓宽计划(空泳道策略 + 多槽位泳道,三视图同步);发布 v1.3.4
- 空泳道策略(F2 文档设置 →「泳道」):动作全部移走的泳道可保留(默认,序号不变)
  或自动移除;条形空行 / 圆周空环 / 流程空列与左侧栏占位行同步
- 泳道加宽(1–5 槽):双击条形视图左侧泳道编号 / 右键空白泳道 / 左侧栏「N 槽」徽标;
  条形分子行(浅色虚线分隔)、圆周同色加宽环带 + 槽位虚线、流程图分子列且泳道带
  随内容智能加宽;拖拽动作同时换道 + 换槽位;旧数据零迁移(row 语义改为槽位并自动钳制)
- 流程图智能排开:同源同层扇出连线在空隙内均匀铺开;同层节点水平重叠自动推开
- 显示修复:画布左栏标题按真实行高排版(灰色副标题不再被换行标题压住,
  持续换行到泳道高度不足);多槽位采用「槽位紧凑 + 泳道间拉开」的间隔
- 「时序创建和编辑」更名为「文档设置」(含对话框标题/帮助/文档);新增自动保存
  (默认 10 分钟,可选 1/5/10/30 或关闭;写入文件并同步 .bak)
- 授权临时冻结(kLicenseRequired=false):桌面版导出无需 .lic;关于页授权状态
  「开放授权版本」、EDC 版权、开发者与交流群(邮箱 liuyu65@126.com、微信 online-goose)
- 更新体验:直接升级到最新版本提示、下载过程保持屏幕常亮提示、
  下载/上传统一限速 320KB/s(客户端限速 + 发布脚本 --limit-rate 320k)
- docs/HELP.md 与帮助中心同步更新;新增 docs/ROADMAP.md 开发路线图
- flutter analyze 0 问题、40 项测试全过;演示截图更新(含泳道加宽与拥挤场景验证图)
2026-10-10 09:21:45 +08:00

143 lines
6.4 KiB
Dart
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.
import 'dart:ui' show Rect, Size;
import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/layout/flow_layout.dart';
import 'package:sequence_diagram/layout/layout.dart';
import 'package:sequence_diagram/model/models.dart';
import 'package:sequence_diagram/state/app_controller.dart';
void main() {
group('station management', () {
test('setStations reassigns actions of a removed station', () {
final AppController c = AppController(project: Project.demo());
// 演示工程至少包含两个工位;移除第二个工位后其动作应被重新分配。
expect(c.project.stations.length, greaterThan(1));
final String removed = c.project.stations[1].id;
expect(c.project.actions.any((Action a) => a.stationId == removed), isTrue);
c.setStations(<Station>[c.project.stations.first]);
expect(c.project.stations.length, 1);
expect(c.project.actions.every((Action a) => a.stationId == c.project.stations.first.id), isTrue);
expect(c.canUndo, isTrue);
});
test('setStations ignores an empty list (keep at least one station)', () {
final AppController c = AppController(project: Project.demo());
final int before = c.project.stations.length;
c.setStations(<Station>[]);
expect(c.project.stations.length, before);
});
test('setStations can add and rename stations', () {
final AppController c = AppController(project: Project.demo());
final int before = c.project.stations.length;
final List<Station> next = <Station>[
...c.project.stations,
const Station(id: 'ST9', name: '工位 9', order: 9, color: 0xFF4ADE80),
];
c.setStations(next);
expect(c.project.stations.length, before + 1);
expect(c.project.stationById('ST9')?.name, '工位 9');
});
});
group('空泳道策略', () {
test('保留空泳道:动作移走后泳道仍在,关闭后自动移除', () {
final AppController c = AppController(project: Project.demo());
// 演示工程中 A4 独占 L3(layer 2):移走后该泳道变为空泳道。
c.moveActionLane('A4', 1);
expect(c.project.renderLanes, <int>[0, 1, 2]);
expect(c.project.renderLaneCount, 3);
// 三种视图的布局都包含保留的空泳道。
expect(BarLayout(c.project, const Size(1280, 800)).lanes, <int>[0, 1, 2]);
expect(CircularLayout(c.project, const Size(1280, 800)).lanes, <int>[0, 1, 2]);
// 关闭策略:空泳道移除、序号顺延。
c.setKeepEmptyLanes(false);
expect(c.project.renderLanes, <int>[0, 1]);
// 重新开启:以当前使用中的泳道为保底(不会把已收缩的泳道补回来)。
c.setKeepEmptyLanes(true);
expect(c.project.renderLanes, <int>[0, 1]);
// 策略字段随 JSON 往返保存。
final Project decoded = Project.decode(c.project.encode());
expect(decoded.keepEmptyLanes, isTrue);
expect(decoded.minLaneCount, 2);
});
test('关闭策略时动作移走立即收缩', () {
final AppController c = AppController(project: Project.demo());
c.setKeepEmptyLanes(false);
c.moveActionLane('A4', 1);
expect(c.project.renderLanes, <int>[0, 1]);
});
});
group('泳道槽位(加宽)', () {
test('加宽后动作按槽位分行,几何与反查一致,配置随 JSON 往返', () {
final AppController c = AppController(project: Project.demo());
// L1(layer 0)加宽为 2 槽:加宽本身不散乱动作(仍全部在槽 1),
// 用户再把 A2 拖到槽 2。
c.setLaneSlots(0, 2);
expect(c.project.slotsOf(0), 2);
c.moveActionTo('A2', 0, 1);
final BarLayout layout = BarLayout(c.project, const Size(1280, 800));
final Action a1 = c.project.actionById('A1')!;
final Action a2 = c.project.actionById('A2')!;
expect(layout.slotOf(a1), 0);
expect(layout.slotOf(a2), 1);
final Rect r1 = layout.rectFor(a1);
final Rect r2 = layout.rectFor(a2);
expect((r1.top - r2.top).abs(), greaterThan(10), reason: '不同槽位应位于不同子行');
// 纵坐标反查(泳道, 槽位)。
expect(layout.laneSlotAt(r1.center.dy), (0, 0));
expect(layout.laneSlotAt(r2.center.dy), (0, 1));
// 圆周视图:同一轨道的不同槽位对应不同子环半径。
final CircularLayout cl = CircularLayout(c.project, const Size(1280, 800));
expect(cl.subRingCount, greaterThan(0));
expect(cl.radiusFor(0, 1) - cl.radiusFor(0, 0), closeTo(cl.pitch, 0.001));
expect(cl.laneSlotAtRadius(cl.radiusFor(0, 1)), (0, 1));
// 流程图:同一泳道的不同槽位对应不同列中心。
final FlowLayout fl = FlowLayout(c.project);
expect((fl.nodeById('A1')!.rect.center.dx - fl.nodeById('A2')!.rect.center.dx).abs(),
greaterThan(50));
expect(fl.laneWidth(0), greaterThan(FlowLayout.nodeW));
// JSON 往返保留槽位配置。
final Project decoded = Project.decode(c.project.encode());
expect(decoded.slotsOf(0), 2);
});
test('跨泳道移动可指定槽位;缩窄时槽位被钳制且动作不丢失', () {
final AppController c = AppController(project: Project.demo());
// 把 A4 移到 L2(layer 1)槽 1。
c.moveActionTo('A4', 1, 0);
expect(c.project.actionById('A4')!.layer, 1);
expect(c.project.actionById('A4')!.row, 0);
// 加宽 L2 为 2 槽 → 3 槽,再缩回 2 槽:A4 的槽位在布局中钳制到末槽。
c.setLaneSlots(1, 3);
c.moveActionTo('A4', 1, 2);
c.setLaneSlots(1, 2);
final BarLayout layout = BarLayout(c.project, const Size(1280, 800));
expect(layout.slotOf(c.project.actionById('A4')!), 1);
expect(c.project.actionById('A4')!.row, 2, reason: '数据保留原值,仅布局钳制');
});
});
group('自动保存设置', () {
test('默认启用且 10 分钟一次;启停与间隔随 JSON 往返', () {
final AppController c = AppController(project: Project.demo());
expect(c.project.autoSaveEnabled, isTrue);
expect(c.project.autoSaveMinutes, 10);
c.setAutoSave(minutes: 5);
expect(c.project.autoSaveMinutes, 5);
c.setAutoSave(enabled: false);
expect(c.project.autoSaveEnabled, isFalse);
final Project decoded = Project.decode(c.project.encode());
expect(decoded.autoSaveEnabled, isFalse);
expect(decoded.autoSaveMinutes, 5);
});
});
}