@@ -131,6 +131,59 @@ void main() {
131
131
NotificationChannelManager .kVibrationPattern)
132
132
;
133
133
});
134
+
135
+ test ('channel is not recreated if one with same id already exists' , () async {
136
+ await NotificationChannelManager .ensureChannel ();
137
+ check (testBinding.androidNotificationHost.takeChannelMethodCallLogs ())
138
+ .deepEquals (['getNotificationChannels' , 'createNotificationChannel' ]);
139
+
140
+ await NotificationChannelManager .ensureChannel ();
141
+ check (testBinding.androidNotificationHost.takeChannelMethodCallLogs ())
142
+ .deepEquals (['getNotificationChannels' ]);
143
+
144
+ check (testBinding.androidNotificationHost.takeCreatedChannels ()).single
145
+ ..id.equals (NotificationChannelManager .kChannelId)
146
+ ..name.equals ('Messages' )
147
+ ..importance.equals (NotificationImportance .high)
148
+ ..lightsEnabled.equals (true )
149
+ ..vibrationPattern.isNotNull ().deepEquals (
150
+ NotificationChannelManager .kVibrationPattern);
151
+ });
152
+
153
+ test ('obsolete channels are removed' , () async {
154
+ await NotificationChannelManager .ensureChannel ();
155
+ check (testBinding.androidNotificationHost.takeChannelMethodCallLogs ())
156
+ .deepEquals (['getNotificationChannels' , 'createNotificationChannel' ]);
157
+
158
+ await testBinding.androidNotificationHost.createNotificationChannel (NotificationChannel (
159
+ id: 'obsolete-1' ,
160
+ name: 'Obsolete 1' ,
161
+ importance: NotificationImportance .high,
162
+ lightsEnabled: true ,
163
+ vibrationPattern: NotificationChannelManager .kVibrationPattern));
164
+ await testBinding.androidNotificationHost.createNotificationChannel (NotificationChannel (
165
+ id: 'obsolete-2' ,
166
+ name: 'Obsolete 2' ,
167
+ importance: NotificationImportance .high,
168
+ lightsEnabled: true ,
169
+ vibrationPattern: NotificationChannelManager .kVibrationPattern));
170
+ check (testBinding.androidNotificationHost.takeChannelMethodCallLogs ())
171
+ .deepEquals (['createNotificationChannel' , 'createNotificationChannel' ]);
172
+
173
+ await NotificationChannelManager .ensureChannel ();
174
+ check (testBinding.androidNotificationHost.takeChannelMethodCallLogs ())
175
+ .deepEquals ([
176
+ 'getNotificationChannels' ,
177
+ 'deleteNotificationChannel' ,
178
+ 'deleteNotificationChannel' ]);
179
+ check (testBinding.androidNotificationHost.takeCreatedChannels ()).single
180
+ ..id.equals (NotificationChannelManager .kChannelId)
181
+ ..name.equals ('Messages' )
182
+ ..importance.equals (NotificationImportance .high)
183
+ ..lightsEnabled.equals (true )
184
+ ..vibrationPattern.isNotNull ().deepEquals (
185
+ NotificationChannelManager .kVibrationPattern);
186
+ });
134
187
});
135
188
136
189
group ('NotificationDisplayManager show' , () {
0 commit comments