| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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,
- }) async {
- await tester.pumpWidget(
- MaterialApp(
- theme: AppTheme.light(),
- home: Scaffold(
- body: Center(
- child: SizedBox(
- width: size.width,
- height: size.height,
- child: ShortcutGrid(shortcuts: _specs(16), 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));
- });
- }
|