From fea9df0f4922eb270a19c40a9d63c3eca941c7c0 Mon Sep 17 00:00:00 2001 From: NguyenTranHoangSym Date: Thu, 10 Nov 2022 22:44:52 +0700 Subject: [PATCH] SDA-3936: BI --- spec/snippingTool.spec.tsx | 58 +++++++++++++++++++++-- src/app/analytics-handler.ts | 5 +- src/renderer/components/snipping-tool.tsx | 14 +++++- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/spec/snippingTool.spec.tsx b/spec/snippingTool.spec.tsx index f0837dd3..0207c3ac 100644 --- a/spec/snippingTool.spec.tsx +++ b/spec/snippingTool.spec.tsx @@ -8,6 +8,7 @@ jest.mock('save-svg-as-png', function () { import { mount, shallow } from 'enzyme'; import * as React from 'react'; +import { ScreenSnippetActionTypes } from '../src/app/analytics-handler'; import { ScreenShotAnnotation } from '../src/common/ipcEvent'; import SnippingTool from '../src/renderer/components/snipping-tool'; import { ipcRenderer } from './__mocks__/electron'; @@ -15,11 +16,11 @@ import { ipcRenderer } from './__mocks__/electron'; const waitForPromisesToResolve = () => new Promise((resolve) => setTimeout(resolve)); -afterEach(() => { - jest.clearAllMocks(); -}); - describe('Snipping Tool', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + it('should render correctly', () => { const wrapper = shallow(React.createElement(SnippingTool)); expect(wrapper).toMatchSnapshot(); @@ -44,7 +45,7 @@ describe('Snipping Tool', () => { it('should send capture_sent BI event when clicking done', async () => { const spy = jest.spyOn(ipcRenderer, 'send'); const expectedValue = { - type: 'annotate_done', + type: ScreenSnippetActionTypes.ANNOTATE_ADD, element: 'screen_capture_annotate', }; const wrapper = mount(React.createElement(SnippingTool)); @@ -54,6 +55,53 @@ describe('Snipping Tool', () => { expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); + it('should send capture_sent BI event when clicking copy to clipboard', async () => { + const spy = jest.spyOn(ipcRenderer, 'send'); + const expectedValue = { + type: ScreenSnippetActionTypes.ANNOTATE_COPY, + element: 'screen_capture_annotate', + }; + const wrapper = mount(React.createElement(SnippingTool)); + wrapper.find('[data-testid="snipping-tool_MENU_BUTTON"]').simulate('click'); + wrapper.update(); + await waitForPromisesToResolve(); + wrapper + .find('[data-testid="snipping-tool_COPY_TO_CLIPBOARD"]') + .simulate('click'); + wrapper.update(); + await waitForPromisesToResolve(); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); + }); + + it('should send capture_sent BI event when clicking save as', async () => { + const spy = jest.spyOn(ipcRenderer, 'send'); + const expectedValue = { + type: ScreenSnippetActionTypes.ANNOTATE_SAVE_AS, + element: 'screen_capture_annotate', + }; + const wrapper = mount(React.createElement(SnippingTool)); + wrapper.find('[data-testid="snipping-tool_MENU_BUTTON"]').simulate('click'); + wrapper.update(); + await waitForPromisesToResolve(); + wrapper.find('[data-testid="snipping-tool_SAVE_AS"]').simulate('click'); + wrapper.update(); + await waitForPromisesToResolve(); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); + }); + + it('should send capture_sent BI event when clicking done', async () => { + const spy = jest.spyOn(ipcRenderer, 'send'); + const expectedValue = { + type: ScreenSnippetActionTypes.ANNOTATE_CLOSE, + element: 'screen_capture_annotate', + }; + const wrapper = mount(React.createElement(SnippingTool)); + wrapper.find('[data-testid="close-button"]').simulate('click'); + wrapper.update(); + await waitForPromisesToResolve(); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); + }); + it('should send annotate_cleared BI event when clicking clear', async () => { const spy = jest.spyOn(ipcRenderer, 'send'); const expectedValue = { diff --git a/src/app/analytics-handler.ts b/src/app/analytics-handler.ts index 37328dd3..b050443f 100644 --- a/src/app/analytics-handler.ts +++ b/src/app/analytics-handler.ts @@ -30,9 +30,12 @@ export enum ScreenSnippetActionTypes { SCREENSHOT_TAKEN = 'screenshot_taken', ANNOTATE_ADDED_PEN = 'annotate_added_pen', ANNOTATE_ADDED_HIGHLIGHT = 'annotate_added_highlight', - ANNOTATE_DONE = 'annotate_done', + ANNOTATE_ADD = 'annotate_done', ANNOTATE_CLEARED = 'annotate_cleared', ANNOTATE_ERASED = 'annotate_erased', + ANNOTATE_COPY = 'annotate_copy', + ANNOTATE_SAVE_AS = 'annotate_save_as', + ANNOTATE_CLOSE = 'annotate_close', } export enum ToastNotificationActionTypes { diff --git a/src/renderer/components/snipping-tool.tsx b/src/renderer/components/snipping-tool.tsx index 6a7c5cf3..090a5037 100644 --- a/src/renderer/components/snipping-tool.tsx +++ b/src/renderer/components/snipping-tool.tsx @@ -103,6 +103,10 @@ const SnippingTool: React.FunctionComponent = ({ const onCopyToClipboard = async (eventName) => { const img = await mergeImage(); + sendAnalyticsToMain( + AnalyticsElements.SCREEN_CAPTURE_ANNOTATE, + ScreenSnippetActionTypes.ANNOTATE_COPY, + ); ipcRenderer.send(eventName, { clipboard: img, }); @@ -110,6 +114,10 @@ const SnippingTool: React.FunctionComponent = ({ const onSaveAs = async (eventName) => { const img = await mergeImage(); + sendAnalyticsToMain( + AnalyticsElements.SCREEN_CAPTURE_ANNOTATE, + ScreenSnippetActionTypes.ANNOTATE_SAVE_AS, + ); ipcRenderer.send(eventName, { clipboard: img, }); @@ -270,12 +278,16 @@ const SnippingTool: React.FunctionComponent = ({ : 'MERGE_FAIL'; sendAnalyticsToMain( AnalyticsElements.SCREEN_CAPTURE_ANNOTATE, - ScreenSnippetActionTypes.ANNOTATE_DONE, + ScreenSnippetActionTypes.ANNOTATE_ADD, ); ipcRenderer.send('upload-snippet', { screenSnippetPath, mergedImageData }); }; const onClose = async () => { + sendAnalyticsToMain( + AnalyticsElements.SCREEN_CAPTURE_ANNOTATE, + ScreenSnippetActionTypes.ANNOTATE_CLOSE, + ); ipcRenderer.send(ScreenShotAnnotation.CLOSE); };