| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import 'package:cardash_launcher/core/theme/app_theme.dart';
- import 'package:cardash_launcher/features/home/widgets/shortcut_grid.dart';
- import 'package:cardash_launcher/features/home/widgets/shortcut_tile.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_test/flutter_test.dart';
- List<ShortcutSpec> _specs(int count) {
- return List.generate(
- count,
- (index) => ShortcutSpec(
- title: 'App $index',
- subtitle: index < 5 ? 'Select app' : null,
- iconAsset: 'assets/icons/app-window.svg',
- assigned: true,
- onTap: () {},
- onLongPress: () {},
- longPressHint: 'remove from Home',
- ),
- );
- }
- Future<void> _pumpGrid(
- WidgetTester tester, {
- required Size size,
- required bool compact,
- int count = 16,
- }) async {
- await tester.pumpWidget(
- MaterialApp(
- theme: AppTheme.light(),
- home: Scaffold(
- body: Center(
- child: SizedBox(
- width: size.width,
- height: size.height,
- child: ShortcutGrid(shortcuts: _specs(count), compact: compact),
- ),
- ),
- ),
- ),
- );
- await tester.pump();
- }
- void main() {
- TestWidgetsFlutterBinding.ensureInitialized();
- testWidgets('16 buttons fit at 1280x800 without overflow', (tester) async {
- await _pumpGrid(tester, size: const Size(700, 610), compact: false);
- expect(tester.takeException(), isNull);
- expect(find.byType(ShortcutTile), findsNWidgets(16));
- final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
- expect(first.size, lessThanOrEqualTo(196));
- expect(first.size, greaterThan(64));
- });
- testWidgets('16 buttons fit at the 1280x720 layout', (tester) async {
- await _pumpGrid(tester, size: const Size(755, 500), compact: false);
- expect(tester.takeException(), isNull);
- expect(find.byType(ShortcutTile), findsNWidgets(16));
- final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
- expect(first.size, lessThanOrEqualTo(196));
- expect(first.size, greaterThan(64));
- });
- testWidgets('16 buttons fit at the 1024x600 compact layout', (tester) async {
- await _pumpGrid(tester, size: const Size(559, 476), compact: true);
- expect(tester.takeException(), isNull);
- expect(find.byType(ShortcutTile), findsNWidgets(16));
- final first = tester.widget<ShortcutTile>(find.byType(ShortcutTile).first);
- expect(first.size, lessThanOrEqualTo(168));
- expect(first.size, greaterThan(64));
- });
- testWidgets('a short grid is anchored to the bottom edge', (tester) async {
- await _pumpGrid(
- tester,
- size: const Size(600, 400),
- compact: false,
- count: 4,
- );
- expect(tester.takeException(), isNull);
- final grid = tester.getRect(find.byType(ShortcutGrid));
- final wrap = tester.getRect(find.byType(Wrap));
- final last = tester.getRect(find.byType(ShortcutTile).last);
- expect(last.bottom, moreOrLessEquals(grid.bottom, epsilon: 0.5));
- expect(wrap.center.dx, moreOrLessEquals(grid.center.dx, epsilon: 0.5));
- });
- }
|