fix(search): guard stale refresh callbacks
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/i18n/strings.g.dart';
|
||||
import 'package:plezy/mixins/refreshable.dart';
|
||||
import 'package:plezy/screens/search_screen.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() {
|
||||
LocaleSettings.setLocaleSync(AppLocale.en);
|
||||
});
|
||||
|
||||
testWidgets('stale callbacks are no-ops after SearchScreen is disposed', (tester) async {
|
||||
final key = GlobalKey<State<SearchScreen>>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
TranslationProvider(
|
||||
child: MaterialApp(home: SearchScreen(key: key)),
|
||||
),
|
||||
);
|
||||
|
||||
final state = key.currentState!;
|
||||
final searchInput = state as SearchInputFocusable;
|
||||
searchInput.setSearchQuery('movie');
|
||||
await tester.pump();
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(() => (state as Refreshable).refresh(), returnsNormally);
|
||||
expect(() => (state as dynamic).updateItem('movie_1'), returnsNormally);
|
||||
expect(() => (state as FullRefreshable).fullRefresh(), returnsNormally);
|
||||
expect(() => searchInput.setSearchQuery('new movie'), returnsNormally);
|
||||
expect(() => (state as FocusableTab).focusActiveTabIfReady(), returnsNormally);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user