tasq/test/typing_dispose_race_test.dart

38 lines
1.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:tasq/providers/typing_provider.dart';
void main() {
test(
'TypingIndicatorController ignores late remote events after dispose',
() async {
final client = SupabaseClient('http://localhost', 'test-key',
authOptions: const AuthClientOptions(autoRefreshToken: false));
final controller = TypingIndicatorController(client, 'ticket-1');
// initial state should be empty
expect(controller.state.userIds, isEmpty);
// Simulate a remote "start typing" arriving while alive
controller.debugSimulateRemoteTyping('user-2');
expect(controller.state.userIds, contains('user-2'));
// Dispose the controller
controller.dispose();
// Calling the remote handlers after dispose must NOT throw and must be no-ops
expect(
() => controller.debugSimulateRemoteTyping('user-3'),
returnsNormally,
);
expect(
() => controller.debugSimulateRemoteTyping('user-2', stop: true),
returnsNormally,
);
// Ensure state was not modified after dispose
expect(controller.mounted, isFalse);
},
);
}