Files
tatlock-ui/test/harness/screen_sizes.dart
T
Jeroen SchweitzerandClaude Opus 4.5 ea6914b5f4 test: add responsive tests to all page test files
Add shared screen size constants and configureScreenSize() helper in
test/harness/screen_sizes.dart. Add responsive test groups to all page
tests covering desktop (1920x1080), tablet landscape (1024x768), tablet
portrait (768x1024), mobile (375x812), and small mobile (320x568).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 19:45:32 +01:00

93 lines
2.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
/// Standard screen sizes for responsive testing.
abstract class ScreenSizes {
// Desktop sizes
static const desktopLarge = Size(1920, 1080);
static const desktop = Size(1440, 900);
static const desktopSmall = Size(1280, 800);
// Tablet sizes
static const tabletLandscape = Size(1024, 768);
static const tabletPortrait = Size(768, 1024);
// Mobile sizes
static const mobileLarge = Size(428, 926); // iPhone 14 Pro Max
static const mobile = Size(375, 812); // iPhone X/11/12/13
static const mobileSmall = Size(320, 568); // iPhone SE
/// All sizes for comprehensive testing.
static const all = [
desktopLarge,
desktop,
tabletLandscape,
tabletPortrait,
mobileLarge,
mobile,
];
/// Desktop-only sizes.
static const desktopSizes = [desktopLarge, desktop, desktopSmall];
/// Tablet sizes.
static const tabletSizes = [tabletLandscape, tabletPortrait];
/// Mobile sizes.
static const mobileSizes = [mobileLarge, mobile, mobileSmall];
}
/// Extension to easily set screen size in widget tests.
extension ScreenSizeExtension on WidgetTester {
/// Sets the screen size for the test.
///
/// Remember to call `addTearDown(() => view.resetPhysicalSize())` after.
void setScreenSize(Size size) {
view.physicalSize = size;
view.devicePixelRatio = 1.0;
}
/// Resets the screen size to default.
void resetScreenSize() {
view.resetPhysicalSize();
}
}
/// Configures a widget test for a specific screen size with overflow suppression.
///
/// Usage:
/// ```dart
/// testWidgets('renders on mobile', (tester) async {
/// configureScreenSize(tester, ScreenSizes.mobile);
/// // ... test code
/// });
/// ```
void configureScreenSize(WidgetTester tester, Size size) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1.0;
addTearDown(() => tester.view.resetPhysicalSize());
// Suppress overflow errors for responsive tests
final originalOnError = FlutterError.onError;
FlutterError.onError = (details) {
if (details.exceptionAsString().contains('overflowed')) {
return; // Ignore overflow errors
}
originalOnError?.call(details);
};
addTearDown(() => FlutterError.onError = originalOnError);
}
/// Returns a descriptive name for a screen size.
String screenSizeName(Size size) {
if (size == ScreenSizes.desktopLarge) return 'desktop-large';
if (size == ScreenSizes.desktop) return 'desktop';
if (size == ScreenSizes.desktopSmall) return 'desktop-small';
if (size == ScreenSizes.tabletLandscape) return 'tablet-landscape';
if (size == ScreenSizes.tabletPortrait) return 'tablet-portrait';
if (size == ScreenSizes.mobileLarge) return 'mobile-large';
if (size == ScreenSizes.mobile) return 'mobile';
if (size == ScreenSizes.mobileSmall) return 'mobile-small';
return '${size.width.toInt()}x${size.height.toInt()}';
}