SDA-3936: BI

This commit is contained in:
NguyenTranHoangSym 2022-11-10 22:44:52 +07:00 committed by Salah Benmoussati
parent 439ee68d5d
commit fea9df0f49
3 changed files with 70 additions and 7 deletions

View File

@ -8,6 +8,7 @@ jest.mock('save-svg-as-png', function () {
import { mount, shallow } from 'enzyme'; import { mount, shallow } from 'enzyme';
import * as React from 'react'; import * as React from 'react';
import { ScreenSnippetActionTypes } from '../src/app/analytics-handler';
import { ScreenShotAnnotation } from '../src/common/ipcEvent'; import { ScreenShotAnnotation } from '../src/common/ipcEvent';
import SnippingTool from '../src/renderer/components/snipping-tool'; import SnippingTool from '../src/renderer/components/snipping-tool';
import { ipcRenderer } from './__mocks__/electron'; import { ipcRenderer } from './__mocks__/electron';
@ -15,11 +16,11 @@ import { ipcRenderer } from './__mocks__/electron';
const waitForPromisesToResolve = () => const waitForPromisesToResolve = () =>
new Promise((resolve) => setTimeout(resolve)); new Promise((resolve) => setTimeout(resolve));
afterEach(() => {
jest.clearAllMocks();
});
describe('Snipping Tool', () => { describe('Snipping Tool', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should render correctly', () => { it('should render correctly', () => {
const wrapper = shallow(React.createElement(SnippingTool)); const wrapper = shallow(React.createElement(SnippingTool));
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
@ -44,7 +45,7 @@ describe('Snipping Tool', () => {
it('should send capture_sent BI event when clicking done', async () => { it('should send capture_sent BI event when clicking done', async () => {
const spy = jest.spyOn(ipcRenderer, 'send'); const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { const expectedValue = {
type: 'annotate_done', type: ScreenSnippetActionTypes.ANNOTATE_ADD,
element: 'screen_capture_annotate', element: 'screen_capture_annotate',
}; };
const wrapper = mount(React.createElement(SnippingTool)); const wrapper = mount(React.createElement(SnippingTool));
@ -54,6 +55,53 @@ describe('Snipping Tool', () => {
expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); 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 () => { it('should send annotate_cleared BI event when clicking clear', async () => {
const spy = jest.spyOn(ipcRenderer, 'send'); const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { const expectedValue = {

View File

@ -30,9 +30,12 @@ export enum ScreenSnippetActionTypes {
SCREENSHOT_TAKEN = 'screenshot_taken', SCREENSHOT_TAKEN = 'screenshot_taken',
ANNOTATE_ADDED_PEN = 'annotate_added_pen', ANNOTATE_ADDED_PEN = 'annotate_added_pen',
ANNOTATE_ADDED_HIGHLIGHT = 'annotate_added_highlight', ANNOTATE_ADDED_HIGHLIGHT = 'annotate_added_highlight',
ANNOTATE_DONE = 'annotate_done', ANNOTATE_ADD = 'annotate_done',
ANNOTATE_CLEARED = 'annotate_cleared', ANNOTATE_CLEARED = 'annotate_cleared',
ANNOTATE_ERASED = 'annotate_erased', ANNOTATE_ERASED = 'annotate_erased',
ANNOTATE_COPY = 'annotate_copy',
ANNOTATE_SAVE_AS = 'annotate_save_as',
ANNOTATE_CLOSE = 'annotate_close',
} }
export enum ToastNotificationActionTypes { export enum ToastNotificationActionTypes {

View File

@ -103,6 +103,10 @@ const SnippingTool: React.FunctionComponent<ISnippingToolProps> = ({
const onCopyToClipboard = async (eventName) => { const onCopyToClipboard = async (eventName) => {
const img = await mergeImage(); const img = await mergeImage();
sendAnalyticsToMain(
AnalyticsElements.SCREEN_CAPTURE_ANNOTATE,
ScreenSnippetActionTypes.ANNOTATE_COPY,
);
ipcRenderer.send(eventName, { ipcRenderer.send(eventName, {
clipboard: img, clipboard: img,
}); });
@ -110,6 +114,10 @@ const SnippingTool: React.FunctionComponent<ISnippingToolProps> = ({
const onSaveAs = async (eventName) => { const onSaveAs = async (eventName) => {
const img = await mergeImage(); const img = await mergeImage();
sendAnalyticsToMain(
AnalyticsElements.SCREEN_CAPTURE_ANNOTATE,
ScreenSnippetActionTypes.ANNOTATE_SAVE_AS,
);
ipcRenderer.send(eventName, { ipcRenderer.send(eventName, {
clipboard: img, clipboard: img,
}); });
@ -270,12 +278,16 @@ const SnippingTool: React.FunctionComponent<ISnippingToolProps> = ({
: 'MERGE_FAIL'; : 'MERGE_FAIL';
sendAnalyticsToMain( sendAnalyticsToMain(
AnalyticsElements.SCREEN_CAPTURE_ANNOTATE, AnalyticsElements.SCREEN_CAPTURE_ANNOTATE,
ScreenSnippetActionTypes.ANNOTATE_DONE, ScreenSnippetActionTypes.ANNOTATE_ADD,
); );
ipcRenderer.send('upload-snippet', { screenSnippetPath, mergedImageData }); ipcRenderer.send('upload-snippet', { screenSnippetPath, mergedImageData });
}; };
const onClose = async () => { const onClose = async () => {
sendAnalyticsToMain(
AnalyticsElements.SCREEN_CAPTURE_ANNOTATE,
ScreenSnippetActionTypes.ANNOTATE_CLOSE,
);
ipcRenderer.send(ScreenShotAnnotation.CLOSE); ipcRenderer.send(ScreenShotAnnotation.CLOSE);
}; };