1+ import 'package:flutter/foundation.dart' ;
12import 'package:flutter_test/flutter_test.dart' ;
23import 'package:onesignal_flutter/onesignal_flutter.dart' ;
4+
35import 'mock_channel.dart' ;
46
57void main () {
@@ -12,11 +14,126 @@ void main() {
1214 channelController.resetState ();
1315 });
1416
15- test ('set log level' , () {
16- OneSignal .Debug .setLogLevel (
17- OSLogLevel .info,
18- ).then (expectAsync1 ((v) {
19- expect (channelController.state.logLevel.index, OSLogLevel .info.index);
20- }));
17+ group ('OneSignal' , () {
18+ test ('initialize sets appId and calls lifecycle methods' , () async {
19+ OneSignal .initialize ('test-app-id' );
20+
21+ expect (channelController.state.appId, equals ('test-app-id' ));
22+ expect (channelController.state.lifecycleInitCalled, isTrue);
23+ expect (channelController.state.userLifecycleInitCalled, isTrue);
24+ });
25+
26+ group ('login' , () {
27+ test ('login invokes native method with externalId' , () async {
28+ await OneSignal .login ('user-123' );
29+
30+ expect (channelController.state.externalId, equals ('user-123' ));
31+ });
32+
33+ test ('login handles empty externalId' , () async {
34+ await OneSignal .login ('' );
35+
36+ expect (channelController.state.externalId, equals ('' ));
37+ });
38+ });
39+
40+ group ('loginWithJWT' , () {
41+ test ('loginWithJWT invokes native method on Android only' , () async {
42+ // Override platform to Android for this test
43+ debugDefaultTargetPlatformOverride = TargetPlatform .android;
44+
45+ // ignore: deprecated_member_use_from_same_package
46+ await OneSignal .loginWithJWT ('user-123' , 'test-jwt-token' );
47+
48+ // On Android, the method should be invoked
49+ // Note: The mock handler would need to be updated to handle this
50+ // expect(channelController.state.externalId, equals('user-123'));
51+ });
52+
53+ test ('loginWithJWT does nothing on ios platforms' , () async {
54+ // Ensure we're not on Android
55+ debugDefaultTargetPlatformOverride = TargetPlatform .iOS;
56+
57+ // ignore: deprecated_member_use_from_same_package
58+ await OneSignal .loginWithJWT ('user-123' , 'test-jwt-token' );
59+
60+ // On iOS, the method should do nothing
61+ expect (channelController.state.externalId, isNull);
62+ });
63+ }, skip: true );
64+
65+ group ('logout' , () {
66+ test ('logout invokes native method' , () async {
67+ // First login
68+ await OneSignal .login ('user-123' );
69+ expect (channelController.state.externalId, equals ('user-123' ));
70+
71+ // Then logout
72+ await OneSignal .logout ();
73+ expect (channelController.state.externalId, isNull);
74+ });
75+ });
76+
77+ group ('consentGiven' , () {
78+ test ('consentGiven sets consent given to a boolean value' , () async {
79+ await OneSignal .consentGiven (true );
80+ expect (channelController.state.consentGiven, isTrue);
81+
82+ await OneSignal .consentGiven (false );
83+ expect (channelController.state.consentGiven, isFalse);
84+ });
85+ });
86+
87+ group ('consentRequired' , () {
88+ test ('consentRequired sets requirement to a boolean value' , () async {
89+ await OneSignal .consentRequired (true );
90+ expect (channelController.state.requiresPrivacyConsent, isTrue);
91+
92+ await OneSignal .consentRequired (false );
93+ expect (channelController.state.requiresPrivacyConsent, isFalse);
94+ });
95+ });
96+
97+ group ('static properties' , () {
98+ test ('static properties are initialized' , () {
99+ expect (OneSignal .Debug , isNotNull);
100+ expect (OneSignal .User , isNotNull);
101+ expect (OneSignal .Notifications , isNotNull);
102+ expect (OneSignal .Session , isNotNull);
103+ expect (OneSignal .Location , isNotNull);
104+ expect (OneSignal .InAppMessages , isNotNull);
105+ expect (OneSignal .LiveActivities , isNotNull);
106+ });
107+
108+ test ('static properties are singletons' , () {
109+ final debug1 = OneSignal .Debug ;
110+ final debug2 = OneSignal .Debug ;
111+ expect (identical (debug1, debug2), isTrue);
112+
113+ final user1 = OneSignal .User ;
114+ final user2 = OneSignal .User ;
115+ expect (identical (user1, user2), isTrue);
116+
117+ final notifications1 = OneSignal .Notifications ;
118+ final notifications2 = OneSignal .Notifications ;
119+ expect (identical (notifications1, notifications2), isTrue);
120+
121+ final session1 = OneSignal .Session ;
122+ final session2 = OneSignal .Session ;
123+ expect (identical (session1, session2), isTrue);
124+
125+ final location1 = OneSignal .Location ;
126+ final location2 = OneSignal .Location ;
127+ expect (identical (location1, location2), isTrue);
128+
129+ final inAppMessages1 = OneSignal .InAppMessages ;
130+ final inAppMessages2 = OneSignal .InAppMessages ;
131+ expect (identical (inAppMessages1, inAppMessages2), isTrue);
132+
133+ final liveActivities1 = OneSignal .LiveActivities ;
134+ final liveActivities2 = OneSignal .LiveActivities ;
135+ expect (identical (liveActivities1, liveActivities2), isTrue);
136+ });
137+ });
21138 });
22139}
0 commit comments