import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/app_route.dart'; void main() { test('parses each destination and a run detail', () { expect(AppRoute.parse('/pipelines'), AppRoute.pipelines); expect(AppRoute.parse('/runs'), AppRoute.runs); expect(AppRoute.parse('/runs/12'), AppRoute.run(12)); expect(AppRoute.parse('/chat'), AppRoute.chat); expect( AppRoute.parse('/chat/abc_DEF-123'), AppRoute.chatSession('abc_DEF-123'), ); expect(AppRoute.parse('/settings'), AppRoute.settings); }); test('normalises slashes and accepts a full URL, query and fragment', () { expect(AppRoute.parse('/runs/'), AppRoute.runs); expect(AppRoute.parse('/pipelines///'), AppRoute.pipelines); expect( AppRoute.parse('http://127.0.0.1:8096/runs/7?action=decide#top'), AppRoute.run(7), ); expect(AppRoute.parse('/runs/7/'), AppRoute.run(7)); expect( AppRoute.parse('/chat/session/?x=1'), AppRoute.chatSession('session'), ); expect( AppRoute.parse('/chat/probe%2Dchat'), AppRoute.chatSession('probe-chat'), ); }); test('a malformed or unknown location is the default Pipelines route', () { for (final path in [ '', '/', '/runs/abc', '/runs/0', '/runs/-1', '/runs/1/extra', '/pipelines/2', '/chat/a/b', '/chat/%2F', '/chat/${'x' * 201}', '/unknown', '/runs/%E0%A4%A', ]) { expect(AppRoute.parse(path), AppRoute.pipelines, reason: path); } }); test('serialises every route back to a parsable path', () { for (final route in [ AppRoute.pipelines, AppRoute.runs, AppRoute.run(3), AppRoute.chat, AppRoute.chatSession('probe_open-1'), AppRoute.settings, ]) { expect(AppRoute.parse(route.path), route); } expect(AppRoute.run(3).path, '/runs/3'); expect(AppRoute.chatSession('probe_open-1').path, '/chat/probe_open-1'); expect(AppRoute.chatSession('bad id').path, '/chat'); }); }