FB-05: closed-loop routes in Route Planner
Add an isClosedLoop toggle to route plans (schema v3 -> v4 migration), threaded through the domain model, repository distance recomputation, the overflow menu, and the drawn polyline, so a route can loop back to its first waypoint.
This commit is contained in:
@@ -177,4 +177,57 @@ void main() {
|
||||
final waypoints = await db.waypointsForRoute(routeId);
|
||||
expect(waypoints, hasLength(1));
|
||||
});
|
||||
|
||||
test('a v3 database (FB-05) gains isClosedLoop defaulting to false', () async {
|
||||
// v3: identical to the v2 seed above, plus the route_plans/waypoints tables V3-07
|
||||
// added.
|
||||
seedV1Database();
|
||||
final raw = sqlite3.sqlite3.open(dbFile.path);
|
||||
raw.execute('''
|
||||
ALTER TABLE trips ADD COLUMN activity TEXT NOT NULL DEFAULT 'motorcycle';
|
||||
''');
|
||||
raw.execute('''
|
||||
CREATE TABLE route_plans (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
createdAt INTEGER NOT NULL,
|
||||
activity TEXT NOT NULL DEFAULT 'motorcycle',
|
||||
distanceM REAL NOT NULL DEFAULT 0,
|
||||
estimatedMillis INTEGER NULL,
|
||||
geometry TEXT NULL
|
||||
);
|
||||
CREATE TABLE waypoints (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
routeId INTEGER NOT NULL REFERENCES route_plans (id) ON DELETE CASCADE,
|
||||
ordinal INTEGER NOT NULL,
|
||||
latitude REAL NOT NULL,
|
||||
longitude REAL NOT NULL,
|
||||
name TEXT NULL
|
||||
);
|
||||
CREATE INDEX idx_waypoints_route ON waypoints (routeId);
|
||||
''');
|
||||
raw.execute('''
|
||||
INSERT INTO route_plans (id, name, createdAt) VALUES (1, 'Existing route', 8000);
|
||||
''');
|
||||
raw.execute('PRAGMA user_version = 3;');
|
||||
raw.close();
|
||||
|
||||
final db = AppDatabase(NativeDatabase(dbFile));
|
||||
addTearDown(db.close);
|
||||
|
||||
// The pre-existing route survives with the new column defaulting to false.
|
||||
final existing = await db.getRoutePlan(1);
|
||||
expect(existing, isNotNull);
|
||||
expect(existing!.isClosedLoop, isFalse);
|
||||
|
||||
// A freshly inserted route also reads back false by default.
|
||||
final newId = await db.insertRoutePlan(
|
||||
const RoutePlan(name: 'New route', createdAt: 9000),
|
||||
);
|
||||
expect((await db.getRoutePlan(newId))!.isClosedLoop, isFalse);
|
||||
|
||||
// Toggling persists.
|
||||
await db.setRoutePlanClosedLoop(1, true);
|
||||
expect((await db.getRoutePlan(1))!.isClosedLoop, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user