2026-09-18 23:32:36 +08:00
|
|
|
import 'package:flutter_test/flutter_test.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());
|
2026-10-09 13:59:05 +08:00
|
|
|
// 演示工程至少包含两个工位;移除第二个工位后其动作应被重新分配。
|
|
|
|
|
expect(c.project.stations.length, greaterThan(1));
|
2026-09-18 23:32:36 +08:00
|
|
|
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());
|
2026-10-09 13:59:05 +08:00
|
|
|
final int before = c.project.stations.length;
|
2026-09-18 23:32:36 +08:00
|
|
|
final List<Station> next = <Station>[
|
|
|
|
|
...c.project.stations,
|
2026-10-09 13:59:05 +08:00
|
|
|
const Station(id: 'ST9', name: '工位 9', order: 9, color: 0xFF4ADE80),
|
2026-09-18 23:32:36 +08:00
|
|
|
];
|
|
|
|
|
c.setStations(next);
|
2026-10-09 13:59:05 +08:00
|
|
|
expect(c.project.stations.length, before + 1);
|
|
|
|
|
expect(c.project.stationById('ST9')?.name, '工位 9');
|
2026-09-18 23:32:36 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|