22
22
import org .robolectric .android .controller .ActivityController ;
23
23
import org .robolectric .annotation .Config ;
24
24
import org .robolectric .shadows .ShadowLog ;
25
+ import org .robolectric .shadows .ShadowNotificationManager ;
25
26
26
27
import static com .onesignal .OneSignalPackagePrivateHelper .NotificationChannelManager_createNotificationChannel ;
27
28
import static com .onesignal .OneSignalPackagePrivateHelper .NotificationChannelManager_processChannelList ;
@@ -93,12 +94,13 @@ public void createNotificationChannelCreateBasicChannel() throws Exception {
93
94
}
94
95
95
96
@ Test
96
- public void createNotificationChannelWithALlOptionsl () throws Exception {
97
+ public void createNotificationChannelWithALlOptions () throws Exception {
97
98
JSONObject payload = new JSONObject ();
98
99
JSONObject chnl = new JSONObject ();
99
100
100
101
chnl .put ("id" , "test_id" );
101
102
chnl .put ("nm" , "Test Name" );
103
+ chnl .put ("dscr" , "Some description" );
102
104
chnl .put ("grp_id" , "grp_id" );
103
105
chnl .put ("grp_nm" , "Group Name" );
104
106
@@ -120,6 +122,7 @@ public void createNotificationChannelWithALlOptionsl() throws Exception {
120
122
assertEquals ("test_id" , ret );
121
123
assertEquals ("test_id" , ShadowRoboNotificationManager .lastChannel .getId ());
122
124
assertEquals ("Test Name" , channel .getName ());
125
+ assertEquals ("Some description" , channel .getDescription ());
123
126
assertEquals ("grp_id" , channel .getGroup ());
124
127
NotificationChannelGroup group = ShadowRoboNotificationManager .lastChannelGroup ;
125
128
assertEquals ("grp_id" , group .getId ());
@@ -194,6 +197,35 @@ public void processPayloadDeletingOldChannel() throws Exception {
194
197
assertChannelsForBasicChannelList ();
195
198
}
196
199
200
+ // Test that specific "en" defined keys name and descriptions are used when
201
+ // the device language is English.
202
+ // Top level keys under no language key are considered the default language.
203
+ @ Test
204
+ public void processChannelListWithMultiLanguage () throws Exception {
205
+ JSONObject payload = createBasicChannelListPayload ();
206
+
207
+ JSONObject channelItem = (JSONObject )payload .optJSONArray ("chnl_lst" ).get (0 );
208
+ JSONObject channelProperties = channelItem .optJSONObject ("chnl" );
209
+
210
+ // Add "langs" key with a "en" sub key.
211
+ JSONObject langs = new JSONObject ();
212
+ JSONObject en = new JSONObject ();
213
+ en .put ("nm" , "en_nm" );
214
+ en .put ("dscr" , "en_dscr" );
215
+ en .put ("grp_nm" , "en_grp_nm" );
216
+ langs .put ("en" , en );
217
+ channelProperties .put ("langs" , langs );
218
+
219
+ channelProperties .put ("grp_id" , "grp_id1" );
220
+
221
+ NotificationChannelManager_processChannelList (blankActivity , payload );
222
+
223
+ NotificationChannel channel = getChannel ("OS_id1" );
224
+ assertEquals ("en_nm" , channel .getName ());
225
+ assertEquals ("en_dscr" , channel .getDescription ());
226
+ assertEquals ("en_grp_nm" , ShadowRoboNotificationManager .lastChannelGroup .getName ());
227
+ }
228
+
197
229
JSONObject createBasicChannelListPayload () throws JSONException {
198
230
createChannel ("local_existing_id" );
199
231
createChannel ("OS_existing_id" );
0 commit comments