import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/pipelines/pipeline_format.dart'; import 'package:pipelines_app/features/pipelines/pipeline_models.dart'; import 'package:pipelines_app/features/pipelines/pipeline_query.dart'; import 'fixtures.dart'; void main() { group('formatting', () { test('renders local timestamps, durations and ages', () { expect(formatLocalTimestamp('2026-10-17T21:26:00'), '17 Oct 21:26'); expect(formatLocalTimestamp(''), isNull); expect(formatLocalTimestamp('not a time'), isNull); expect(formatDuration(0), '0s'); expect(formatDuration(45), '45s'); expect(formatDuration(125), '2m 5s'); expect(formatDuration(3720), '1h 2m'); expect(formatDuration(-4), '0s'); expect(stageCountText(1), '1 stage'); expect(stageCountText(2), '2 stages'); final now = DateTime(2026, 10, 17, 21, 30); expect(formatRanAgo('2026-10-17T21:29:40', now), 'just now'); expect(formatRanAgo('2026-10-17T21:25:00', now), '5m ago'); expect(formatRanAgo('2026-10-17T19:30:00', now), '2h ago'); expect(formatRanAgo('2026-10-14T21:30:00', now), '3d ago'); expect(formatRanAgo('2026-10-17T22:00:00', now), 'just now'); }); test('maps the server status vocabulary and unknown values', () { expect(runStateOf('success'), 'succeeded'); expect(runStateOf('CANCELLED'), 'canceled'); expect(runStateOf('error'), 'failed'); expect(runStateOf('mystery'), 'unknown'); expect(runStateOf(null), 'unknown'); expect(runStateLabel('running'), 'Running'); }); }); group('pipeline detail', () { test('parses the get_pipeline detail and resolves latest', () { final detail = PipelineDetail.fromJson( pipelineDetail( id: 7, name: 'Seven', version: 0, latestVersion: 3, source: 'name: seven', versions: [versionSummary(1), versionSummary(2), versionSummary(3)], ), ); expect(detail.id, 7); expect(detail.latestVersion, 3); expect(detail.resolvedVersion, 3); expect(detail.source, 'name: seven'); expect(detail.versions.map((version) => version.version), [1, 2, 3]); expect(pipelineSubtitle(detail), 'id 7 · v0 · 1 stage'); expect(pipelineSummaryFields(detail).first.key, 'Content hash'); expect( pipelineSummaryFields( detail, ).firstWhere((field) => field.key == 'Latest version').value, 'v3', ); }); test( 'schedule state distinguishes configured, absent and unknown peers', () { expect( PipelineSummary.fromJson( pipelineSummary(id: 1, name: 'a', scheduleCount: 2), ).scheduleState, PipelineScheduleState.scheduled, ); expect( PipelineSummary.fromJson( pipelineSummary( id: 1, name: 'a', scheduleCount: null, scheduled: null, ), ).scheduleState, PipelineScheduleState.unclassified, ); expect( PipelineSummary.fromJson( pipelineSummary(id: 1, name: 'a'), ).scheduleLabel, '', ); }, ); }); }