@@ -172,6 +172,34 @@ void main() {
172172 });
173173 });
174174
175+ test ('Narrow.toJson' , () {
176+ return FakeApiConnection .with_ ((connection) async {
177+ void checkNarrow (ApiNarrow narrow, String expected) {
178+ narrow = resolveLegacyElements (narrow, connection);
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+
175203 group ('getMessages' , () {
176204 Future <GetMessagesResult > checkGetMessages (
177205 FakeApiConnection connection, {
@@ -215,37 +243,21 @@ void main() {
215243 });
216244 });
217245
218- test ('narrow' , () {
246+ test ('narrow uses resolveLegacyElements to encode ' , () {
219247 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- ]));
245248 connection.zulipFeatureLevel = 176 ;
246- await checkNarrow ([ApiNarrowDm ([123 , 234 ])], jsonEncode ([
247- {'operator' : 'pm-with' , 'operand' : [123 , 234 ]},
248- ]));
249+ connection.prepare (json: fakeResult.toJson ());
250+ await checkGetMessages (connection,
251+ narrow: [ApiNarrowDm ([123 , 234 ])],
252+ anchor: AnchorCode .newest, numBefore: 10 , numAfter: 20 ,
253+ expected: {
254+ 'narrow' : jsonEncode ([
255+ {'operator' : 'pm-with' , 'operand' : [123 , 234 ]},
256+ ]),
257+ 'anchor' : 'newest' ,
258+ 'num_before' : '10' ,
259+ 'num_after' : '20' ,
260+ });
249261 connection.zulipFeatureLevel = eg.futureZulipFeatureLevel;
250262 });
251263 });
0 commit comments