diff --git a/core/events/lib/src/dispatcher.dart b/core/events/lib/src/dispatcher.dart index 9a692a41..bf2137c4 100644 --- a/core/events/lib/src/dispatcher.dart +++ b/core/events/lib/src/dispatcher.dart @@ -328,6 +328,15 @@ class Dispatcher implements DispatcherContract { _transactionManagerResolver = resolver; } + // Add these methods for testing purposes + void triggerQueueResolver() { + _queueResolver(); + } + + void triggerTransactionManagerResolver() { + _transactionManagerResolver(); + } + @override Map> getRawListeners() { return Map.unmodifiable(_listeners); diff --git a/core/events/test/event_test.dart b/core/events/test/event_test.dart index 1c7ff64a..c8b6acb8 100644 --- a/core/events/test/event_test.dart +++ b/core/events/test/event_test.dart @@ -147,6 +147,57 @@ void main() { expect(mockMQClient.queuedMessages['events_queue']!.first.payload, containsPair('event', 'QueueTestEvent')); }); + + test('forgetPushed removes only pushed events', () { + dispatcher.listen('event_pushed', (_, __) {}); + dispatcher.listen('normal_event', (_, __) {}); + + dispatcher.forgetPushed(); + + expect(dispatcher.hasListeners('event_pushed'), isFalse); + expect(dispatcher.hasListeners('normal_event'), isTrue); + }); + + test('setQueueResolver and setTransactionManagerResolver', () { + var queueResolverCalled = false; + var transactionManagerResolverCalled = false; + + dispatcher.setQueueResolver(() { + queueResolverCalled = true; + }); + + dispatcher.setTransactionManagerResolver(() { + transactionManagerResolverCalled = true; + }); + + // Trigger the resolvers + dispatcher.triggerQueueResolver(); + dispatcher.triggerTransactionManagerResolver(); + + expect(queueResolverCalled, isTrue); + expect(transactionManagerResolverCalled, isTrue); + }); + + test('getRawListeners returns unmodifiable map', () { + dispatcher.listen('test_event', (_, __) {}); + var rawListeners = dispatcher.getRawListeners(); + + expect(rawListeners, isA>>()); + expect(() => rawListeners['new_event'] = [], throwsUnsupportedError); + }); + + test('multiple listeners for same event', () async { + var callCount1 = 0; + var callCount2 = 0; + + dispatcher.listen('multi_event', (_, __) => callCount1++); + dispatcher.listen('multi_event', (_, __) => callCount2++); + + await dispatcher.dispatch('multi_event'); + + expect(callCount1, equals(1)); + expect(callCount2, equals(1)); + }); }); }