import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/runs/domain/check_step_output.dart'; void main() { test('a check output reads each command result', () { final output = checkStepOutput({ 'markdown': '# outcome\n\nfail\n', 'summary': '1 of 2 checks failed: go test ./...', 'delivery': true, 'checks': [ { 'command': 'go vet ./...', 'status': 'passed', 'exit_code': 0, 'duration_ms': 2100, 'output': '', 'truncated': false, }, { 'command': 'go test ./...', 'status': 'failed', 'exit_code': 1, 'duration_ms': 51000, 'output': '--- FAIL', 'truncated': true, }, {'command': 'make lint', 'status': 'not_run'}, 'not a map', ], })!; expect(output.delivery, isTrue); expect(output.summary, '1 of 2 checks failed: go test ./...'); expect(output.markdown, startsWith('# outcome')); expect(output.checks, hasLength(3)); final [vet, test, lint] = output.checks; expect(vet.status, CheckCommandStatus.passed); expect(vet.meta, 'exit 0 · 2.1s'); expect(test.status, CheckCommandStatus.failed); expect(test.meta, 'exit 1 · 51s'); expect(test.truncated, isTrue); expect(lint.status, CheckCommandStatus.notRun); expect(lint.meta, ''); expect(checkStatusLabel(lint), 'Not run'); }); test('statuses this client does not know keep their own word', () { final output = checkStepOutput({ 'checks': [ {'command': 'x', 'status': 'skipped_by_policy'}, {'command': 'y'}, {'command': 'z', 'status': 'timed_out'}, ], })!; expect(output.checks[0].status, CheckCommandStatus.unknown); expect(checkStatusLabel(output.checks[0]), 'skipped_by_policy'); expect(checkStatusLabel(output.checks[1]), 'Unknown status'); expect(checkStatusLabel(output.checks[2]), 'Timed out'); expect(output.delivery, isFalse); }); test('outputs without a checks list are not check outputs', () { expect(checkStepOutput(null), isNull); expect(checkStepOutput('text'), isNull); expect(checkStepOutput({'markdown': '# outcome'}), isNull); expect(checkStepOutput({'checks': 'go test'}), isNull); }); test('durations read compactly', () { expect(formatCheckDuration(850), '850ms'); expect(formatCheckDuration(2000), '2s'); expect(formatCheckDuration(2100), '2.1s'); expect(formatCheckDuration(51000), '51s'); expect(formatCheckDuration(185000), '3m 05s'); expect(formatCheckDuration(3720000), '1h 02m'); }); }