|
| 1 | +// |
| 2 | +// InstabugBugReportingTests.m |
| 3 | +// InstabugSampleTests |
| 4 | +// |
| 5 | +// Created by Salma Ali on 7/30/19. |
| 6 | +// Copyright © 2019 Facebook. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import <XCTest/XCTest.h> |
| 10 | +#import "OCMock/OCMock.h" |
| 11 | +#import "InstabugBugReportingBridge.h" |
| 12 | +#import <Instabug/IBGTypes.h> |
| 13 | +#import "Instabug/Instabug.h" |
| 14 | +#import "IBGConstants.h" |
| 15 | + |
| 16 | +@interface InstabugBugReportingTests : XCTestCase |
| 17 | +@property (nonatomic, retain) InstabugBugReportingBridge *instabugBridge; |
| 18 | +@end |
| 19 | + |
| 20 | +@implementation InstabugBugReportingTests |
| 21 | + |
| 22 | +- (void)setUp { |
| 23 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 24 | + self.instabugBridge = [[InstabugBugReportingBridge alloc] init]; |
| 25 | +} |
| 26 | + |
| 27 | +/* |
| 28 | + +------------------------------------------------------------------------+ |
| 29 | + | Bug Reporting Module | |
| 30 | + +------------------------------------------------------------------------+ |
| 31 | + */ |
| 32 | + |
| 33 | +- (void) testgivenBoolean$setBugReportingEnabled_whenQuery_thenShouldCallNativeApi { |
| 34 | + BOOL enabled = true; |
| 35 | + [self.instabugBridge setEnabled:enabled]; |
| 36 | + XCTAssertTrue(IBGBugReporting.enabled); |
| 37 | +} |
| 38 | + |
| 39 | +- (void) testgivenInvocationEvent$setInvocationEvents_whenQuery_thenShouldCallNativeApiWithArgs { |
| 40 | + NSArray *invocationEventsArr; |
| 41 | + invocationEventsArr = [NSArray arrayWithObjects: @(IBGInvocationEventScreenshot), nil]; |
| 42 | + |
| 43 | + [self.instabugBridge setInvocationEvents:invocationEventsArr]; |
| 44 | + IBGInvocationEvent invocationEvents = 0; |
| 45 | + for (NSNumber *boxedValue in invocationEventsArr) { |
| 46 | + invocationEvents |= [boxedValue intValue]; |
| 47 | + } |
| 48 | + XCTAssertEqual(IBGBugReporting.invocationEvents, invocationEvents); |
| 49 | +} |
| 50 | + |
| 51 | +- (void) testgivenOptions$setOptions_whenQuery_thenShouldCallNativeApiWithArgs { |
| 52 | + NSArray *invocationOptionsArr = [NSArray arrayWithObjects: @(IBGBugReportingInvocationOptionEmailFieldHidden), nil]; |
| 53 | + |
| 54 | + [self.instabugBridge setOptions:invocationOptionsArr]; |
| 55 | + IBGBugReportingOption invocationOptions = 0; |
| 56 | + for (NSNumber *boxedValue in invocationOptionsArr) { |
| 57 | + invocationOptions |= [boxedValue intValue]; |
| 58 | + } |
| 59 | + XCTAssertEqual(IBGBugReporting.bugReportingOptions, invocationOptions); |
| 60 | +} |
| 61 | + |
| 62 | +- (void) testgivenHandler$setOnInvokeHandler_whenQuery_thenShouldCallNativeApi { |
| 63 | + id partialMock = OCMPartialMock(self.instabugBridge); |
| 64 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 65 | + [partialMock setOnInvokeHandler:callback]; |
| 66 | + XCTAssertNotNil(IBGBugReporting.willInvokeHandler); |
| 67 | + OCMStub([partialMock sendEventWithName:@"IBGpreInvocationHandler" body:nil]); |
| 68 | + IBGBugReporting.willInvokeHandler(); |
| 69 | + OCMVerify([partialMock sendEventWithName:@"IBGpreInvocationHandler" body:nil]); |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | +- (void) testgivenHandlerCANCEL$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi { |
| 74 | + id partialMock = OCMPartialMock(self.instabugBridge); |
| 75 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 76 | + [partialMock setOnSDKDismissedHandler:callback]; |
| 77 | + XCTAssertNotNil(IBGBugReporting.didDismissHandler); |
| 78 | + NSDictionary *result = @{ @"dismissType": @"CANCEL", |
| 79 | + @"reportType": @"bug"}; |
| 80 | + OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 81 | + IBGBugReporting.didDismissHandler(IBGDismissTypeCancel,IBGReportTypeBug); |
| 82 | + OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 83 | +} |
| 84 | + |
| 85 | +- (void) testgivenHandlerSUBMIT$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi { |
| 86 | + id partialMock = OCMPartialMock(self.instabugBridge); |
| 87 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 88 | + [partialMock setOnSDKDismissedHandler:callback]; |
| 89 | + XCTAssertNotNil(IBGBugReporting.didDismissHandler); |
| 90 | + |
| 91 | + NSDictionary *result = @{ @"dismissType": @"SUBMIT", |
| 92 | + @"reportType": @"feedback"}; |
| 93 | + OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 94 | + IBGBugReporting.didDismissHandler(IBGDismissTypeSubmit,IBGReportTypeFeedback); |
| 95 | + OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 96 | +} |
| 97 | + |
| 98 | +- (void) testgivenHandlerADD_ATTACHMENT$setOnSDKDismissedHandler_whenQuery_thenShouldCallNativeApi { |
| 99 | + id partialMock = OCMPartialMock(self.instabugBridge); |
| 100 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 101 | + [partialMock setOnSDKDismissedHandler:callback]; |
| 102 | + XCTAssertNotNil(IBGBugReporting.didDismissHandler); |
| 103 | + NSDictionary *result = @{ @"dismissType": @"ADD_ATTACHMENT", |
| 104 | + @"reportType": @"feedback"}; |
| 105 | + OCMStub([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 106 | + IBGBugReporting.didDismissHandler(IBGDismissTypeAddAttachment,IBGReportTypeFeedback); |
| 107 | + OCMVerify([partialMock sendEventWithName:@"IBGpostInvocationHandler" body:result]); |
| 108 | +} |
| 109 | + |
| 110 | +- (void) skip_testgivenDouble$setShakingThresholdForiPhone_whenQuery_thenShouldCallNativeApi { |
| 111 | + double threshold = 12; |
| 112 | + [self.instabugBridge setShakingThresholdForiPhone:threshold]; |
| 113 | + XCTAssertEqual(IBGBugReporting.shakingThresholdForiPhone, threshold); |
| 114 | +} |
| 115 | + |
| 116 | +- (void) skip_testgivenDouble$setShakingThresholdForiPad_whenQuery_thenShouldCallNativeApi { |
| 117 | + double threshold = 12; |
| 118 | + [self.instabugBridge setShakingThresholdForiPad:threshold]; |
| 119 | + XCTAssertEqual(IBGBugReporting.shakingThresholdForiPad, threshold); |
| 120 | +} |
| 121 | + |
| 122 | +- (void) testgivenExtendedBugReportMode$setExtendedBugReportMode_whenQuery_thenShouldCallNativeApi { |
| 123 | + IBGExtendedBugReportMode extendedBugReportMode = IBGExtendedBugReportModeEnabledWithOptionalFields; |
| 124 | + [self.instabugBridge setExtendedBugReportMode:extendedBugReportMode]; |
| 125 | + XCTAssertEqual(IBGBugReporting.extendedBugReportMode, extendedBugReportMode); |
| 126 | +} |
| 127 | + |
| 128 | +- (void) testgivenArray$setReportTypes_whenQuery_thenShouldCallNativeApi { |
| 129 | + id mock = OCMClassMock([IBGBugReporting class]); |
| 130 | + NSArray *reportTypesArr = [NSArray arrayWithObjects: @(IBGReportTypeBug), nil]; |
| 131 | + IBGBugReportingReportType reportTypes = 0; |
| 132 | + for (NSNumber *boxedValue in reportTypesArr) { |
| 133 | + reportTypes |= [boxedValue intValue]; |
| 134 | + } |
| 135 | + OCMStub([mock setPromptOptionsEnabledReportTypes:reportTypes]); |
| 136 | + [self.instabugBridge setReportTypes:reportTypesArr]; |
| 137 | + OCMVerify([mock setPromptOptionsEnabledReportTypes:reportTypes]); |
| 138 | +} |
| 139 | + |
| 140 | + |
| 141 | +- (void) testgivenArgs$showBugReportingWithReportTypeAndOptions_whenQuery_thenShouldCallNativeApi { |
| 142 | + id mock = OCMClassMock([IBGBugReporting class]); |
| 143 | + IBGBugReportingReportType reportType = IBGBugReportingReportTypeBug; |
| 144 | + NSArray *options = [NSArray arrayWithObjects: @(IBGBugReportingOptionEmailFieldOptional), nil]; |
| 145 | + IBGBugReportingOption parsedOptions = 0; |
| 146 | + for (NSNumber *boxedValue in options) { |
| 147 | + parsedOptions |= [boxedValue intValue]; |
| 148 | + } |
| 149 | + OCMStub([mock showWithReportType:reportType options:parsedOptions]); |
| 150 | + [self.instabugBridge show:reportType options:options]; |
| 151 | + |
| 152 | + XCTestExpectation *expectation = [self expectationWithDescription:@"Test ME PLX"]; |
| 153 | + |
| 154 | + [[NSRunLoop mainRunLoop] performBlock:^{ |
| 155 | + OCMVerify([mock showWithReportType:reportType options:parsedOptions]); |
| 156 | + [expectation fulfill]; |
| 157 | + }]; |
| 158 | + |
| 159 | + [self waitForExpectationsWithTimeout:EXPECTATION_TIMEOUT handler:nil]; |
| 160 | +} |
| 161 | + |
| 162 | +- (void) testgivenBoolean$setAutoScreenRecordingEnabled_whenQuery_thenShouldCallNativeApi { |
| 163 | + BOOL enabled = true; |
| 164 | + [self.instabugBridge setAutoScreenRecordingEnabled:enabled]; |
| 165 | + XCTAssertTrue(IBGBugReporting.autoScreenRecordingEnabled); |
| 166 | +} |
| 167 | + |
| 168 | +- (void) testgivenArgs$setAutoScreenRecordingMaxDuration_whenQuery_thenShouldCallNativeApi { |
| 169 | + CGFloat duration = 12.3; |
| 170 | + [self.instabugBridge setAutoScreenRecordingMaxDuration:duration]; |
| 171 | + XCTAssertEqual(IBGBugReporting.autoScreenRecordingDuration, duration); |
| 172 | +} |
| 173 | + |
| 174 | +- (void) testgivenBoolean$setViewHierarchyEnabled_whenQuery_thenShouldCallNativeApi { |
| 175 | + BOOL enabled = true; |
| 176 | + [self.instabugBridge setViewHierarchyEnabled:enabled]; |
| 177 | + XCTAssertTrue(IBGBugReporting.shouldCaptureViewHierarchy); |
| 178 | +} |
| 179 | + |
| 180 | +@end |
| 181 | + |
0 commit comments