11import 'package:flutter/foundation.dart' ;
2- import 'package:flutter/services.dart' ;
32import 'package:flutter_test/flutter_test.dart' ;
43import 'package:onesignal_flutter/src/liveactivities.dart' ;
54
5+ import 'mock_channel.dart' ;
6+
67const activityId = 'test-activity-id' ;
78const token = 'test-token' ;
89const activityType = 'TestActivityType' ;
@@ -12,61 +13,45 @@ void main() {
1213
1314 group ('OneSignalLiveActivities' , () {
1415 late OneSignalLiveActivities liveActivities;
15- late List < MethodCall > methodCalls ;
16+ late OneSignalMockChannelController channelController ;
1617
1718 setUp (() {
18- methodCalls = [];
19+ channelController = OneSignalMockChannelController ();
20+ channelController.resetState ();
1921 liveActivities = OneSignalLiveActivities ();
2022 debugDefaultTargetPlatformOverride = TargetPlatform .iOS;
21-
22- TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
23- .setMockMethodCallHandler (
24- const MethodChannel ('OneSignal#liveactivities' ),
25- (call) async {
26- methodCalls.add (call);
27- return null ;
28- },
29- );
3023 });
3124
3225 tearDown (() {
3326 debugDefaultTargetPlatformOverride = null ;
34- TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
35- .setMockMethodCallHandler (
36- const MethodChannel ('OneSignal#liveactivities' ),
37- null ,
38- );
3927 });
4028
4129 group ('enterLiveActivity' , () {
4230 test ('invokes OneSignal#enterLiveActivity with activityId and token' ,
4331 () async {
4432 await liveActivities.enterLiveActivity (activityId, token);
4533
46- expect (methodCalls.length, 1 );
47- expect (methodCalls[0 ].method, 'OneSignal#enterLiveActivity' );
48- expect (methodCalls[0 ].arguments,
49- {'activityId' : activityId, 'token' : token});
34+ expect (channelController.state.liveActivityEntered, true );
35+ expect (channelController.state.liveActivityId, activityId);
36+ expect (channelController.state.liveActivityToken, token);
5037 });
5138 });
5239
5340 group ('exitLiveActivity' , () {
5441 test ('invokes OneSignal#exitLiveActivity with activityId' , () async {
5542 await liveActivities.exitLiveActivity (activityId);
5643
57- expect (methodCalls.length, 1 );
58- expect (methodCalls[0 ].method, 'OneSignal#exitLiveActivity' );
59- expect (methodCalls[0 ].arguments, {'activityId' : activityId});
44+ expect (channelController.state.liveActivityExited, true );
45+ expect (channelController.state.liveActivityId, activityId);
6046 });
6147 });
6248
6349 group ('setupDefault' , () {
6450 test ('invokes OneSignal#setupDefault without options' , () async {
6551 await liveActivities.setupDefault ();
6652
67- expect (methodCalls.length, 1 );
68- expect (methodCalls[0 ].method, 'OneSignal#setupDefault' );
69- expect (methodCalls[0 ].arguments['options' ], isNull);
53+ expect (channelController.state.liveActivitySetupCalled, true );
54+ expect (channelController.state.liveActivitySetupOptions, isNull);
7055 });
7156
7257 test ('invokes OneSignal#setupDefault with custom options' , () async {
@@ -77,9 +62,8 @@ void main() {
7762
7863 await liveActivities.setupDefault (options: options);
7964
80- expect (methodCalls.length, 1 );
81- expect (methodCalls[0 ].method, 'OneSignal#setupDefault' );
82- expect (methodCalls[0 ].arguments['options' ], {
65+ expect (channelController.state.liveActivitySetupCalled, true );
66+ expect (channelController.state.liveActivitySetupOptions, {
8367 'enablePushToStart' : false ,
8468 'enablePushToUpdate' : false ,
8569 });
@@ -90,7 +74,7 @@ void main() {
9074
9175 await liveActivities.setupDefault (options: options);
9276
93- expect (methodCalls[ 0 ].arguments[ 'options' ] , {
77+ expect (channelController.state.liveActivitySetupOptions , {
9478 'enablePushToStart' : true ,
9579 'enablePushToUpdate' : true ,
9680 });
@@ -104,13 +88,10 @@ void main() {
10488
10589 await liveActivities.startDefault (activityId, attributes, content);
10690
107- expect (methodCalls.length, 1 );
108- expect (methodCalls[0 ].method, 'OneSignal#startDefault' );
109- expect (methodCalls[0 ].arguments, {
110- 'activityId' : activityId,
111- 'attributes' : attributes,
112- 'content' : content,
113- });
91+ expect (channelController.state.liveActivityStarted, true );
92+ expect (channelController.state.liveActivityId, activityId);
93+ expect (channelController.state.liveActivityAttributes, attributes);
94+ expect (channelController.state.liveActivityContent, content);
11495 });
11596
11697 test ('handles complex nested attributes and content' , () async {
@@ -126,10 +107,10 @@ void main() {
126107 await liveActivities.startDefault (
127108 activityId, complexAttributes, complexContent);
128109
129- expect (
130- methodCalls[ 0 ].arguments[ 'attributes' ][ 'nested' ][ 'key' ], 'value' );
131- expect (
132- methodCalls[ 0 ].arguments[ 'content' ][ 'data' ][ 'status' ], 'running' );
110+ expect (channelController.state.liveActivityAttributes[ 'nested' ][ 'key' ],
111+ 'value' );
112+ expect (channelController.state.liveActivityContent[ 'data' ][ 'status' ],
113+ 'running' );
133114 });
134115 });
135116
@@ -138,10 +119,9 @@ void main() {
138119 () async {
139120 await liveActivities.setPushToStartToken (activityType, token);
140121
141- expect (methodCalls.length, 1 );
142- expect (methodCalls[0 ].method, 'OneSignal#setPushToStartToken' );
143- expect (methodCalls[0 ].arguments,
144- {'activityType' : activityType, 'token' : token});
122+ expect (channelController.state.liveActivityPushToStartSet, true );
123+ expect (channelController.state.liveActivityType, activityType);
124+ expect (channelController.state.liveActivityPushToken, token);
145125 });
146126 });
147127
@@ -150,9 +130,8 @@ void main() {
150130 () async {
151131 await liveActivities.removePushToStartToken (activityType);
152132
153- expect (methodCalls.length, 1 );
154- expect (methodCalls[0 ].method, 'OneSignal#removePushToStartToken' );
155- expect (methodCalls[0 ].arguments, {'activityType' : activityType});
133+ expect (channelController.state.liveActivityPushToStartRemoved, true );
134+ expect (channelController.state.liveActivityType, activityType);
156135 });
157136 });
158137 });
0 commit comments