mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-22 18:52:29 +01:00
Stop const-folding EmptyState's constructor out of coverage
Some checks failed
design_system tests / test (push) Has been cancelled
Some checks failed
design_system tests / test (push) Has been cancelled
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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XS1m7b1piBtAL22USLW6jL
This commit is contained in:
parent
3dab75fde5
commit
480a8bdd82
@ -2,15 +2,21 @@ import 'package:design_system/design_system.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.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<void> _pumpEmptyState(WidgetTester tester) {
|
Future<void> _pumpEmptyState(WidgetTester tester) {
|
||||||
return tester.pumpWidget(
|
return tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
theme: buildDarkTheme(),
|
theme: buildDarkTheme(),
|
||||||
home: const Scaffold(
|
home: Scaffold(
|
||||||
body: EmptyState(
|
body: EmptyState(
|
||||||
icon: Icons.inbox_outlined,
|
icon: Icons.inbox_outlined,
|
||||||
title: 'Nothing here yet',
|
title: 'Nothing here yet',
|
||||||
message: 'Add your first item to get started.',
|
message: _message(0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -22,7 +28,7 @@ void main() {
|
|||||||
await _pumpEmptyState(tester);
|
await _pumpEmptyState(tester);
|
||||||
expect(find.byIcon(Icons.inbox_outlined), findsOneWidget);
|
expect(find.byIcon(Icons.inbox_outlined), findsOneWidget);
|
||||||
expect(find.text('Nothing here yet'), 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', (
|
testWidgets('draws the icon at the shared size in the muted color', (
|
||||||
@ -39,7 +45,7 @@ void main() {
|
|||||||
final scheme = buildDarkTheme().colorScheme;
|
final scheme = buildDarkTheme().colorScheme;
|
||||||
|
|
||||||
final message = tester.widget<Text>(
|
final message = tester.widget<Text>(
|
||||||
find.text('Add your first item to get started.'),
|
find.text(_message(0)),
|
||||||
);
|
);
|
||||||
expect(message.style?.color, scheme.onSurfaceVariant);
|
expect(message.style?.color, scheme.onSurfaceVariant);
|
||||||
expect(message.textAlign, TextAlign.center);
|
expect(message.textAlign, TextAlign.center);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user