2022-11-07 03:26:36 -06:00
|
|
|
jest.mock('save-svg-as-png', function () {
|
|
|
|
return {
|
|
|
|
svgAsPngUri: async function (svg) {
|
|
|
|
return Promise.resolve(svg);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-11-19 02:17:39 -06:00
|
|
|
import { mount, shallow } from 'enzyme';
|
|
|
|
import * as React from 'react';
|
2022-11-10 09:44:52 -06:00
|
|
|
import { ScreenSnippetActionTypes } from '../src/app/analytics-handler';
|
2022-11-07 03:26:36 -06:00
|
|
|
import { ScreenShotAnnotation } from '../src/common/ipcEvent';
|
2020-11-19 02:17:39 -06:00
|
|
|
import SnippingTool from '../src/renderer/components/snipping-tool';
|
|
|
|
import { ipcRenderer } from './__mocks__/electron';
|
|
|
|
|
2021-01-29 00:25:40 -06:00
|
|
|
const waitForPromisesToResolve = () =>
|
|
|
|
new Promise((resolve) => setTimeout(resolve));
|
2020-11-19 02:17:39 -06:00
|
|
|
|
|
|
|
describe('Snipping Tool', () => {
|
2022-11-10 09:44:52 -06:00
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2020-11-19 02:17:39 -06:00
|
|
|
it('should render correctly', () => {
|
|
|
|
const wrapper = shallow(React.createElement(SnippingTool));
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set up a "once" listener for snipping-tool-data event on mounting', () => {
|
|
|
|
const spy = jest.spyOn(ipcRenderer, 'once');
|
2020-11-26 03:27:18 -06:00
|
|
|
mount(React.createElement(SnippingTool));
|
2020-11-19 02:17:39 -06:00
|
|
|
expect(spy).toBeCalledWith('snipping-tool-data', expect.any(Function));
|
|
|
|
});
|
|
|
|
|
2020-12-03 10:22:06 -06:00
|
|
|
it('should send screenshot_taken BI event on component mount', () => {
|
2020-12-10 06:18:23 -06:00
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
2021-01-29 00:25:40 -06:00
|
|
|
const expectedValue = {
|
|
|
|
type: 'screenshot_taken',
|
|
|
|
element: 'screen_capture_annotate',
|
|
|
|
};
|
2020-11-27 10:07:46 -06:00
|
|
|
mount(React.createElement(SnippingTool));
|
2020-12-18 07:11:15 -06:00
|
|
|
expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue);
|
2020-11-27 10:07:46 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should send capture_sent BI event when clicking done', async () => {
|
2020-12-10 06:18:23 -06:00
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
2021-01-29 00:25:40 -06:00
|
|
|
const expectedValue = {
|
2022-11-10 09:44:52 -06:00
|
|
|
type: ScreenSnippetActionTypes.ANNOTATE_ADD,
|
2021-01-29 00:25:40 -06:00
|
|
|
element: 'screen_capture_annotate',
|
|
|
|
};
|
2020-11-27 10:07:46 -06:00
|
|
|
const wrapper = mount(React.createElement(SnippingTool));
|
|
|
|
wrapper.find('[data-testid="done-button"]').simulate('click');
|
|
|
|
wrapper.update();
|
|
|
|
await waitForPromisesToResolve();
|
2020-12-18 07:11:15 -06:00
|
|
|
expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue);
|
2020-11-27 10:07:46 -06:00
|
|
|
});
|
|
|
|
|
2022-11-10 09:44:52 -06:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2020-12-03 10:22:06 -06:00
|
|
|
it('should send annotate_cleared BI event when clicking clear', async () => {
|
2020-12-10 06:18:23 -06:00
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
2021-01-29 00:25:40 -06:00
|
|
|
const expectedValue = {
|
|
|
|
type: 'annotate_cleared',
|
|
|
|
element: 'screen_capture_annotate',
|
|
|
|
};
|
2020-12-03 10:22:06 -06:00
|
|
|
const wrapper = mount(React.createElement(SnippingTool));
|
|
|
|
wrapper.find('[data-testid="clear-button"]').simulate('click');
|
|
|
|
wrapper.update();
|
|
|
|
await waitForPromisesToResolve();
|
2020-12-18 07:11:15 -06:00
|
|
|
expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue);
|
2020-12-03 10:22:06 -06:00
|
|
|
});
|
|
|
|
|
2020-11-19 02:17:39 -06:00
|
|
|
it('should render pen color picker when clicked on pen', () => {
|
|
|
|
const wrapper = shallow(React.createElement(SnippingTool));
|
|
|
|
wrapper.find('[data-testid="pen-button"]').simulate('click');
|
|
|
|
expect(wrapper.find('[data-testid="pen-colorpicker"]').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render highlight color picker when clicked on highlight', () => {
|
|
|
|
const wrapper = shallow(React.createElement(SnippingTool));
|
|
|
|
wrapper.find('[data-testid="highlight-button"]').simulate('click');
|
2021-01-29 00:25:40 -06:00
|
|
|
expect(wrapper.find('[data-testid="highlight-colorpicker"]').exists()).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2020-11-19 02:17:39 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should clear all paths when clicked on clear', () => {
|
|
|
|
const props = {
|
2021-01-29 00:25:40 -06:00
|
|
|
existingPaths: [
|
|
|
|
{
|
|
|
|
points: [{ x: 0, y: 0 }],
|
|
|
|
shouldShow: true,
|
|
|
|
strokeWidth: 5,
|
|
|
|
color: 'rgba(233, 0, 0, 0.64)',
|
|
|
|
key: 'path0',
|
|
|
|
},
|
|
|
|
],
|
2020-11-19 02:17:39 -06:00
|
|
|
};
|
|
|
|
const wrapper = mount(<SnippingTool {...props} />);
|
2021-01-29 00:25:40 -06:00
|
|
|
const annotateComponent = wrapper.find(
|
|
|
|
'[data-testid="annotate-component"]',
|
|
|
|
);
|
2020-11-19 02:17:39 -06:00
|
|
|
wrapper.find('[data-testid="clear-button"]').simulate('click');
|
|
|
|
wrapper.update();
|
2021-01-29 00:25:40 -06:00
|
|
|
expect(annotateComponent.prop('paths')).toEqual([
|
|
|
|
{
|
2020-11-19 02:17:39 -06:00
|
|
|
color: 'rgba(233, 0, 0, 0.64)',
|
|
|
|
key: 'path0',
|
|
|
|
points: [{ x: 0, y: 0 }],
|
|
|
|
shouldShow: false,
|
|
|
|
strokeWidth: 5,
|
2021-01-29 00:25:40 -06:00
|
|
|
},
|
|
|
|
]);
|
2020-11-19 02:17:39 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should send upload-snippet event with correct data when clicked on done', async () => {
|
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
|
|
|
const wrapper = mount(<SnippingTool />);
|
|
|
|
wrapper.find('[data-testid="done-button"]').simulate('click');
|
|
|
|
wrapper.update();
|
|
|
|
await waitForPromisesToResolve();
|
|
|
|
expect(spy).toBeCalledWith('upload-snippet', {
|
2020-12-01 09:35:29 -06:00
|
|
|
mergedImageData: 'MERGE_FAIL',
|
2020-11-26 03:27:18 -06:00
|
|
|
screenSnippetPath: '',
|
2020-11-19 02:17:39 -06:00
|
|
|
});
|
|
|
|
});
|
2022-11-07 03:26:36 -06:00
|
|
|
|
|
|
|
it('should send upload-snippet event with correct data when clicked on copy to clipboard', async () => {
|
|
|
|
const wrapper = mount(<SnippingTool />);
|
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
|
|
|
jest.spyOn(document, 'getElementById').mockImplementation((selector) => {
|
|
|
|
switch (selector) {
|
|
|
|
case 'annotate-area':
|
|
|
|
return '123';
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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(ScreenShotAnnotation.COPY_TO_CLIPBOARD, {
|
|
|
|
clipboard: '123',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should send upload-snippet event with correct data when clicked on save as', async () => {
|
|
|
|
const wrapper = mount(<SnippingTool />);
|
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
|
|
|
jest.spyOn(document, 'getElementById').mockImplementation((selector) => {
|
|
|
|
switch (selector) {
|
|
|
|
case 'annotate-area':
|
|
|
|
return '123';
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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(ScreenShotAnnotation.SAVE_AS, {
|
|
|
|
clipboard: '123',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should send upload-snippet event with correct data when clicked on close', async () => {
|
|
|
|
const wrapper = mount(<SnippingTool />);
|
|
|
|
const spy = jest.spyOn(ipcRenderer, 'send');
|
|
|
|
wrapper.find('[data-testid="close-button"]').simulate('click');
|
|
|
|
wrapper.update();
|
|
|
|
await waitForPromisesToResolve();
|
|
|
|
expect(spy).toBeCalledWith(ScreenShotAnnotation.CLOSE);
|
|
|
|
});
|
2020-11-19 02:17:39 -06:00
|
|
|
});
|