forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshare_sheet_test.dart
More file actions
65 lines (53 loc) · 2.04 KB
/
Copy pathshare_sheet_test.dart
File metadata and controls
65 lines (53 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// The share sheet must always get a non-empty anchor rect.
///
/// iPad and macOS present it as a popover and `share_plus` throws a
/// PlatformException when the origin is missing or zero-sized. Share calls are
/// typically the last await in a button handler, so that exception goes
/// unhandled and the button silently does nothing — which is how the device
/// diagnostics export appeared broken.
library;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/utils/share_sheet.dart';
void main() {
group('shareSheetOrigin', () {
test('falls back to a non-empty rect when there is no anchor key', () {
final rect = shareSheetOrigin();
expect(rect.isEmpty, isFalse);
expect(rect, equals(kFallbackShareOrigin));
});
test('falls back when the key was never attached to a widget', () {
final rect = shareSheetOrigin(GlobalKey());
expect(rect.isEmpty, isFalse);
});
testWidgets('returns the anchor widget rect once laid out', (tester) async {
final key = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(child: SizedBox(key: key, width: 48, height: 24)),
),
),
);
final rect = shareSheetOrigin(key);
expect(rect.width, 48);
expect(rect.height, 24);
expect(rect.isEmpty, isFalse);
// Anchored to the real widget, not the corner fallback.
expect(rect, isNot(equals(kFallbackShareOrigin)));
});
testWidgets('falls back rather than returning an empty rect for a zero-sized anchor', (tester) async {
final key = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(child: SizedBox(key: key, width: 0, height: 0)),
),
),
);
final rect = shareSheetOrigin(key);
expect(rect.isEmpty, isFalse, reason: 'an empty rect is exactly what makes share_plus throw');
expect(rect, equals(kFallbackShareOrigin));
});
});
}