import 'package:cutdex_ui/theme.dart'; import 'package:cutdex_ui/widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('active resource progress omits a redundant status suffix', ( tester, ) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( body: ResourceDownloadProgress( downloadedBytes: 7100000, totalBytes: 618000000, status: '', ), ), ), ); expect(find.text('0 B/s - 7.1 MB/618 MB'), findsOneWidget); }); testWidgets('progress displays the download speed supplied by the task', ( tester, ) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( body: ResourceDownloadProgress( downloadedBytes: 7100000, totalBytes: 618000000, bytesPerSecond: 1200000, status: '', ), ), ), ); expect(find.text('1.2 MB/s - 7.1 MB/618 MB'), findsOneWidget); }); testWidgets('resource download shows byte progress above a thin track', ( tester, ) async { await tester.pumpWidget( MaterialApp( theme: AppTheme.penDark, home: const Scaffold( body: SizedBox( width: 300, child: ResourceDownloadProgress( downloadedBytes: 7100000, totalBytes: 618000000, status: '已暂停', paused: true, ), ), ), ), ); final label = find.text('7.1 MB/618 MB, 已暂停'); final bar = find.byType(LinearProgressIndicator); expect(label, findsOneWidget); expect(tester.getRect(label).bottom, lessThan(tester.getRect(bar).top)); final indicator = tester.widget(bar); expect(indicator.value, closeTo(7.1 / 618, 0.00001)); expect(indicator.minHeight, 3); expect(indicator.backgroundColor, AppTheme.penDark.dividerColor); }); }