import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/search/domain/search_row.dart'; JsonMap pipelineHit([JsonMap overrides = const {}]) => { 'kind': 'pipeline', 'target': 'pipeline:7', 'pipeline': { 'id': 7, 'name': 'release', 'version': 3, 'stages': 4, ...overrides, }, }; JsonMap versionHit() => { 'kind': 'version', 'target': 'pipeline:9:v2', 'recency': '2026-01-01T00:00:00Z', 'version': { 'pipeline_id': 9, 'version': 2, 'content_hash': 'abc', 'created_at': '2026-01-01T00:00:00Z', }, }; JsonMap runHit([JsonMap overrides = const {}]) => { 'kind': 'run', 'target': 'run:11', 'run': { 'id': 11, 'pipeline_name': 'release', 'status': 'succeeded', 'created_at': '2026-01-01T00:00:00Z', ...overrides, }, }; JsonMap stepHit([JsonMap overrides = const {}]) => { 'kind': 'step', 'target': 'run:11:4', 'step': { 'run_id': 11, 'sequence': 4, 'stage': 'builder', 'visit': 2, 'outcome': 'success', ...overrides, }, }; JsonMap fieldHit([JsonMap overrides = const {}]) => { 'kind': 'field', 'target': 'run:11:4:output', 'matched_field': 'output', 'field': { 'run_id': 11, 'sequence': 4, 'field': 'output', 'snippet': 'the release is ready', ...overrides, }, }; JsonMap artifactHit([JsonMap overrides = const {}]) => { 'kind': 'artifact', 'target': '/artifacts/11/4/notes.md', 'artifact': { 'run_id': 11, 'sequence': 4, 'name': 'notes.md', 'content_type': 'text/markdown', 'size_bytes': 2048, ...overrides, }, }; void main() { test('per-kind rows mirror the browser titles and secondary lines', () { final pipeline = searchRowView(pipelineHit(), 'release'); expect(pipeline.title, 'release'); expect(pipeline.secondary, 'pipeline 7 · v3 · 4 stages'); expect(pipeline.kindLabel, 'Pipeline'); expect(pipeline.target, 'pipeline:7'); final blankName = searchRowView(pipelineHit({'name': ' '}), 'x'); expect(blankName.title, 'pipeline 7'); final version = searchRowView(versionHit(), 'release'); expect(version.title, 'pipeline 9 · v2'); expect(version.secondary, startsWith('content abc · ')); expect(version.recency, isNotNull); final run = searchRowView(runHit(), 'release'); expect(run.title, 'run #11 · release'); expect(run.secondary, startsWith('succeeded · ')); expect(run.secondary.split(' · '), hasLength(2)); final unnamed = searchRowView(runHit({'pipeline_name': ''}), ''); expect(unnamed.title, 'run #11'); final step = searchRowView(stepHit({'target': '#success'}), ''); expect(step.title, 'run #11 · builder visit 2'); expect(step.secondary, 'success · → #success'); final artifact = searchRowView(artifactHit(), 'notes'); expect(artifact.title, 'notes.md'); expect(artifact.secondary, 'run #11 · step 4 · text/markdown · 2.0 KiB'); }); test('a field snippet marks the first case-insensitive query occurrence', () { final row = searchRowView(fieldHit(), 'RELEASE'); expect(row.snippet, 'the release is ready'); expect(row.snippetSpans.map((span) => (span.text, span.matched)), [ ('the ', false), ('release', true), (' is ready', false), ]); expect(row.snippetSpans.where((span) => span.matched), hasLength(1)); final absent = searchRowView(fieldHit({'snippet': 'no match'}), 'absent'); expect(absent.snippetSpans.single.matched, isFalse); expect(absent.snippetSpans.single.text, 'no match'); final blank = searchRowView(fieldHit({'snippet': ''}), 'release'); expect(blank.snippetSpans, isEmpty); }); test('unknown or targetless hits are read-only and never open a guess', () { final unknown = searchRowView({ 'kind': 'future_kind', 'target': 'widget:7', }, 'x'); expect(unknown.title, 'widget:7'); expect(unknown.secondary, 'kind "future_kind" · read-only'); expect(unknown.openable, isFalse); expect(unknown.target, isNull); expect(unknown.kindLabel, 'Unrecognised result'); final targetless = searchRowView({ 'kind': 'run', 'run': {'id': 11}, }, 'x'); expect(targetless.openable, isFalse); expect(targetless.target, isNull); expect(searchRowView(pipelineHit(), '').openable, isTrue); expect(searchRowView(versionHit(), '').openable, isTrue); expect(searchRowView(artifactHit(), '').openable, isTrue); }); test('byte sizes use the shared binary rendering', () { expect(humanBytes(0), '0 B'); expect(humanBytes(1023), '1023 B'); expect(humanBytes(1024), '1.0 KiB'); expect(humanBytes(2048), '2.0 KiB'); expect(humanBytes(1048576), '1.0 MiB'); }); }