feat(app): parse and emit the web client's route vocabulary
Widen AppRoute to the pipeline detail, definition stage pane, runs filter, run stage pane, decision prompt and template detail the web client already addresses, and canonicalise the /settings/templates aliases. The URL codec moves to app_route_codec.dart as a part file to keep the route model and the parser under the app's 250-line aim.
This commit is contained in:
@@ -2,10 +2,28 @@ 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', () {
|
||||
test('parses each destination, detail and stage pane', () {
|
||||
expect(AppRoute.parse('/pipelines'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/pipelines/5'), AppRoute.pipeline(5));
|
||||
expect(AppRoute.parse('/pipelines/5/7'), AppRoute.pipeline(5, version: 7));
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/7/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build', version: 7),
|
||||
);
|
||||
expect(AppRoute.parse('/runs'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs/12'), AppRoute.run(12));
|
||||
expect(
|
||||
AppRoute.parse('/runs/12/stage/build'),
|
||||
AppRoute.run.stage(12, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/12/stage/build?visit=3'),
|
||||
AppRoute.run.stage(12, 'build', visit: 3),
|
||||
);
|
||||
expect(AppRoute.parse('/chat'), AppRoute.chat);
|
||||
expect(
|
||||
AppRoute.parse('/chat/abc_DEF-123'),
|
||||
@@ -14,6 +32,94 @@ void main() {
|
||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||
expect(AppRoute.parse('/settings'), AppRoute.settings);
|
||||
expect(AppRoute.parse('/templates'), AppRoute.templates);
|
||||
expect(AppRoute.parse('/templates/release'), AppRoute.template('release'));
|
||||
});
|
||||
|
||||
test('version before stage: /stage/ is a pane key, not a version', () {
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/9/stage/7'),
|
||||
AppRoute.pipelineStage(9, '7'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/9/7/stage/7'),
|
||||
AppRoute.pipelineStage(9, '7', version: 7),
|
||||
);
|
||||
});
|
||||
|
||||
test('version 0 means latest and is omitted from the path', () {
|
||||
expect(AppRoute.parse('/pipelines/5/0'), AppRoute.pipeline(5));
|
||||
expect(AppRoute.parse('/pipelines/5/0').path, '/pipelines/5');
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/0/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(AppRoute.pipeline(5, version: 0).path, '/pipelines/5');
|
||||
expect(AppRoute.pipeline(5, version: -1).path, '/pipelines/5');
|
||||
});
|
||||
|
||||
test('template aliases resolve to the canonical template route', () {
|
||||
expect(AppRoute.parse('/settings/templates'), AppRoute.templates);
|
||||
expect(
|
||||
AppRoute.parse('/settings/templates/release'),
|
||||
AppRoute.template('release'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/settings/templates/release').path,
|
||||
'/templates/release',
|
||||
);
|
||||
expect(AppRoute.parse('/settings/templates/a/b'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/settings/other'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/templates/a/b'), AppRoute.pipelines);
|
||||
});
|
||||
|
||||
test('runs list pipeline filter and run action are parsed', () {
|
||||
expect(AppRoute.parse('/runs?pipeline=7'), AppRoute.runsForPipeline(7));
|
||||
expect(AppRoute.parse('/runs?pipeline=7').path, '/runs?pipeline=7');
|
||||
expect(AppRoute.parse('/runs?pipeline=0'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs?pipeline=abc'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs/5?action=decide'), AppRoute.run.decide(5));
|
||||
expect(AppRoute.run.decide(5).path, '/runs/5?action=decide');
|
||||
expect(AppRoute.parse('/runs/5?action='), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?action=retry'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?action=retry').path, '/runs/5');
|
||||
});
|
||||
|
||||
test('unknown query parameters are ignored and invalid values dropped', () {
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=-1'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=1.5'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=abc'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=0&x=1'),
|
||||
AppRoute.run.stage(5, 'build', visit: 0),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=99999999999999999999'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?action=decide'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(AppRoute.parse('/runs/5?pipeline=7'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?x=1'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?x=%E0%A4%A'), AppRoute.run(5));
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/stage/build?visit=2'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/templates/release?x=1'),
|
||||
AppRoute.template('release'),
|
||||
);
|
||||
});
|
||||
|
||||
test('normalises slashes and accepts a full URL, query and fragment', () {
|
||||
@@ -22,7 +128,11 @@ void main() {
|
||||
expect(AppRoute.parse('/templates/'), AppRoute.templates);
|
||||
expect(
|
||||
AppRoute.parse('http://127.0.0.1:8096/runs/7?action=decide#top'),
|
||||
AppRoute.run(7),
|
||||
AppRoute.run.decide(7),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('https://example.test/runs/7/stage/build?visit=2#top'),
|
||||
AppRoute.run.stage(7, 'build', visit: 2),
|
||||
);
|
||||
expect(AppRoute.parse('/runs/7/'), AppRoute.run(7));
|
||||
expect(
|
||||
@@ -43,9 +153,20 @@ void main() {
|
||||
'/runs/0',
|
||||
'/runs/-1',
|
||||
'/runs/1/extra',
|
||||
'/pipelines/2',
|
||||
'/runs/5/stage',
|
||||
'/runs/5/stage/a/b',
|
||||
'/runs/5/stage/',
|
||||
'/pipelines/0',
|
||||
'/pipelines/abc',
|
||||
'/pipelines/5/abc',
|
||||
'/pipelines/5/-1',
|
||||
'/pipelines/5/stage',
|
||||
'/pipelines/5/stage/a/b',
|
||||
'/pipelines/5/1/2',
|
||||
'/search/1',
|
||||
'/templates/release',
|
||||
'/runs/9007199254740992',
|
||||
'/pipelines/9007199254740992',
|
||||
'/templates/a/b',
|
||||
'/chat/a/b',
|
||||
'/chat/%2F',
|
||||
'/chat/${'x' * 201}',
|
||||
@@ -59,19 +180,70 @@ void main() {
|
||||
test('serialises every route back to a parsable path', () {
|
||||
for (final route in [
|
||||
AppRoute.pipelines,
|
||||
AppRoute.pipeline(5),
|
||||
AppRoute.pipeline(5, version: 2),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
AppRoute.pipelineStage(5, 'build', version: 2),
|
||||
AppRoute.pipelineStage(5, 'a/b'),
|
||||
AppRoute.runs,
|
||||
AppRoute.runsForPipeline(7),
|
||||
AppRoute.run(3),
|
||||
AppRoute.run.decide(3),
|
||||
AppRoute.run.stage(3, 'build'),
|
||||
AppRoute.run.stage(3, 'build', visit: 0),
|
||||
AppRoute.run.stage(3, 'build', visit: 4),
|
||||
AppRoute.chat,
|
||||
AppRoute.chatSession('probe_open-1'),
|
||||
AppRoute.search,
|
||||
AppRoute.settings,
|
||||
AppRoute.templates,
|
||||
AppRoute.template('release'),
|
||||
AppRoute.template('release notes'),
|
||||
AppRoute.template('café'),
|
||||
AppRoute.pipelineStage(5, 'build ✓'),
|
||||
]) {
|
||||
expect(AppRoute.parse(route.path), route);
|
||||
expect(AppRoute.parse(route.path), route, reason: route.path);
|
||||
}
|
||||
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');
|
||||
expect(AppRoute.templates.path, '/templates');
|
||||
});
|
||||
|
||||
test('canonical paths for the extended vocabulary', () {
|
||||
expect(AppRoute.pipeline(5).path, '/pipelines/5');
|
||||
expect(AppRoute.pipeline(5, version: 2).path, '/pipelines/5/2');
|
||||
expect(AppRoute.pipelineStage(5, 'build').path, '/pipelines/5/stage/build');
|
||||
expect(
|
||||
AppRoute.pipelineStage(5, 'build', version: 2).path,
|
||||
'/pipelines/5/2/stage/build',
|
||||
);
|
||||
expect(
|
||||
AppRoute.pipelineStage(5, 'release notes').path,
|
||||
'/pipelines/5/stage/release%20notes',
|
||||
);
|
||||
expect(AppRoute.runsForPipeline(7).path, '/runs?pipeline=7');
|
||||
expect(AppRoute.run.decide(3).path, '/runs/3?action=decide');
|
||||
expect(
|
||||
AppRoute.run.stage(3, 'build', visit: 2).path,
|
||||
'/runs/3/stage/build?visit=2',
|
||||
);
|
||||
expect(AppRoute.run.stage(3, 'build').path, '/runs/3/stage/build');
|
||||
expect(AppRoute.template('release').path, '/templates/release');
|
||||
expect(AppRoute.template('').path, '/templates');
|
||||
});
|
||||
|
||||
test('invalid ids never serialise outside the vocabulary', () {
|
||||
expect(AppRoute.pipeline(0), AppRoute.pipelines);
|
||||
expect(AppRoute.pipeline(-1), AppRoute.pipelines);
|
||||
expect(AppRoute.pipelineStage(0, 'build'), AppRoute.pipelines);
|
||||
expect(AppRoute.pipelineStage(5, ''), AppRoute.pipelines);
|
||||
expect(AppRoute.runsForPipeline(0), AppRoute.runs);
|
||||
expect(AppRoute.run(0), AppRoute.runs);
|
||||
expect(AppRoute.run.stage(0, 'build'), AppRoute.runs);
|
||||
expect(AppRoute.run.stage(3, ''), AppRoute.runs);
|
||||
expect(AppRoute.run.decide(0), AppRoute.runs);
|
||||
expect(AppRoute(AppRouteKind.pipelines, pipelineId: 0).path, '/pipelines');
|
||||
expect(AppRoute(AppRouteKind.runs, runId: 0).path, '/runs');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user