Update: completed writing initial unit test all are passing
This commit is contained in:
parent
fadcffdc25
commit
2e4e153b4f
2 changed files with 60 additions and 0 deletions
|
@ -328,6 +328,15 @@ class Dispatcher implements DispatcherContract {
|
|||
_transactionManagerResolver = resolver;
|
||||
}
|
||||
|
||||
// Add these methods for testing purposes
|
||||
void triggerQueueResolver() {
|
||||
_queueResolver();
|
||||
}
|
||||
|
||||
void triggerTransactionManagerResolver() {
|
||||
_transactionManagerResolver();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, List<Function>> getRawListeners() {
|
||||
return Map.unmodifiable(_listeners);
|
||||
|
|
|
@ -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<Map<String, List<Function>>>());
|
||||
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));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue