RNNotificationsStoreTests.m 2.79 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "RNNotificationsStore.h"

@interface RNNotificationsStoreTests : XCTestCase
@property (nonatomic, retain) RNNotificationsStore* store;
@end

@implementation RNNotificationsStoreTests

- (void)setUp {
    _store = [RNNotificationsStore sharedInstance];
}

- (void)testSetActionCompletionHandler_ShouldStoreBlock {
    void (^testBlock)(void) = ^void() {};
    [_store setActionCompletionHandler:testBlock withCompletionKey:@"actionTestBlock"];
    XCTAssertEqual(testBlock, [_store getActionCompletionHandler:@"actionTestBlock"]);
}

- (void)testCompleteAction_ShouldInvokeBlock {
    __block BOOL blockInvoked = NO;
    void (^testBlock)(void) = ^void() {
        blockInvoked = YES;
    };
    [_store setActionCompletionHandler:testBlock withCompletionKey:@"actionTestBlock"];
    [_store completeAction:@"actionTestBlock"];
    XCTAssertTrue(blockInvoked);
}

- (void)testCompleteAction_ShouldRemoveBlock {
    __block BOOL blockInvoked = NO;
    void (^testBlock)(void) = ^void() {
        blockInvoked = YES;
    };
    [_store setActionCompletionHandler:testBlock withCompletionKey:@"actionTestBlock"];
    [_store completeAction:@"actionTestBlock"];
    XCTAssertNil([_store getActionCompletionHandler:@"actionTestBlock"]);
}


- (void)testSetPersentationCompletionHandler_ShouldStoreBlock {
    void (^testBlock)(UNNotificationPresentationOptions) = ^void(UNNotificationPresentationOptions options) {};
    [_store setPresentationCompletionHandler:testBlock withCompletionKey:@"presentationTestBlock"];
    XCTAssertEqual(testBlock, [_store getPresentationCompletionHandler:@"presentationTestBlock"]);
}

- (void)testCompletePresentation_ShouldInvokeBlockWithParams {
    __block UNNotificationPresentationOptions presentationOptions;
    void (^testBlock)(UNNotificationPresentationOptions) = ^void(UNNotificationPresentationOptions options) {
        presentationOptions = options;
    };
    [_store setPresentationCompletionHandler:testBlock withCompletionKey:@"presentationTestBlock"];
    [_store completePresentation:@"presentationTestBlock" withPresentationOptions:UNNotificationPresentationOptionAlert];
    XCTAssertEqual(presentationOptions, UNNotificationPresentationOptionAlert);
}

- (void)testCompletePresentation_ShouldRemoveBlock {
    __block UNNotificationPresentationOptions presentationOptions;
    void (^testBlock)(UNNotificationPresentationOptions) = ^void(UNNotificationPresentationOptions options) {
        presentationOptions = options;
    };
    [_store setPresentationCompletionHandler:testBlock withCompletionKey:@"presentationTestBlock"];
    [_store completePresentation:@"presentationTestBlock" withPresentationOptions:UNNotificationPresentationOptionAlert];
    XCTAssertNil([_store getPresentationCompletionHandler:@"presentationTestBlock"]);
}


@end