Files
imagefind/mobile/test/widget_test.dart
T
2026-08-18 01:07:44 +08:00

65 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:imagefind_mobile/src/models.dart';
import 'package:imagefind_mobile/src/screens/core_screens.dart';
import 'package:imagefind_mobile/src/screens/shell.dart';
import 'package:imagefind_mobile/src/theme.dart';
void main() {
test('formats media duration', () {
expect(formatDuration(1845000), '30:45');
expect(formatDuration(3723000), '1:02:03');
});
testWidgets('selected navigation has no bubble', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: buildTheme(Brightness.light, TargetPlatform.android),
home: Scaffold(
bottomNavigationBar: NavigationBar(
selectedIndex: 0,
destinations: const [
NavigationDestination(
icon: Icon(Icons.home_outlined),
label: '首页',
),
NavigationDestination(icon: Icon(Icons.search), label: '搜索'),
],
),
),
),
);
final theme = NavigationBarTheme.of(
tester.element(find.byType(NavigationBar)),
);
expect(theme.indicatorColor, Colors.transparent);
});
testWidgets('phone shell and search fit a 390dp viewport', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
theme: buildTheme(Brightness.light, TargetPlatform.android),
home: const AppShell(index: 1, child: SearchScreen()),
),
),
);
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.byType(NavigationBar), findsOneWidget);
final field = tester.getRect(find.byType(TextField));
expect(field.left, greaterThanOrEqualTo(6));
expect(field.right, lessThan(340));
final navigation = tester.getRect(find.byType(NavigationBar));
expect(navigation.left, 0);
expect(navigation.right, 390);
});
}