SDA-2751 Fixed UTs

This commit is contained in:
psjostrom 2020-12-10 13:18:23 +01:00
parent 4ab878cbfb
commit 4d9f3fc9ee
2 changed files with 19 additions and 20 deletions

View File

@ -2,7 +2,7 @@ import { mount } from 'enzyme';
import * as React from 'react';
import AnnotateArea from '../src/renderer/components/annotate-area';
import { Tool } from '../src/renderer/components/snipping-tool';
import * as analyticsHandler from './../src/app/analytics-handler';
import { ipcRenderer } from './__mocks__/electron';
const defaultProps = {
paths: [],
@ -127,7 +127,7 @@ describe('<AnnotateArea/>', () => {
});
it('should send annotate_erased if clicked on path with tool eraser', () => {
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const spy = jest.spyOn(ipcRenderer, 'send');
const pathProps = {
paths: [{
points: [{ x: 0, y: 0 }],
@ -146,19 +146,19 @@ describe('<AnnotateArea/>', () => {
};
const wrapper = mount(<AnnotateArea {...pathProps} />);
const path = wrapper.find('[data-testid="path0"]');
const expectedValue = { action_type: 'annotate_erased', element: 'screen_capture_annotate' };
const expectedValue = { type: 'annotate_erased', element: 'screen_capture_annotate' };
path.simulate('click');
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
it('should send annotate_added_pen event when drawn with pen', () => {
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const expectedValue = { action_type: 'annotate_added_pen', element: 'screen_capture_annotate' };
const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { type: 'annotate_added_pen', element: 'screen_capture_annotate' };
const wrapper = mount(<AnnotateArea {...defaultProps} />);
const area = wrapper.find('[data-testid="annotate-area"]');
area.simulate('mousedown', { pageX: 2, pageY: 49 });
area.simulate('mouseup');
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
it('should send annotate_added_highlight event when drawn with highlight', () => {
@ -172,12 +172,12 @@ describe('<AnnotateArea/>', () => {
chosenTool: Tool.highlight,
screenSnippetPath: 'very-nice-path',
};
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const expectedValue = { action_type: 'annotate_added_highlight', element: 'screen_capture_annotate' };
const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { type: 'annotate_added_highlight', element: 'screen_capture_annotate' };
const wrapper = mount(<AnnotateArea {...highlightProps} />);
const area = wrapper.find('[data-testid="annotate-area"]');
area.simulate('mousedown', { pageX: 2, pageY: 49 });
area.simulate('mouseup');
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
});

View File

@ -1,7 +1,6 @@
import { mount, shallow } from 'enzyme';
import * as React from 'react';
import SnippingTool from '../src/renderer/components/snipping-tool';
import * as analyticsHandler from './../src/app/analytics-handler';
import { ipcRenderer } from './__mocks__/electron';
const waitForPromisesToResolve = () => new Promise((resolve) => setTimeout(resolve));
@ -23,30 +22,30 @@ describe('Snipping Tool', () => {
});
it('should send screenshot_taken BI event on component mount', () => {
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const expectedValue = { action_type: 'screenshot_taken', element: 'screen_capture_annotate' };
const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { type: 'screenshot_taken', element: 'screen_capture_annotate' };
mount(React.createElement(SnippingTool));
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
it('should send capture_sent BI event when clicking done', async () => {
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const expectedValue = { action_type: 'annotate_done', element: 'screen_capture_annotate' };
const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { type: 'annotate_done', element: 'screen_capture_annotate' };
const wrapper = mount(React.createElement(SnippingTool));
wrapper.find('[data-testid="done-button"]').simulate('click');
wrapper.update();
await waitForPromisesToResolve();
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
it('should send annotate_cleared BI event when clicking clear', async () => {
const spy = jest.spyOn(analyticsHandler.analytics, 'track');
const expectedValue = { action_type: 'annotate_cleared', element: 'screen_capture_annotate' };
const spy = jest.spyOn(ipcRenderer, 'send');
const expectedValue = { type: 'annotate_cleared', element: 'screen_capture_annotate' };
const wrapper = mount(React.createElement(SnippingTool));
wrapper.find('[data-testid="clear-button"]').simulate('click');
wrapper.update();
await waitForPromisesToResolve();
expect(spy).toBeCalledWith(expectedValue);
expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue);
});
it('should render pen color picker when clicked on pen', () => {