84 lines
2.8 KiB
Dart
84 lines
2.8 KiB
Dart
|
|
// 依赖编辑:修改已有依赖的类型 / 偏移 / 前置动作,并保留手动走线偏移。
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:sequence_diagram/model/models.dart';
|
||
|
|
import 'package:sequence_diagram/state/app_controller.dart';
|
||
|
|
|
||
|
|
Project _project() {
|
||
|
|
Action a(String id, double start) => Action(
|
||
|
|
id: id,
|
||
|
|
name: id,
|
||
|
|
stationId: 'ST1',
|
||
|
|
driver: '',
|
||
|
|
startAngle: start,
|
||
|
|
durationAngle: 30,
|
||
|
|
layer: 0,
|
||
|
|
color: 0xFF4CC9F0,
|
||
|
|
);
|
||
|
|
return Project(
|
||
|
|
name: 'dep-edit',
|
||
|
|
cycle: const Cycle(durationMs: 2400),
|
||
|
|
stations: const <Station>[
|
||
|
|
Station(id: 'ST1', name: 'S', order: 0, color: 0xFF4CC9F0),
|
||
|
|
],
|
||
|
|
actions: <Action>[a('A1', 0), a('A2', 60), a('A3', 120)],
|
||
|
|
units: const UnitSettings(),
|
||
|
|
viewState: const ViewState(mode: ViewMode.bar),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('updateDependency:修改类型与偏移,保留走线偏移', () {
|
||
|
|
final AppController c = AppController(project: _project());
|
||
|
|
addTearDown(c.dispose);
|
||
|
|
c.addDependency('A1', 'A2', DepType.fs, 0);
|
||
|
|
c.setDependencyOffset('A1', 'A2', 30);
|
||
|
|
c.updateDependency(
|
||
|
|
'A1',
|
||
|
|
'A2',
|
||
|
|
fromId: 'A1',
|
||
|
|
type: DepType.ss,
|
||
|
|
offset: 12,
|
||
|
|
);
|
||
|
|
final Dependency d =
|
||
|
|
c.project.actionById('A2')!.deps.firstWhere((Dependency d) => d.fromId == 'A1');
|
||
|
|
expect(d.type, DepType.ss);
|
||
|
|
expect(d.offsetAngle, 12);
|
||
|
|
expect(d.routeOffset, 30);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改循环时长:依赖偏移的时间保持不变', () {
|
||
|
|
final AppController c = AppController(project: _project());
|
||
|
|
addTearDown(c.dispose);
|
||
|
|
c.addDependency('A1', 'A2', DepType.ss, 50);
|
||
|
|
c.setCycleDuration(4800);
|
||
|
|
Dependency d =
|
||
|
|
c.project.actionById('A2')!.deps.firstWhere((Dependency d) => d.fromId == 'A1');
|
||
|
|
// 2400ms 下 50° = 0.333s;换成 4800ms 后角度应减半,时间不变。
|
||
|
|
expect(d.offsetAngle, closeTo(25, 0.001));
|
||
|
|
c.setCycleDuration(2400);
|
||
|
|
d = c.project.actionById('A2')!.deps.firstWhere((Dependency d) => d.fromId == 'A1');
|
||
|
|
expect(d.offsetAngle, closeTo(50, 0.001));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('updateDependency:更换前置动作时去重并合并', () {
|
||
|
|
final AppController c = AppController(project: _project());
|
||
|
|
addTearDown(c.dispose);
|
||
|
|
c.addDependency('A1', 'A2', DepType.fs, 0);
|
||
|
|
c.addDependency('A3', 'A2', DepType.ss, 5);
|
||
|
|
c.updateDependency(
|
||
|
|
'A1',
|
||
|
|
'A2',
|
||
|
|
fromId: 'A3',
|
||
|
|
type: DepType.ff,
|
||
|
|
offset: 7,
|
||
|
|
);
|
||
|
|
final List<Dependency> deps = c.project.actionById('A2')!.deps;
|
||
|
|
expect(deps.where((Dependency d) => d.fromId == 'A1'), isEmpty);
|
||
|
|
final List<Dependency> from3 =
|
||
|
|
deps.where((Dependency d) => d.fromId == 'A3').toList();
|
||
|
|
expect(from3.length, 1);
|
||
|
|
expect(from3.single.type, DepType.ff);
|
||
|
|
expect(from3.single.offsetAngle, 7);
|
||
|
|
});
|
||
|
|
}
|