@@ -71,16 +71,23 @@ class _Channels extends ChannelsNotifier {
7171
7272class _Reads extends ReadStateNotifier {
7373 final bool empty;
74- _Reads ({this .empty = false });
74+ final bool ready;
75+ _Reads ({this .empty = false , this .ready = true });
7576 @override
7677 void seedContextRead (String key, int timestamp) => read (key, timestamp);
7778 @override
7879 ReadStateState build () => ReadStateState (
79- isReady: true ,
80+ isReady: ready ,
8081 pubkey: 'owner' ,
8182 contexts: empty ? {} : {'solo' : 10 },
8283 version: 0 ,
8384 );
85+ void finishLoading () => state = ReadStateState (
86+ isReady: true ,
87+ pubkey: state.pubkey,
88+ contexts: state.contexts,
89+ version: state.version + 1 ,
90+ );
8491 void resetIdentity () => state = const ReadStateState (
8592 isReady: true ,
8693 pubkey: 'other-owner' ,
@@ -177,74 +184,101 @@ void main() {
177184 },
178185 );
179186 }
180- testWidgets (
181- 'Solo retains live unread row, collapsed section, and tab indication' ,
182- (tester) async {
183- SharedPreferences .setMockInitialValues ({});
184- final prefs = await SharedPreferences .getInstance ();
185- final channels = _Channels ();
186- final reads = _Reads ();
187- await tester.pumpWidget (
188- ProviderScope (
189- overrides: [
190- savedPrefsProvider.overrideWithValue (prefs),
191- channelsProvider.overrideWith (() => channels),
192- readStateProvider.overrideWith (() => reads),
193- meGroupsProvider.overrideWith ((ref) => Stream .value (organization)),
194- meAssistantsProvider.overrideWith ((ref) async => []),
195- ],
196- child: MaterialApp (
197- theme: AppTheme .light (),
198- home: Consumer (
199- builder: (context, ref, _) => HomePage (
200- settingsPageBuilder: (_) => const SizedBox (),
201- mePageBuilder: (_) => const MePage (),
202- hasUnreadInbox: false ,
203- hasUnreadSolo: ref.watch (meUnreadChannelIdsProvider).isNotEmpty,
187+ for (final loading in [false , true ]) {
188+ testWidgets (
189+ 'Solo retains row, section, and tab unread after loading=$loading ' ,
190+ (tester) async {
191+ SharedPreferences .setMockInitialValues ({});
192+ final prefs = await SharedPreferences .getInstance ();
193+ final channels = _Channels ();
194+ final reads = _Reads (empty: loading, ready: ! loading);
195+ await tester.pumpWidget (
196+ ProviderScope (
197+ overrides: [
198+ savedPrefsProvider.overrideWithValue (prefs),
199+ channelsProvider.overrideWith (() => channels),
200+ readStateProvider.overrideWith (() => reads),
201+ meGroupsProvider.overrideWith (
202+ (ref) => Stream .value (organization),
203+ ),
204+ meAssistantsProvider.overrideWith ((ref) async => []),
205+ ],
206+ child: MaterialApp (
207+ theme: AppTheme .light (),
208+ home: Consumer (
209+ builder: (context, ref, _) => HomePage (
210+ settingsPageBuilder: (_) => const SizedBox (),
211+ mePageBuilder: (_) => const MePage (),
212+ hasUnreadInbox: false ,
213+ hasUnreadSolo: ref
214+ .watch (meUnreadChannelIdsProvider)
215+ .isNotEmpty,
216+ ),
204217 ),
205218 ),
206219 ),
207- ),
208- );
209- await tester.pumpAndSettle ();
210- final container = ProviderScope .containerOf (
211- tester.element (find.byType (HomePage )),
212- );
213- expect (container.read (meUnreadChannelIdsProvider), {'solo' });
214- expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
215- expect (find.text ('solo' ), findsNothing);
216- await tester.tap (find.byTooltip ('Solo' ));
217- await tester.pumpAndSettle ();
218- expect (
219- tester.widget <Text >(find.text ('solo' )).style? .fontWeight,
220- FontWeight .w700,
221- );
222- expect (find.bySemanticsLabel ('solo, unread' ), findsOneWidget);
223- await tester.tap (find.text ('Project' ));
224- await tester.pumpAndSettle ();
225- expect (find.text ('solo' ), findsNothing);
226- expect (
227- find.byKey (const ValueKey ('solo-section-unread-Project' )),
228- findsOneWidget,
229- );
230- reads.read ('msg:reply' , 20 );
231- await tester.pumpAndSettle ();
232- expect (
233- find.byKey (const ValueKey ('solo-section-unread-Project' )),
234- findsNothing,
235- );
236- await tester.tap (find.byTooltip ('Home' ));
237- await tester.pumpAndSettle ();
238- expect (find.bySemanticsLabel ('Solo, unread' ), findsNothing);
239- channels.reply ();
240- await tester.pumpAndSettle ();
241- expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
242- reads.read ('thread:root' , 21 );
243- await tester.pumpAndSettle ();
244- expect (find.bySemanticsLabel ('Solo, unread' ), findsNothing);
245- reads.force ();
246- await tester.pumpAndSettle ();
247- expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
248- },
249- );
220+ );
221+ await tester.pumpAndSettle ();
222+ final container = ProviderScope .containerOf (
223+ tester.element (find.byType (HomePage )),
224+ );
225+ if (loading) {
226+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
227+ expect (find.bySemanticsLabel ('Solo, unread' ), findsNothing);
228+ expect (
229+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
230+ isNull,
231+ );
232+ channels.reply ();
233+ await tester.pumpAndSettle ();
234+ expect (container.read (meUnreadChannelIdsProvider), isEmpty);
235+ expect (
236+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
237+ isNull,
238+ );
239+ reads.finishLoading ();
240+ await tester.pumpAndSettle ();
241+ expect (
242+ container.read (readStateProvider).effectiveTimestamp ('solo' ),
243+ 20 ,
244+ );
245+ }
246+ expect (container.read (meUnreadChannelIdsProvider), {'solo' });
247+ expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
248+ expect (find.text ('solo' ), findsNothing);
249+ await tester.tap (find.byTooltip ('Solo' ));
250+ await tester.pumpAndSettle ();
251+ expect (
252+ tester.widget <Text >(find.text ('solo' )).style? .fontWeight,
253+ FontWeight .w700,
254+ );
255+ expect (find.bySemanticsLabel ('solo, unread' ), findsOneWidget);
256+ await tester.tap (find.text ('Project' ));
257+ await tester.pumpAndSettle ();
258+ expect (find.text ('solo' ), findsNothing);
259+ expect (
260+ find.byKey (const ValueKey ('solo-section-unread-Project' )),
261+ findsOneWidget,
262+ );
263+ reads.read ('msg:reply' , channels.timestamp);
264+ await tester.pumpAndSettle ();
265+ expect (
266+ find.byKey (const ValueKey ('solo-section-unread-Project' )),
267+ findsNothing,
268+ );
269+ await tester.tap (find.byTooltip ('Home' ));
270+ await tester.pumpAndSettle ();
271+ expect (find.bySemanticsLabel ('Solo, unread' ), findsNothing);
272+ channels.reply ();
273+ await tester.pumpAndSettle ();
274+ expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
275+ reads.read ('thread:root' , channels.timestamp);
276+ await tester.pumpAndSettle ();
277+ expect (find.bySemanticsLabel ('Solo, unread' ), findsNothing);
278+ reads.force ();
279+ await tester.pumpAndSettle ();
280+ expect (find.bySemanticsLabel ('Solo, unread' ), findsOneWidget);
281+ },
282+ );
283+ }
250284}
0 commit comments