Skip to content

Commit

Permalink
fixed license block dates; moved debounce from tracking module to com…
Browse files Browse the repository at this point in the history
…ponent
  • Loading branch information
VladislavBryukhanov committed May 11, 2022
1 parent 89fbba9 commit bebe985
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const state = {
const props = mapStateToProps(state);

Date.now = jest.fn(() => 1487076708000); // Tue, 14 Feb 2017 12:51:48 GMT'
jest.mock('lodash/debounce', () => fn => fn);

describe('<MonitorATMServicesView>', () => {
let wrapper;
Expand Down Expand Up @@ -303,20 +304,21 @@ describe('<MonitorATMServicesView>', () => {
).not.toBeNull();
});

it('Should track all events', () => {
it('Should track all events', async () => {
const trackSelectServiceSpy = jest.spyOn(track, 'trackSelectService');
const trackViewAllTracesSpy = jest.spyOn(track, 'trackViewAllTraces');
const trackSelectTimeframeSpy = jest.spyOn(track, 'trackSelectTimeframe');
const trackSearchOperationDebouncedSpy = jest.spyOn(track, 'trackSearchOperationDebounced');
const trackSearchOperationSpy = jest.spyOn(track, 'trackSearchOperation');

const newValue = 'newValue';
const [timeFrameOption] = timeFrameOptions;

wrapper.setProps({
metrics: { ...originInitialState, serviceOpsMetrics },
});

wrapper.find('Search').simulate('change', { target: { value: newValue } });
expect(trackSearchOperationDebouncedSpy).toHaveBeenCalledWith(newValue);
expect(trackSearchOperationSpy).toHaveBeenCalledWith(newValue);

wrapper
.find('Field')
Expand All @@ -336,7 +338,7 @@ describe('<MonitorATMServicesView>', () => {
trackSelectServiceSpy.mockReset();
trackViewAllTracesSpy.mockReset();
trackSelectTimeframeSpy.mockReset();
trackSearchOperationDebouncedSpy.mockReset();
trackSearchOperationSpy.mockReset();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Uber Technologies, Inc.
// Copyright (c) 2022 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,10 @@ import {
CATEGORY_SELECT_SERVICE,
CATEGORY_SELECT_TIMEFRAME,
CATEGORY_VIEW_ALL_TRACES,
trackSearchOperationDebounced,
trackSelectService,
trackSelectTimeframe,
trackViewAllTraces,
trackSearchOperation,
} from './index.track';

describe('ServicesView tracking', () => {
Expand Down Expand Up @@ -52,16 +52,9 @@ describe('ServicesView tracking', () => {
expect(trackEvent).toHaveBeenCalledWith(CATEGORY_SELECT_TIMEFRAME, timeframe);
});

it('trackSearchOperationDebounced calls trackEvent just once with the match category and show action', async () => {
const debounceTimeout = 1000;
it('trackSearchOperation calls trackEvent with the match category and show action', async () => {
const searchQuery = 'name';

for (let i = 0; i < 10; i++) {
trackSearchOperationDebounced(searchQuery);
}
await new Promise(res => setTimeout(res, debounceTimeout));

expect(trackEvent).toHaveBeenCalledTimes(1);
trackSearchOperation(searchQuery);
expect(trackEvent).toHaveBeenCalledWith(CATEGORY_SEARCH_OPERATION, searchQuery);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 The Jaeger Authors.
// Copyright (c) 2022 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import _debounce from 'lodash/debounce';
import { trackEvent } from '../../../utils/tracking';

const SPM_CATEGORY_BASE = 'jaeger/ux/trace/spm';
Expand All @@ -25,8 +24,5 @@ export const CATEGORY_SEARCH_OPERATION = `${SPM_CATEGORY_BASE}/search-operation`
export const trackViewAllTraces = () => trackEvent(CATEGORY_VIEW_ALL_TRACES, 'click');
export const trackSelectService = (service: string) => trackEvent(CATEGORY_SELECT_SERVICE, service);
export const trackSelectTimeframe = (timeframe: string) => trackEvent(CATEGORY_SELECT_TIMEFRAME, timeframe);

export const trackSearchOperationDebounced = _debounce(
(searchQuery: string) => trackEvent(CATEGORY_SEARCH_OPERATION, searchQuery),
1000
);
export const trackSearchOperation = (searchQuery: string) =>
trackEvent(CATEGORY_SEARCH_OPERATION, searchQuery);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import * as React from 'react';
import { Row, Col, Input, Alert } from 'antd';
import { ActionFunction, Action } from 'redux-actions';
import _debounce from 'lodash/debounce';
import _isEqual from 'lodash/isEqual';
import _isEmpty from 'lodash/isEmpty';
// @ts-ignore
Expand Down Expand Up @@ -45,7 +46,7 @@ import { convertToTimeUnit, convertTimeUnitToShortTerm, getSuitableTimeUnit } fr
import './index.css';
import { getConfigValue } from '../../../utils/config/get-config';
import {
trackSearchOperationDebounced,
trackSearchOperation,
trackSelectService,
trackSelectTimeframe,
trackViewAllTraces,
Expand Down Expand Up @@ -74,6 +75,8 @@ type TDispatchProps = {
fetchAllServiceMetrics: (serviceName: string, query: MetricsAPIQueryParams) => void;
};

const trackSearchOperationDebounced = _debounce(searchQuery => trackSearchOperation(searchQuery), 1000);

const Search = Input.Search;

const AdaptedVirtualSelect = reduxFormFieldAdapter({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Uber Technologies, Inc.
// Copyright (c) 2022 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 The Jaeger Authors.
// Copyright (c) 2022 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit bebe985

Please sign in to comment.