@@ -131,6 +131,81 @@ 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
+ addTearDown (testBinding.reset);
137
+
138
+ // Setup initial channel.
139
+ await testBinding.androidNotificationHost.createNotificationChannel (
140
+ NotificationChannel (
141
+ id: NotificationChannelManager .kChannelId,
142
+ name: 'Messages' ,
143
+ importance: NotificationImportance .high,
144
+ lightsEnabled: true ,
145
+ vibrationPattern: NotificationChannelManager .kVibrationPattern));
146
+ // Clear the log.
147
+ check (testBinding.androidNotificationHost.takeCreatedChannels ())
148
+ .length.equals (1 );
149
+
150
+ // Ensure that no calls were made to the deleteChannel or createChannel
151
+ // functions.
152
+ await NotificationChannelManager .ensureChannel ();
153
+ check (testBinding.androidNotificationHost.takeDeletedChannels ())
154
+ .isEmpty ();
155
+ check (testBinding.androidNotificationHost.takeCreatedChannels ())
156
+ .isEmpty ();
157
+ check (testBinding.androidNotificationHost.activeChannels).single
158
+ ..id.equals (NotificationChannelManager .kChannelId)
159
+ ..name.equals ('Messages' )
160
+ ..importance.equals (NotificationImportance .high)
161
+ ..lightsEnabled.equals (true )
162
+ ..vibrationPattern.isNotNull ().deepEquals (
163
+ NotificationChannelManager .kVibrationPattern);
164
+ });
165
+
166
+ test ('obsolete channels are removed' , () async {
167
+ addTearDown (testBinding.reset);
168
+
169
+ // Setup initial channels.
170
+ await testBinding.androidNotificationHost.createNotificationChannel (
171
+ NotificationChannel (
172
+ id: 'obsolete-1' ,
173
+ name: 'Obsolete 1' ,
174
+ importance: NotificationImportance .high,
175
+ lightsEnabled: true ,
176
+ vibrationPattern: NotificationChannelManager .kVibrationPattern));
177
+ await testBinding.androidNotificationHost.createNotificationChannel (
178
+ NotificationChannel (
179
+ id: 'obsolete-2' ,
180
+ name: 'Obsolete 2' ,
181
+ importance: NotificationImportance .high,
182
+ lightsEnabled: true ,
183
+ vibrationPattern: NotificationChannelManager .kVibrationPattern));
184
+ // Clear the log.
185
+ check (testBinding.androidNotificationHost.takeCreatedChannels ())
186
+ .length.equals (2 );
187
+
188
+ // Ensure that any channel whose channel-id differs from the desired
189
+ // channel-id (NotificationChannelManager.kChannelId) is deleted, and a
190
+ // new one with the desired channel-id is created.
191
+ await NotificationChannelManager .ensureChannel ();
192
+ check (testBinding.androidNotificationHost.takeDeletedChannels ())
193
+ .deepEquals (['obsolete-1' , 'obsolete-2' ]);
194
+ check (testBinding.androidNotificationHost.takeCreatedChannels ()).single
195
+ ..id.equals (NotificationChannelManager .kChannelId)
196
+ ..name.equals ('Messages' )
197
+ ..importance.equals (NotificationImportance .high)
198
+ ..lightsEnabled.equals (true )
199
+ ..vibrationPattern.isNotNull ().deepEquals (
200
+ NotificationChannelManager .kVibrationPattern);
201
+ check (testBinding.androidNotificationHost.activeChannels).single
202
+ ..id.equals (NotificationChannelManager .kChannelId)
203
+ ..name.equals ('Messages' )
204
+ ..importance.equals (NotificationImportance .high)
205
+ ..lightsEnabled.equals (true )
206
+ ..vibrationPattern.isNotNull ().deepEquals (
207
+ NotificationChannelManager .kVibrationPattern);
208
+ });
134
209
});
135
210
136
211
group ('NotificationDisplayManager show' , () {
0 commit comments