-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new session replay apis (#1034)
Jira ID: IBGCRASH-20006 --------- Co-authored-by: Ahmed Mahmoud <a7med.mahmoud2004@gmail.com>
- Loading branch information
1 parent
b8e19eb
commit 748ac40
Showing
15 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
android/src/main/java/com/instabug/reactlibrary/RNInstabugSessionReplayModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.instabug.reactlibrary; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.instabug.library.sessionreplay.SessionReplay; | ||
import com.instabug.reactlibrary.utils.MainThreadHandler; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class RNInstabugSessionReplayModule extends ReactContextBaseJavaModule { | ||
|
||
public RNInstabugSessionReplayModule(ReactApplicationContext reactApplicationContext) { | ||
super(reactApplicationContext); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getName() { | ||
return "IBGSessionReplay"; | ||
} | ||
|
||
@ReactMethod | ||
public void setEnabled(final boolean isEnabled) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
SessionReplay.setEnabled(isEnabled); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@ReactMethod | ||
public void setNetworkLogsEnabled(final boolean isEnabled) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
SessionReplay.setNetworkLogsEnabled(isEnabled); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
@ReactMethod | ||
public void setInstabugLogsEnabled(final boolean isEnabled) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
SessionReplay.setIBGLogsEnabled(isEnabled); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@ReactMethod | ||
public void setUserStepsEnabled(final boolean isEnabled) { | ||
MainThreadHandler.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
SessionReplay.setUserStepsEnabled(isEnabled); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
android/src/test/java/com/instabug/reactlibrary/RNInstabugSessionReplayModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.instabug.reactlibrary; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import android.os.Looper; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.JavaOnlyArray; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.WritableArray; | ||
import com.instabug.featuresrequest.ActionType; | ||
import com.instabug.featuresrequest.FeatureRequests; | ||
import com.instabug.library.Feature; | ||
import com.instabug.library.sessionreplay.SessionReplay; | ||
import com.instabug.reactlibrary.utils.MainThreadHandler; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
|
||
public class RNInstabugSessionReplayModuleTest { | ||
private RNInstabugSessionReplayModule sessionReplayModule = new RNInstabugSessionReplayModule(null); | ||
|
||
private final static ScheduledExecutorService mainThread = Executors.newSingleThreadScheduledExecutor(); | ||
|
||
// Mock Objects | ||
private MockedStatic<Looper> mockLooper; | ||
private MockedStatic <MainThreadHandler> mockMainThreadHandler; | ||
private MockedStatic <SessionReplay> mockSessionReplay; | ||
|
||
@Before | ||
public void mockMainThreadHandler() throws Exception { | ||
// Mock static functions | ||
mockSessionReplay = mockStatic(SessionReplay.class); | ||
mockLooper = mockStatic(Looper.class); | ||
mockMainThreadHandler = mockStatic(MainThreadHandler.class); | ||
|
||
// Mock Looper class | ||
Looper mockMainThreadLooper = Mockito.mock(Looper.class); | ||
Mockito.when(Looper.getMainLooper()).thenReturn(mockMainThreadLooper); | ||
|
||
// Override runOnMainThread | ||
Answer<Boolean> handlerPostAnswer = new Answer<Boolean>() { | ||
@Override | ||
public Boolean answer(InvocationOnMock invocation) throws Throwable { | ||
invocation.getArgument(0, Runnable.class).run(); | ||
return true; | ||
} | ||
}; | ||
Mockito.doAnswer(handlerPostAnswer).when(MainThreadHandler.class); | ||
MainThreadHandler.runOnMainThread(any(Runnable.class)); | ||
} | ||
@After | ||
public void tearDown() { | ||
// Remove static mocks | ||
mockLooper.close(); | ||
mockMainThreadHandler.close(); | ||
mockSessionReplay.close(); | ||
} | ||
|
||
@Test | ||
public void testSetEnabled() { | ||
|
||
sessionReplayModule.setEnabled(true); | ||
|
||
mockSessionReplay.verify(() -> SessionReplay.setEnabled(true)); | ||
mockSessionReplay.verifyNoMoreInteractions(); | ||
} | ||
|
||
@Test | ||
public void testSetNetworkLogsEnabled() { | ||
|
||
sessionReplayModule.setNetworkLogsEnabled(true); | ||
|
||
mockSessionReplay.verify(() -> SessionReplay.setNetworkLogsEnabled(true)); | ||
mockSessionReplay.verifyNoMoreInteractions(); | ||
} | ||
|
||
@Test | ||
public void testSetInstabugLogsEnabled() { | ||
|
||
sessionReplayModule.setInstabugLogsEnabled(true); | ||
|
||
mockSessionReplay.verify(() -> SessionReplay.setIBGLogsEnabled(true)); | ||
mockSessionReplay.verifyNoMoreInteractions(); | ||
} | ||
|
||
@Test | ||
public void testSetUserStepsEnabled() { | ||
|
||
sessionReplayModule.setUserStepsEnabled(true); | ||
|
||
mockSessionReplay.verify(() -> SessionReplay.setUserStepsEnabled(true)); | ||
mockSessionReplay.verifyNoMoreInteractions(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
examples/default/ios/InstabugTests/InstabugSessionReplayTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "OCMock/OCMock.h" | ||
#import "InstabugSessionReplayBridge.h" | ||
#import <Instabug/IBGTypes.h> | ||
#import "Instabug/Instabug.h" | ||
#import "IBGConstants.h" | ||
|
||
@interface InstabugSessionReplayTests : XCTestCase | ||
|
||
@property (nonatomic, strong) id mSessionReplay; | ||
@property (nonatomic, strong) InstabugSessionReplayBridge *bridge; | ||
|
||
@end | ||
|
||
@implementation InstabugSessionReplayTests | ||
|
||
|
||
- (void)setUp { | ||
self.mSessionReplay = OCMClassMock([IBGSessionReplay class]); | ||
self.bridge = [[InstabugSessionReplayBridge alloc] init]; | ||
} | ||
|
||
- (void)testSetEnabled { | ||
BOOL enabled = NO; | ||
|
||
[self.bridge setEnabled:enabled]; | ||
|
||
OCMVerify([self.mSessionReplay setEnabled:enabled]); | ||
} | ||
|
||
- (void)testSetInstabugLogsEnabled { | ||
BOOL enabled = NO; | ||
|
||
[self.bridge setInstabugLogsEnabled:enabled]; | ||
|
||
OCMVerify([self.mSessionReplay setIBGLogsEnabled:enabled]); | ||
} | ||
|
||
- (void)testSetNetworkLogsEnabled { | ||
BOOL enabled = NO; | ||
|
||
[self.bridge setNetworkLogsEnabled:enabled]; | ||
|
||
OCMVerify([self.mSessionReplay setNetworkLogsEnabled:enabled]); | ||
} | ||
|
||
- (void)testSetUserStepsEnabled { | ||
BOOL enabled = NO; | ||
|
||
[self.bridge setUserStepsEnabled:enabled]; | ||
|
||
OCMVerify([self.mSessionReplay setUserStepsEnabled:enabled]); | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
#import <Instabug/IBGTypes.h> | ||
|
||
@interface InstabugSessionReplayBridge : RCTEventEmitter <RCTBridgeModule> | ||
/* | ||
+------------------------------------------------------------------------+ | ||
| Session Replay Module | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
- (void)setEnabled:(BOOL)isEnabled; | ||
|
||
- (void)setInstabugLogsEnabled:(BOOL)isEnabled; | ||
|
||
- (void)setNetworkLogsEnabled:(BOOL)isEnabled; | ||
|
||
- (void)setUserStepsEnabled:(BOOL)isEnabled; | ||
|
||
|
||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#import <asl.h> | ||
#import <React/RCTLog.h> | ||
#import <os/log.h> | ||
#import <Instabug/IBGTypes.h> | ||
#import <React/RCTUIManager.h> | ||
#import <Instabug/IBGSessionReplay.h> | ||
#import "InstabugSessionReplayBridge.h" | ||
|
||
@implementation InstabugSessionReplayBridge | ||
|
||
- (dispatch_queue_t)methodQueue { | ||
return dispatch_get_main_queue(); | ||
} | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return NO; | ||
} | ||
|
||
- (NSArray<NSString *> *)supportedEvents { | ||
return @[]; | ||
} | ||
|
||
RCT_EXPORT_MODULE(IBGSessionReplay) | ||
|
||
RCT_EXPORT_METHOD(setEnabled:(BOOL)isEnabled) { | ||
IBGSessionReplay.enabled = isEnabled; | ||
} | ||
|
||
RCT_EXPORT_METHOD(setNetworkLogsEnabled:(BOOL)isEnabled) { | ||
IBGSessionReplay.networkLogsEnabled = isEnabled; | ||
} | ||
|
||
RCT_EXPORT_METHOD(setInstabugLogsEnabled:(BOOL)isEnabled) { | ||
IBGSessionReplay.IBGLogsEnabled = isEnabled; | ||
} | ||
|
||
RCT_EXPORT_METHOD(setUserStepsEnabled:(BOOL)isEnabled) { | ||
IBGSessionReplay.userStepsEnabled = isEnabled; | ||
} | ||
|
||
@synthesize description; | ||
|
||
@synthesize hash; | ||
|
||
@synthesize superclass; | ||
|
||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.