Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Davit Yeghshatyan <[email protected]>
  • Loading branch information
Davit Yeghshatyan committed Jun 21, 2018
1 parent 301831a commit b64074c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
12 changes: 6 additions & 6 deletions packages/jaeger-ui/src/components/SearchTracePage/SearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const ACTION_SET = 'set';
const ACTION_CLEAR = 'clear';
const ACTION_DEFAULT = 'default';

const CATEGORY_OPERATION = `${CATEGORY_BASE}/operation`;
const CATEGORY_LOOKBACK = `${CATEGORY_BASE}/lookback`;
const CATEGORY_TAGS = `${CATEGORY_BASE}/tags`;
const CATEGORY_MIN_DURATION = `${CATEGORY_BASE}/min_duration`;
const CATEGORY_MAX_DURATION = `${CATEGORY_BASE}/max_duration`;
const CATEGORY_LIMIT = `${CATEGORY_BASE}/limit`;
export const CATEGORY_OPERATION = `${CATEGORY_BASE}/operation`;
export const CATEGORY_LOOKBACK = `${CATEGORY_BASE}/lookback`;
export const CATEGORY_TAGS = `${CATEGORY_BASE}/tags`;
export const CATEGORY_MIN_DURATION = `${CATEGORY_BASE}/min_duration`;
export const CATEGORY_MAX_DURATION = `${CATEGORY_BASE}/max_duration`;
export const CATEGORY_LIMIT = `${CATEGORY_BASE}/limit`;

export function getUnixTimeStampInMSFromForm({ startDate, startDateTime, endDate, endDateTime }) {
const start = `${startDate} ${startDateTime}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

/* eslint-disable import/first */
jest.mock('store');
jest.mock('../../utils/tracking');

import React from 'react';
import { shallow } from 'enzyme';
import moment from 'moment';
import queryString from 'query-string';
import store from 'store';
import { trackEvent } from '../../utils/tracking';

import {
convertQueryParamsToFormDates,
Expand All @@ -29,6 +31,12 @@ import {
submitForm,
traceIDsToQuery,
SearchFormImpl as SearchForm,
CATEGORY_OPERATION,
CATEGORY_LIMIT,
CATEGORY_TAGS,
CATEGORY_MAX_DURATION,
CATEGORY_MIN_DURATION,
CATEGORY_LOOKBACK,
} from './SearchForm';
import * as markers from './SearchForm.markers';

Expand Down Expand Up @@ -139,6 +147,7 @@ describe('submitForm()', () => {
resultsLimit: 20,
service: 'svc-a',
};
trackEvent.mockClear();
});

it('ignores `fields.operation` when it is "all"', () => {
Expand Down Expand Up @@ -240,6 +249,22 @@ describe('submitForm()', () => {
expect(maxDuration).toBe(null);
});
});

it('sends form input to GA', () => {
submitForm(fields, searchTraces);
expect(trackEvent.mock.calls.length).toBe(6);
const categoriesTracked = trackEvent.mock.calls.map(call => call[0]).sort();
expect(categoriesTracked).toEqual(
[
CATEGORY_OPERATION,
CATEGORY_LIMIT,
CATEGORY_TAGS,
CATEGORY_MAX_DURATION,
CATEGORY_MIN_DURATION,
CATEGORY_LOOKBACK,
].sort()
);
});
});

describe('<SearchForm>', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { trackEvent } from '../../utils/tracking';

export const CATEGORY_BASE = 'jaeger/ux/trace/search';
export const CATEGORY_SORTBY = `${CATEGORY_BASE}/sortby`;
export const FORM_CHANGE_ACTION_TYPE = '@@redux-form/CHANGE';

export const middlewareHooks = {
'@@redux-form/CHANGE': (store: Store, action: any) => {
[FORM_CHANGE_ACTION_TYPE]: (store: Store, action: any) => {
if (action.meta.form === 'sortBy') {
trackEvent(CATEGORY_SORTBY, action.payload);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2017 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable import/first */
jest.mock('../../utils/tracking');

import { trackEvent } from '../../utils/tracking';
import * as track from '../SearchTracePage/SearchForm.track';

describe('middlewareHooks', () => {
it('tracks a GA event for changing sort criteria', () => {
const action = { meta: { form: 'sortBy' }, payload: 'MOST_RECENT' };
track.middlewareHooks[track.FORM_CHANGE_ACTION_TYPE]({}, action);
expect(trackEvent.mock.calls.length).toBe(1);
expect(trackEvent.mock.calls[0]).toEqual([track.CATEGORY_SORTBY, expect.any(String)]);
});
});

0 comments on commit b64074c

Please sign in to comment.