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()); // 演示工程至少包含两个工位;移除第二个工位后其动作应被重新分配。 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([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([]); 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 next = [ ...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'); }); }); }