@@ -172,6 +172,34 @@ void main() {
172
172
});
173
173
});
174
174
175
+ test ('Narrow.toJson' , () {
176
+ return FakeApiConnection .with_ ((connection) async {
177
+ void checkNarrow (ApiNarrow narrow, String expected) {
178
+ narrow = resolveDmElements (narrow, connection.zulipFeatureLevel! );
179
+ check (jsonEncode (narrow)).equals (expected);
180
+ }
181
+
182
+ checkNarrow (const AllMessagesNarrow ().apiEncode (), jsonEncode ([]));
183
+ checkNarrow (const StreamNarrow (12 ).apiEncode (), jsonEncode ([
184
+ {'operator' : 'stream' , 'operand' : 12 },
185
+ ]));
186
+ checkNarrow (const TopicNarrow (12 , 'stuff' ).apiEncode (), jsonEncode ([
187
+ {'operator' : 'stream' , 'operand' : 12 },
188
+ {'operator' : 'topic' , 'operand' : 'stuff' },
189
+ ]));
190
+
191
+ checkNarrow ([ApiNarrowDm ([123 , 234 ])], jsonEncode ([
192
+ {'operator' : 'dm' , 'operand' : [123 , 234 ]},
193
+ ]));
194
+
195
+ connection.zulipFeatureLevel = 176 ;
196
+ checkNarrow ([ApiNarrowDm ([123 , 234 ])], jsonEncode ([
197
+ {'operator' : 'pm-with' , 'operand' : [123 , 234 ]},
198
+ ]));
199
+ connection.zulipFeatureLevel = eg.futureZulipFeatureLevel;
200
+ });
201
+ });
202
+
175
203
group ('getMessages' , () {
176
204
Future <GetMessagesResult > checkGetMessages (
177
205
FakeApiConnection connection, {
@@ -215,38 +243,20 @@ void main() {
215
243
});
216
244
});
217
245
218
- test ('narrow' , () {
219
- return FakeApiConnection .with_ ((connection) async {
220
- Future <void > checkNarrow (ApiNarrow narrow, String expected) async {
221
- connection.prepare (json: fakeResult.toJson ());
222
- await checkGetMessages (connection,
223
- narrow: narrow,
224
- anchor: AnchorCode .newest, numBefore: 10 , numAfter: 20 ,
225
- expected: {
226
- 'narrow' : expected,
227
- 'anchor' : 'newest' ,
228
- 'num_before' : '10' ,
229
- 'num_after' : '20' ,
230
- });
231
- }
232
-
233
- await checkNarrow (const AllMessagesNarrow ().apiEncode (), jsonEncode ([]));
234
- await checkNarrow (const StreamNarrow (12 ).apiEncode (), jsonEncode ([
235
- {'operator' : 'stream' , 'operand' : 12 },
236
- ]));
237
- await checkNarrow (const TopicNarrow (12 , 'stuff' ).apiEncode (), jsonEncode ([
238
- {'operator' : 'stream' , 'operand' : 12 },
239
- {'operator' : 'topic' , 'operand' : 'stuff' },
240
- ]));
241
-
242
- await checkNarrow ([ApiNarrowDm ([123 , 234 ])], jsonEncode ([
243
- {'operator' : 'dm' , 'operand' : [123 , 234 ]},
244
- ]));
245
- connection.zulipFeatureLevel = 176 ;
246
- await checkNarrow ([ApiNarrowDm ([123 , 234 ])], jsonEncode ([
247
- {'operator' : 'pm-with' , 'operand' : [123 , 234 ]},
248
- ]));
249
- connection.zulipFeatureLevel = eg.futureZulipFeatureLevel;
246
+ test ('narrow uses resolveLegacyElements to encode' , () {
247
+ return FakeApiConnection .with_ (zulipFeatureLevel: 176 , (connection) async {
248
+ connection.prepare (json: fakeResult.toJson ());
249
+ await checkGetMessages (connection,
250
+ narrow: [ApiNarrowDm ([123 , 234 ])],
251
+ anchor: AnchorCode .newest, numBefore: 10 , numAfter: 20 ,
252
+ expected: {
253
+ 'narrow' : jsonEncode ([
254
+ {'operator' : 'pm-with' , 'operand' : [123 , 234 ]},
255
+ ]),
256
+ 'anchor' : 'newest' ,
257
+ 'num_before' : '10' ,
258
+ 'num_after' : '20' ,
259
+ });
250
260
});
251
261
});
252
262
0 commit comments