|
| 1 | +/** |
| 2 | + * @format |
| 3 | + * @lint-ignore-every XPLATJSCOPYRIGHT1 |
| 4 | + */ |
| 5 | + |
| 6 | +import "react-native"; |
| 7 | +import { NativeModules } from "react-native"; |
| 8 | +import "../jest/mockAPM"; |
| 9 | +import APM from "../modules/APM"; |
| 10 | +import sinon from "sinon"; |
| 11 | + |
| 12 | +import IBGConstants from "../utils/InstabugConstants"; |
| 13 | +import IBGEventEmitter from "../utils/IBGEventEmitter"; |
| 14 | + |
| 15 | +describe("APM Module", () => { |
| 16 | + const setEnabled = sinon.spy(NativeModules.IBGAPM, "setEnabled"); |
| 17 | + const setAppLaunchEnabled = sinon.spy(NativeModules.IBGAPM, "setAppLaunchEnabled"); |
| 18 | + const setLogLevel = sinon.spy(NativeModules.IBGAPM, "setLogLevel"); |
| 19 | + const setAutoUITraceEnabled = sinon.spy(NativeModules.IBGAPM, "setAutoUITraceEnabled"); |
| 20 | + const startExecutionTrace = sinon.spy(NativeModules.IBGAPM, "startExecutionTrace"); |
| 21 | + const setExecutionTraceAttribute = sinon.spy(NativeModules.IBGAPM, "setExecutionTraceAttribute"); |
| 22 | + const endExecutionTrace = sinon.spy(NativeModules.IBGAPM, "endExecutionTrace"); |
| 23 | + const startUITrace = sinon.spy(NativeModules.IBGAPM, "startUITrace"); |
| 24 | + const endUITrace = sinon.spy(NativeModules.IBGAPM, "endUITrace"); |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + // setWillShowSurveyHandler.resetHistory(); |
| 28 | + // setDidDismissSurveyHandler.resetHistory(); |
| 29 | + IBGEventEmitter.removeAllListeners(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should call the native method setEnabled", () => { |
| 33 | + APM.setEnabled(true); |
| 34 | + |
| 35 | + expect(setEnabled.calledOnceWithExactly(true)).toBe(true); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should call the native method setAppLaunchEnabled", () => { |
| 39 | + APM.setAppLaunchEnabled(true); |
| 40 | + |
| 41 | + expect(setAppLaunchEnabled.calledOnceWithExactly(true)).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should call the native method setAutoUITraceEnabled", () => { |
| 45 | + APM.setAutoUITraceEnabled(true); |
| 46 | + |
| 47 | + expect(setAutoUITraceEnabled.calledOnceWithExactly(true)).toBe(true); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should call the native method setLogLevel", () => { |
| 51 | + APM.setLogLevel(APM.logLevel.verbose); |
| 52 | + |
| 53 | + expect(setLogLevel.calledOnceWithExactly(APM.logLevel.verbose)).toBe(true); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should call the native method startExecutionTrace", () => { |
| 57 | + APM.startExecutionTrace("trace"); |
| 58 | + |
| 59 | + expect(startExecutionTrace.calledOnceWith("trace")).toBe(true); |
| 60 | + }); |
| 61 | + |
| 62 | + it("should call the native method setExecutionTraceAttribute", () => { |
| 63 | + const trace = APM.startExecutionTrace("trace").then(() => { |
| 64 | + trace.setAttribute("key", "value"); |
| 65 | + expect(setExecutionTraceAttribute.calledOnceWithExactly(expect.any(String), "key", "value")).toBe(true); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should call the native method endExecutionTrace", () => { |
| 70 | + const trace = APM.startExecutionTrace("trace").then(() => { |
| 71 | + trace.end(); |
| 72 | + expect(endExecutionTrace.calledOnceWithExactly(expect.any(String))).toBe(true); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + it("should call the native method startUITrace", () => { |
| 77 | + APM.startUITrace("uiTrace"); |
| 78 | + |
| 79 | + expect(startUITrace.calledOnceWithExactly("uiTrace")).toBe(true); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should call the native method endUITrace", () => { |
| 83 | + APM.endUITrace(); |
| 84 | + |
| 85 | + expect(endUITrace.calledOnceWithExactly()).toBe(true); |
| 86 | + }); |
| 87 | + |
| 88 | + // it("should call the native method setAppStoreURL", () => { |
| 89 | + // Surveys.setAppStoreURL("URL"); |
| 90 | + |
| 91 | + // expect(setAppStoreURL.calledOnceWithExactly("URL")).toBe(true); |
| 92 | + // }); |
| 93 | + |
| 94 | + // it("should call the native method showSurveysIfAvailable", () => { |
| 95 | + // Surveys.showSurveyIfAvailable(); |
| 96 | + |
| 97 | + // expect(showSurveysIfAvailable.calledOnce).toBe(true); |
| 98 | + // }); |
| 99 | + |
| 100 | + // it("should call the native method setThresholdForReshowingSurveyAfterDismiss", () => { |
| 101 | + // const sessionCount = 2; |
| 102 | + // const daysCount = 3; |
| 103 | + // Surveys.setThresholdForReshowingSurveyAfterDismiss(sessionCount, daysCount); |
| 104 | + |
| 105 | + // expect( |
| 106 | + // setThresholdForReshowingSurveyAfterDismiss.calledOnceWithExactly( |
| 107 | + // sessionCount, |
| 108 | + // daysCount |
| 109 | + // ) |
| 110 | + // ).toBe(true); |
| 111 | + // }); |
| 112 | + |
| 113 | + // it("should call the native method getAvailableSurveys", () => { |
| 114 | + // const callback = jest.fn(); |
| 115 | + // Surveys.getAvailableSurveys(callback); |
| 116 | + |
| 117 | + // expect(getAvailableSurveys.calledOnceWithExactly(callback)).toBe(true); |
| 118 | + // }); |
| 119 | + |
| 120 | + // it("should call the native method setAutoShowingSurveysEnabled", () => { |
| 121 | + // Surveys.setAutoShowingEnabled(true); |
| 122 | + |
| 123 | + // expect(setAutoShowingSurveysEnabled.calledOnceWithExactly(true)).toBe(true); |
| 124 | + // }); |
| 125 | + |
| 126 | + // it("should call the native method setWillShowSurveyHandler with a function", () => { |
| 127 | + // const callback = jest.fn(); |
| 128 | + // Surveys.setOnShowHandler(callback); |
| 129 | + |
| 130 | + // expect(setWillShowSurveyHandler.calledOnceWithExactly(callback)).toBe(true); |
| 131 | + // }); |
| 132 | + |
| 133 | + // it("should invoke callback on emitting the event IBGWillShowSurvey", () => { |
| 134 | + // const callback = jest.fn(); |
| 135 | + // Surveys.setOnShowHandler(callback); |
| 136 | + // IBGEventEmitter.emit(IBGConstants.WILL_SHOW_SURVEY_HANDLER); |
| 137 | + |
| 138 | + // expect( |
| 139 | + // IBGEventEmitter.getListeners(IBGConstants.WILL_SHOW_SURVEY_HANDLER).length |
| 140 | + // ).toEqual(1); |
| 141 | + // expect(callback).toHaveBeenCalled(); |
| 142 | + // }); |
| 143 | + |
| 144 | + // it("should call the native method setDidDismissSurveyHandler with a function", () => { |
| 145 | + // const callback = jest.fn(); |
| 146 | + // Surveys.setOnDismissHandler(callback); |
| 147 | + |
| 148 | + // expect(setDidDismissSurveyHandler.calledOnceWithExactly(callback)).toBe( |
| 149 | + // true |
| 150 | + // ); |
| 151 | + // }); |
| 152 | + |
| 153 | + // it("should invoke callback on emitting the event IBGDidDismissSurvey", () => { |
| 154 | + // const callback = jest.fn(); |
| 155 | + // Surveys.setOnDismissHandler(callback); |
| 156 | + // IBGEventEmitter.emit(IBGConstants.DID_DISMISS_SURVEY_HANDLER); |
| 157 | + |
| 158 | + // expect( |
| 159 | + // IBGEventEmitter.getListeners(IBGConstants.DID_DISMISS_SURVEY_HANDLER) |
| 160 | + // .length |
| 161 | + // ).toEqual(1); |
| 162 | + // expect(callback).toHaveBeenCalled(); |
| 163 | + // }); |
| 164 | + |
| 165 | + // it("should call the native method showSurveyWithToken", () => { |
| 166 | + // const surveyToken = "HEU128JD"; |
| 167 | + // Surveys.showSurvey(surveyToken); |
| 168 | + |
| 169 | + // expect(showSurveyWithToken.calledOnceWithExactly(surveyToken)).toBe(true); |
| 170 | + // }); |
| 171 | + |
| 172 | + // it("should call the native method hasRespondedToSurveyWithToken", done => { |
| 173 | + // const callback = hasResponded => { |
| 174 | + // expect(hasResponded).toBe(true); |
| 175 | + // done(); |
| 176 | + // }; |
| 177 | + // const surveyToken = "HEU128JD"; |
| 178 | + // Surveys.hasRespondedToSurvey(surveyToken, callback); |
| 179 | + |
| 180 | + // expect( |
| 181 | + // hasRespondedToSurveyWithToken.calledOnceWithExactly(surveyToken, callback) |
| 182 | + // ).toBe(true); |
| 183 | + // }); |
| 184 | + |
| 185 | + // it("should call the native method setShouldShowSurveysWelcomeScreen", () => { |
| 186 | + // Surveys.setShouldShowWelcomeScreen(true); |
| 187 | + |
| 188 | + // expect(setShouldShowSurveysWelcomeScreen.calledOnceWithExactly(true)).toBe( |
| 189 | + // true |
| 190 | + // ); |
| 191 | + // }); |
| 192 | +}); |
0 commit comments