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,124 @@ 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+ await OneSignal .loginWithJWT ('user-123' , 'test-jwt-token' );
46+
47+ // On Android, the method should be invoked
48+ // Note: The mock handler would need to be updated to handle this
49+ // expect(channelController.state.externalId, equals('user-123'));
50+ });
51+
52+ test ('loginWithJWT does nothing on ios platforms' , () async {
53+ // Ensure we're not on Android
54+ debugDefaultTargetPlatformOverride = TargetPlatform .iOS;
55+
56+ await OneSignal .loginWithJWT ('user-123' , 'test-jwt-token' );
57+
58+ // On iOS, the method should do nothing
59+ expect (channelController.state.externalId, isNull);
60+ });
61+ }, skip: true );
62+
63+ group ('logout' , () {
64+ test ('logout invokes native method' , () async {
65+ // First login
66+ await OneSignal .login ('user-123' );
67+ expect (channelController.state.externalId, equals ('user-123' ));
68+
69+ // Then logout
70+ await OneSignal .logout ();
71+ expect (channelController.state.externalId, isNull);
72+ });
73+ });
74+
75+ group ('consentGiven' , () {
76+ test ('consentGiven sets consent given to a boolean value' , () async {
77+ await OneSignal .consentGiven (true );
78+ expect (channelController.state.consentGiven, isTrue);
79+
80+ await OneSignal .consentGiven (false );
81+ expect (channelController.state.consentGiven, isFalse);
82+ });
83+ });
84+
85+ group ('consentRequired' , () {
86+ test ('consentRequired sets requirement to a boolean value' , () async {
87+ await OneSignal .consentRequired (true );
88+ expect (channelController.state.requiresPrivacyConsent, isTrue);
89+
90+ await OneSignal .consentRequired (false );
91+ expect (channelController.state.requiresPrivacyConsent, isFalse);
92+ });
93+ });
94+
95+ group ('static properties' , () {
96+ test ('static properties are initialized' , () {
97+ expect (OneSignal .Debug , isNotNull);
98+ expect (OneSignal .User , isNotNull);
99+ expect (OneSignal .Notifications , isNotNull);
100+ expect (OneSignal .Session , isNotNull);
101+ expect (OneSignal .Location , isNotNull);
102+ expect (OneSignal .InAppMessages , isNotNull);
103+ expect (OneSignal .LiveActivities , isNotNull);
104+ });
105+
106+ test ('static properties are singletons' , () {
107+ final debug1 = OneSignal .Debug ;
108+ final debug2 = OneSignal .Debug ;
109+ expect (identical (debug1, debug2), isTrue);
110+
111+ final user1 = OneSignal .User ;
112+ final user2 = OneSignal .User ;
113+ expect (identical (user1, user2), isTrue);
114+
115+ final notifications1 = OneSignal .Notifications ;
116+ final notifications2 = OneSignal .Notifications ;
117+ expect (identical (notifications1, notifications2), isTrue);
118+
119+ final session1 = OneSignal .Session ;
120+ final session2 = OneSignal .Session ;
121+ expect (identical (session1, session2), isTrue);
122+
123+ final location1 = OneSignal .Location ;
124+ final location2 = OneSignal .Location ;
125+ expect (identical (location1, location2), isTrue);
126+
127+ final inAppMessages1 = OneSignal .InAppMessages ;
128+ final inAppMessages2 = OneSignal .InAppMessages ;
129+ expect (identical (inAppMessages1, inAppMessages2), isTrue);
130+
131+ final liveActivities1 = OneSignal .LiveActivities ;
132+ final liveActivities2 = OneSignal .LiveActivities ;
133+ expect (identical (liveActivities1, liveActivities2), isTrue);
134+ });
135+ });
21136 });
22137}
0 commit comments