shortcut_grid_test.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. int count = 16,
  25. }) async {
  26. await tester.pumpWidget(
  27. MaterialApp(
  28. theme: AppTheme.light(),
  29. home: Scaffold(
  30. body: Center(
  31. child: SizedBox(
  32. width: size.width,
  33. height: size.height,
  34. child: ShortcutGrid(shortcuts: _specs(count), compact: compact),
  35. ),
  36. ),
  37. ),
  38. ),
  39. );
  40. await tester.pump();
  41. }
  42. void main() {
  43. TestWidgetsFlutterBinding.ensureInitialized();
  44. testWidgets('16 buttons fit at 1280x800 without overflow', (tester) async {
  45. await _pumpGrid(tester, size: const Size(700, 610), compact: false);
  46. expect(tester.takeException(), isNull);
  47. expect(find.byType(ShortcutTile), findsNWidgets(16));
  48. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  49. expect(first.size, lessThanOrEqualTo(196));
  50. expect(first.size, greaterThan(64));
  51. });
  52. testWidgets('16 buttons fit at the 1280x720 layout', (tester) async {
  53. await _pumpGrid(tester, size: const Size(755, 500), compact: false);
  54. expect(tester.takeException(), isNull);
  55. expect(find.byType(ShortcutTile), findsNWidgets(16));
  56. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  57. expect(first.size, lessThanOrEqualTo(196));
  58. expect(first.size, greaterThan(64));
  59. });
  60. testWidgets('16 buttons fit at the 1024x600 compact layout', (tester) async {
  61. await _pumpGrid(tester, size: const Size(559, 476), compact: true);
  62. expect(tester.takeException(), isNull);
  63. expect(find.byType(ShortcutTile), findsNWidgets(16));
  64. final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
  65. expect(first.size, lessThanOrEqualTo(168));
  66. expect(first.size, greaterThan(64));
  67. });
  68. testWidgets('a short grid is anchored to the bottom edge', (tester) async {
  69. await _pumpGrid(
  70. tester,
  71. size: const Size(600, 400),
  72. compact: false,
  73. count: 4,
  74. );
  75. expect(tester.takeException(), isNull);
  76. final grid = tester.getRect(find.byType(ShortcutGrid));
  77. final wrap = tester.getRect(find.byType(Wrap));
  78. final last = tester.getRect(find.byType(ShortcutTile).last);
  79. expect(last.bottom, moreOrLessEquals(grid.bottom, epsilon: 0.5));
  80. expect(wrap.center.dx, moreOrLessEquals(grid.center.dx, epsilon: 0.5));
  81. });
  82. testWidgets('a long Jellyfin subtitle is clipped to the tile width', (
  83. tester,
  84. ) async {
  85. await tester.binding.setSurfaceSize(const Size(1280, 400));
  86. addTearDown(() => tester.binding.setSurfaceSize(null));
  87. await tester.pumpWidget(
  88. MaterialApp(
  89. theme: AppTheme.light(),
  90. home: Scaffold(
  91. body: Center(
  92. child: ShortcutTile(
  93. title: 'Jellyfin',
  94. subtitle: 'Paradise Lost — Drown In Darkness - The Early Demos',
  95. iconAsset: 'assets/icons/headphones.svg',
  96. size: 196,
  97. assigned: true,
  98. onTap: () {},
  99. ),
  100. ),
  101. ),
  102. ),
  103. );
  104. await tester.pump();
  105. expect(tester.getSize(find.byType(ShortcutTile)).width, 196);
  106. expect(tester.takeException(), isNull);
  107. });
  108. }