From 480a8bdd82d325b23010ad90c5ea306e7f35ab6c Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 14 Aug 2026 23:10:43 +0200 Subject: [PATCH] Stop const-folding EmptyState's constructor out of coverage Removing the action slot made the constructor const-invocable, so the test's `const EmptyState(...)` was evaluated at compile time and the constructor line never executed -- 99%, caught by the pre-push gate rather than by review, which is the point of having it. Building the message through a helper keeps the invocation non-const. That is also closer to real call sites, which interpolate runtime state into the string rather than passing a literal. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01XS1m7b1piBtAL22USLW6jL --- design_system/test/empty_state_test.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/design_system/test/empty_state_test.dart b/design_system/test/empty_state_test.dart index f522674..08c90a9 100644 --- a/design_system/test/empty_state_test.dart +++ b/design_system/test/empty_state_test.dart @@ -2,15 +2,21 @@ import 'package:design_system/design_system.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +/// Built at runtime rather than inlined as a literal, so the `EmptyState` +/// below cannot be const-folded: a const invocation is evaluated at compile +/// time, so the constructor never executes and coverage silently drops. +/// Real call sites interpolate runtime state into these strings anyway. +String _message(int count) => 'Add your first item to get started ($count).'; + Future _pumpEmptyState(WidgetTester tester) { return tester.pumpWidget( MaterialApp( theme: buildDarkTheme(), - home: const Scaffold( + home: Scaffold( body: EmptyState( icon: Icons.inbox_outlined, title: 'Nothing here yet', - message: 'Add your first item to get started.', + message: _message(0), ), ), ), @@ -22,7 +28,7 @@ void main() { await _pumpEmptyState(tester); expect(find.byIcon(Icons.inbox_outlined), findsOneWidget); expect(find.text('Nothing here yet'), findsOneWidget); - expect(find.text('Add your first item to get started.'), findsOneWidget); + expect(find.text(_message(0)), findsOneWidget); }); testWidgets('draws the icon at the shared size in the muted color', ( @@ -39,7 +45,7 @@ void main() { final scheme = buildDarkTheme().colorScheme; final message = tester.widget( - find.text('Add your first item to get started.'), + find.text(_message(0)), ); expect(message.style?.color, scheme.onSurfaceVariant); expect(message.textAlign, TextAlign.center);