mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 01:11:13 -06:00
SDA-3936: BI
This commit is contained in:
parent
439ee68d5d
commit
fea9df0f49
@ -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 = {
|
||||
|
@ -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 {
|
||||
|
@ -103,6 +103,10 @@ const SnippingTool: React.FunctionComponent<ISnippingToolProps> = ({
|
||||
|
||||
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<ISnippingToolProps> = ({
|
||||
|
||||
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<ISnippingToolProps> = ({
|
||||
: '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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user