fixed client-reported crashes in the pdf viewer, image picker and prosemirror images, mapped webdav errors to user messages and hardened keychain, cache and push stores against io failures
This commit is contained in:
1 parent
c5592f117b
commit
23e4510bf8
19 files changed
+545
-55
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:marianum_mobile/widget/prosemirror/pm_image_view.dart';
|
||||
|
||||
void main() {
|
||||
group('resolvePmImageWidth', () {
|
||||
test('returns null without a width attribute', () {
|
||||
expect(resolvePmImageWidth(null, 300), isNull);
|
||||
});
|
||||
|
||||
test('returns null for unparseable widths', () {
|
||||
expect(resolvePmImageWidth('auto', 300), isNull);
|
||||
});
|
||||
|
||||
test('resolves px, %, em and rem', () {
|
||||
expect(resolvePmImageWidth('120px', 300), 120);
|
||||
expect(resolvePmImageWidth('50%', 300), 150);
|
||||
expect(resolvePmImageWidth('2em', 300), 32);
|
||||
expect(resolvePmImageWidth('2rem', 300), 32);
|
||||
});
|
||||
|
||||
test('caps at the available width and floors at one pixel', () {
|
||||
expect(resolvePmImageWidth('900px', 300), 300);
|
||||
expect(resolvePmImageWidth('0px', 300), 1);
|
||||
});
|
||||
|
||||
test('survives zero or sub-pixel available width', () {
|
||||
expect(resolvePmImageWidth('50%', 0), isNull);
|
||||
expect(resolvePmImageWidth('120px', 0.5), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -11,7 +11,12 @@ void main() {
|
||||
Widget gatedPage() => Scaffold(
|
||||
body: RouteTransitionGate(
|
||||
placeholder: const SizedBox(key: placeholder),
|
||||
builder: (_) => const SizedBox(key: gated),
|
||||
// Hit-testable like the real viewer, so pointer tracking sees it.
|
||||
builder: (_) => const ColoredBox(
|
||||
key: gated,
|
||||
color: Color(0x00000000),
|
||||
child: SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -29,7 +34,9 @@ void main() {
|
||||
) async {
|
||||
await pumpApp(tester);
|
||||
unawaited(
|
||||
navigator(tester).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
@@ -45,7 +52,9 @@ void main() {
|
||||
testWidgets('swaps back to placeholder while the route pops', (tester) async {
|
||||
await pumpApp(tester);
|
||||
unawaited(
|
||||
navigator(tester).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
@@ -63,13 +72,17 @@ void main() {
|
||||
) async {
|
||||
await pumpApp(tester);
|
||||
unawaited(
|
||||
navigator(tester).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
|
||||
unawaited(
|
||||
navigator(tester).push(MaterialPageRoute<void>(builder: (_) => const Scaffold())),
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => const Scaffold())),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
@@ -84,6 +97,86 @@ void main() {
|
||||
expect(find.byKey(placeholder), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('re-gates when the settled subtree moves under a fresh Transform', (
|
||||
tester,
|
||||
) async {
|
||||
// Android's predictive back moves the route content (GlobalKey) under a
|
||||
// brand-new Transform.scale without any animation status change. The
|
||||
// padding changes the constraints so the moved subtree is laid out nested
|
||||
// under the transform's first layout, which is when `localToGlobal` throws.
|
||||
final subtree = GlobalKey();
|
||||
var wrapped = false;
|
||||
late StateSetter rebuild;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
rebuild = setState;
|
||||
final child = KeyedSubtree(
|
||||
key: subtree,
|
||||
child: Scaffold(
|
||||
body: RouteTransitionGate(
|
||||
placeholder: const SizedBox(key: placeholder),
|
||||
builder: (_) => const _LocalToGlobalProbe(key: gated),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!wrapped) return child;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(1),
|
||||
child: Transform.scale(scale: 1, child: child),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
|
||||
rebuild(() => wrapped = true);
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(placeholder), findsOneWidget);
|
||||
|
||||
await tester.pump();
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('keeps the child mounted while a back swipe drives the pop', (
|
||||
tester,
|
||||
) async {
|
||||
// iOS back swipe: the edge detector is translucent, so the finger that
|
||||
// drives the pop animation is also down on the viewer. Unmounting it now
|
||||
// would route the next pointer move into a disposed State. (A programmatic
|
||||
// pop is harmless — the Navigator cancels active pointers first.)
|
||||
await pumpApp(tester);
|
||||
unawaited(
|
||||
navigator(
|
||||
tester,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => gatedPage())),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(5, 300));
|
||||
await gesture.moveBy(const Offset(60, 0));
|
||||
await tester.pump();
|
||||
await gesture.moveBy(const Offset(60, 0));
|
||||
await tester.pump();
|
||||
// Pop animation is running (status reverse), finger still down.
|
||||
expect(find.byKey(gated), findsOneWidget);
|
||||
expect(find.byKey(placeholder), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
expect(find.byKey(gated), findsNothing);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
|
||||
|
||||
testWidgets('holds the child back for one frame without a route animation', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -99,3 +192,25 @@ void main() {
|
||||
expect(find.byKey(placeholder), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
/// Mimics SfPdfViewer: a stateful widget whose LayoutBuilder resolves a
|
||||
/// child's global position during layout.
|
||||
class _LocalToGlobalProbe extends StatefulWidget {
|
||||
const _LocalToGlobalProbe({super.key});
|
||||
|
||||
@override
|
||||
State<_LocalToGlobalProbe> createState() => _LocalToGlobalProbeState();
|
||||
}
|
||||
|
||||
class _LocalToGlobalProbeState extends State<_LocalToGlobalProbe> {
|
||||
final _viewport = GlobalKey();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final box = _viewport.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (box != null && box.hasSize) box.localToGlobal(Offset.zero);
|
||||
return SizedBox.expand(key: _viewport);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user