Skip to content

Commit f540467

Browse files
committed
test: add deeplink tests
1 parent e6e25a7 commit f540467

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
194194
}
195195
}
196196

197+
// This function is a workaround, when we support open the workspace from invitation deep link,
198+
// we should refactor the code here
197199
void _openWorkspaceFromInvitation() {
198200
final workspaceId = openWorkspaceIdNotifier.value;
199201
if (workspaceId == null) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'package:appflowy/startup/tasks/deeplink/deeplink_handler.dart';
2+
import 'package:appflowy/startup/tasks/deeplink/invitation_deeplink_hanlder.dart';
3+
import 'package:appflowy/startup/tasks/deeplink/login_deeplink_handler.dart';
4+
import 'package:appflowy/startup/tasks/deeplink/payment_deeplink_handler.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
group('deep link handler: ', () {
9+
final deepLinkHandlerRegistry = DeepLinkHandlerRegistry.instance
10+
..register(LoginDeepLinkHandler())
11+
..register(PaymentDeepLinkHandler())
12+
..register(InvitationDeepLinkHandler());
13+
14+
test('invitation deep link handler', () {
15+
final uri =
16+
Uri.parse('appflowy-flutter://invitation-callback?workspace_id=123');
17+
deepLinkHandlerRegistry.processDeepLink(
18+
uri: uri,
19+
onStateChange: (handler, state) {
20+
expect(handler, isA<InvitationDeepLinkHandler>());
21+
},
22+
onResult: (handler, result) {
23+
expect(handler, isA<InvitationDeepLinkHandler>());
24+
expect(result.isSuccess, true);
25+
},
26+
onError: (error) {
27+
expect(error, isNull);
28+
},
29+
);
30+
});
31+
32+
test('login deep link handler', () {
33+
final uri = Uri.parse('appflowy-flutter://login');
34+
deepLinkHandlerRegistry.processDeepLink(
35+
uri: uri,
36+
onStateChange: (handler, state) {
37+
expect(handler, isA<LoginDeepLinkHandler>());
38+
},
39+
onResult: (handler, result) {
40+
expect(handler, isA<LoginDeepLinkHandler>());
41+
expect(result.isSuccess, true);
42+
},
43+
onError: (error) {
44+
expect(error, isNull);
45+
},
46+
);
47+
});
48+
49+
test('payment deep link handler', () {
50+
final uri = Uri.parse('appflowy-flutter://payment');
51+
deepLinkHandlerRegistry.processDeepLink(
52+
uri: uri,
53+
onStateChange: (handler, state) {
54+
expect(handler, isA<PaymentDeepLinkHandler>());
55+
},
56+
onResult: (handler, result) {
57+
expect(handler, isA<PaymentDeepLinkHandler>());
58+
expect(result.isSuccess, true);
59+
},
60+
onError: (error) {
61+
expect(error, isNull);
62+
},
63+
);
64+
});
65+
66+
test('unknown deep link handler', () {
67+
final uri =
68+
Uri.parse('appflowy-flutter://unknown-callback?workspace_id=123');
69+
deepLinkHandlerRegistry.processDeepLink(
70+
uri: uri,
71+
onStateChange: (handler, state) {},
72+
onResult: (handler, result) {},
73+
onError: (error) {
74+
expect(error, isNotNull);
75+
},
76+
);
77+
});
78+
});
79+
}

0 commit comments

Comments
 (0)