diff --git a/app/src/analytics/__tests__/make-event.test.js b/app/src/analytics/__tests__/make-event.test.js index c943096af45..4c4ea31375f 100644 --- a/app/src/analytics/__tests__/make-event.test.js +++ b/app/src/analytics/__tests__/make-event.test.js @@ -53,6 +53,22 @@ describe('analytics events map', () => { }) }) + test('robot:SESSION_RESPONSE error -> protocolUpload event', () => { + const state = {} + const success = {type: 'robot:SESSION_RESPONSE'} + const failure = {type: 'robot:SESSION_RESPONSE', error: new Error('AH')} + + expect(makeEvent(state, success)).toEqual({ + name: 'protocolUpload', + properties: {success: true, error: ''} + }) + + expect(makeEvent(state, failure)).toEqual({ + name: 'protocolUpload', + properties: {success: false, error: 'AH'} + }) + }) + test('robot:RUN -> runStart event', () => { const state = {} const action = {type: 'robot:RUN'} @@ -63,6 +79,59 @@ describe('analytics events map', () => { }) }) + test('robot:PAUSE_RESPONSE -> runPause event', () => { + const state = {} + const success = {type: 'robot:PAUSE_RESPONSE'} + const failure = {type: 'robot:PAUSE_RESPONSE', error: new Error('AH')} + + expect(makeEvent(state, success)).toEqual({ + name: 'runPause', + properties: { + success: true, + error: '' + } + }) + + expect(makeEvent(state, failure)).toEqual({ + name: 'runPause', + properties: { + success: false, + error: 'AH' + } + }) + }) + + test('robot:CANCEL_REPSONSE -> runCancel event', () => { + const state = { + robot: { + session: { + startTime: 1000, + runTime: 5000 + } + } + } + const success = {type: 'robot:CANCEL_RESPONSE'} + const failure = {type: 'robot:CANCEL_RESPONSE', error: new Error('AH')} + + expect(makeEvent(state, success)).toEqual({ + name: 'runCancel', + properties: { + runTime: 4, + success: true, + error: '' + } + }) + + expect(makeEvent(state, failure)).toEqual({ + name: 'runCancel', + properties: { + runTime: 4, + success: false, + error: 'AH' + } + }) + }) + test('robot:RUN_RESPONSE success -> runFinish event', () => { const state = { robot: { @@ -79,4 +148,14 @@ describe('analytics events map', () => { properties: {runTime: 4} }) }) + + test('robot:RUN_RESPONSE error -> runError event', () => { + const state = {} + const action = {type: 'robot:RUN_RESPONSE', error: new Error('AH')} + + expect(makeEvent(state, action)).toEqual({ + name: 'runError', + properties: {error: 'AH'} + }) + }) }) diff --git a/app/src/analytics/make-event.js b/app/src/analytics/make-event.js index 2a490421614..5697ef20f91 100644 --- a/app/src/analytics/make-event.js +++ b/app/src/analytics/make-event.js @@ -35,6 +35,17 @@ export default function makeEvent (state: State, action: Action): ?Event { } } + // $FlowFixMe(ka, 2018-06-5): flow type robot:SESSION_RESPONSE + case 'robot:SESSION_RESPONSE': + // TODO (ka, 2018-6-6): add file open type 'button' | 'drag-n-drop' (work required in action meta) + return { + name: 'protocolUpload', + properties: { + success: !action.error, + error: (action.error && action.error.message) || '' + } + } + // $FlowFixMe(mc, 2018-05-28): flow type robot:RUN case 'robot:RUN': return {name: 'runStart', properties: {}} @@ -45,8 +56,33 @@ export default function makeEvent (state: State, action: Action): ?Event { const runTime = robotSelectors.getRunSeconds(state) return {name: 'runFinish', properties: {runTime}} } else { - // TODO(mc, 2018-05-28): runError event - return null + return { + name: 'runError', + properties: { + error: action.error.message + } + } + } + // $FlowFixMe(ka, 2018-06-5): flow type robot:PAUSE_RESPONSE + case 'robot:PAUSE_RESPONSE': + return { + name: 'runPause', + properties: { + success: !action.error, + error: (action.error && action.error.message) || '' + } + } + + // $FlowFixMe(ka, 2018-06-5): flow type robot:CANCEL + case 'robot:CANCEL_RESPONSE': + const runTime = robotSelectors.getRunSeconds(state) + return { + name: 'runCancel', + properties: { + runTime, + success: !action.error, + error: (action.error && action.error.message) || '' + } } }