shortcut_grid_test.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:cardash_launcher/core/theme/app_theme.dart';
  2. import 'package:cardash_launcher/features/home/widgets/shortcut_grid.dart';
  3. import 'package:cardash_launcher/features/home/widgets/shortcut_tile.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_test/flutter_test.dart';
  6. List<ShortcutSpec> _specs(int count) {
  7. return List.generate(
  8. count,
  9. (index) => ShortcutSpec(
  10. title: 'App $index',
  11. subtitle: index < 5 ? 'Select app' : null,
  12. iconAsset: 'assets/icons/app-window.svg',
  13. assigned: true,
  14. onTap: () {},
  15. onLongPress: () {},
  16. longPressHint: 'remove from Home',
  17. ),
  18. );
  19. }
  20. Future<void> _pumpGrid(
  21. WidgetTester tester, {
  22. required Size size,
  23. required bool compact,
  24. }) async {
  25. await tester.pumpWidget(
  26. MaterialApp(
  27. theme: AppTheme.light(),
  28. home: Scaffold(
  29. body: Center(
  30. child: SizedBox(
  31. width: size.width,
  32. height: size.height,
  33. child: ShortcutGrid(shortcuts: _specs(16), compact: compact),
  34. ),
  35. ),
  36. ),
  37. ),
  38. );
  39. await tester.pump();
  40. }
  41. void main() {
  42. TestWidgetsFlutterBinding.ensureInitialized();
  43. testWidgets('16 buttons fit at 1280x800 without overflow', (tester) async {
  44. await _pumpGrid(tester, size: const Size(700, 610), compact: false);
  45. expect(tester.takeException(), isNull);
  46. expect(find.byType(ShortcutTile), findsNWidgets(16));
  47. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  48. expect(first.size, lessThanOrEqualTo(196));
  49. expect(first.size, greaterThan(64));
  50. });
  51. testWidgets('16 buttons fit at the 1280x720 layout', (tester) async {
  52. await _pumpGrid(tester, size: const Size(755, 500), compact: false);
  53. expect(tester.takeException(), isNull);
  54. expect(find.byType(ShortcutTile), findsNWidgets(16));
  55. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  56. expect(first.size, lessThanOrEqualTo(196));
  57. expect(first.size, greaterThan(64));
  58. });
  59. testWidgets('16 buttons fit at the 1024x600 compact layout', (tester) async {
  60. await _pumpGrid(tester, size: const Size(559, 476), compact: true);
  61. expect(tester.takeException(), isNull);
  62. expect(find.byType(ShortcutTile), findsNWidgets(16));
  63. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  64. expect(first.size, lessThanOrEqualTo(168));
  65. expect(first.size, greaterThan(64));
  66. });
  67. }