Files
alan bb2adcc182 Add an interface size setting (0.5x to 2x)
Settings > Appearance > Interface size scales every dimension, text, icon
and dialog on this device. The app lays out in a smaller or larger viewport
and paints it scaled to the window, so hit testing and layout stay
consistent; the value is saved per device and applies when the slider is
released.
2026-11-09 12:56:42 +00:00

109 lines
3.3 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_scale_section.dart';
import 'package:pipelines_app/ui/scale/ui_scale.dart';
class _Store implements UiScaleStore {
double? saved;
double? stored;
@override
Future<double?> load() async => stored;
@override
Future<bool> save(double scale) async {
saved = scale;
return true;
}
}
void main() {
test('restores, clamps and saves the scale', () async {
final store = _Store()..stored = 3;
final controller = UiScaleController(store: store);
await controller.restore();
expect(controller.scale, maxUiScale);
controller.setScale(0.1);
expect(controller.scale, minUiScale);
await controller.save();
expect(store.saved, minUiScale);
await controller.reset();
expect(controller.scale, 1);
expect(store.saved, 1);
});
testWidgets('the host lays out smaller and paints scaled to fill', (
tester,
) async {
tester.view.physicalSize = const Size(800, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final controller = UiScaleController(store: _Store());
Size? seen;
var taps = 0;
await tester.pumpWidget(
MaterialApp(
builder: (context, child) =>
UiScaleHost(controller: controller, child: child!),
home: Builder(
builder: (context) {
seen = MediaQuery.sizeOf(context);
return Align(
alignment: Alignment.topLeft,
child: GestureDetector(
onTap: () => taps++,
behavior: HitTestBehavior.opaque,
child: const SizedBox(key: Key('box'), width: 100, height: 100),
),
);
},
),
),
);
expect(seen, const Size(800, 600));
controller.setScale(2);
await tester.pump();
expect(seen, const Size(400, 300));
// The 100×100 box now covers 200×200 window pixels and is tappable there.
final rect = tester.getRect(find.byKey(const Key('box')));
expect(rect.size, const Size(200, 200));
await tester.tapAt(const Offset(180, 180));
expect(taps, 1);
controller.setScale(0.5);
await tester.pump();
expect(seen, const Size(1600, 1200));
expect(
tester.getRect(find.byKey(const Key('box'))).size,
const Size(50, 50),
);
});
testWidgets('the settings slider applies when the drag ends', (tester) async {
final store = _Store();
final controller = UiScaleController(store: store);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: SettingsScaleSection(controller: controller),
),
),
),
);
expect(find.text('1.0×'), findsOneWidget);
final slider = tester.widget<Slider>(
find.byKey(const Key('settings-ui-scale')),
);
slider.onChanged!(1.5);
await tester.pump();
expect(find.text('1.5×'), findsOneWidget);
expect(controller.scale, 1, reason: 'dragging only previews');
slider.onChangeEnd!(1.5);
await tester.pump();
expect(controller.scale, 1.5);
await tester.pump();
expect(store.saved, 1.5);
await tester.tap(find.text('Reset'));
await tester.pump();
expect(controller.scale, 1);
});
}