Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
  • Loading branch information
th3M1ke committed Feb 16, 2021
1 parent 171ca8f commit 186e6c8
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
44 changes: 41 additions & 3 deletions packages/jaeger-ui/src/utils/tracking/ga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jest.mock('./index', () => {
});

import ReactGA from 'react-ga';

import GA from './ga';
import * as GA from './ga';
import * as utils from './utils';

let longStr = '---';
function getStr(len) {
Expand All @@ -41,7 +41,7 @@ describe('google analytics tracking', () => {
let tracking;

beforeAll(() => {
tracking = GA(
tracking = GA.default(
{
tracking: {
gaID: 'UA-123456',
Expand Down Expand Up @@ -177,4 +177,42 @@ describe('google analytics tracking', () => {
['send', { hitType: 'event', eventCategory: expect.any(String), eventAction: expect.any(String) }],
]);
});

describe('Debug mode', () => {
let trackingDebug;

beforeAll(() => {
const originalWindow = { ...window };
const windowSpy = jest.spyOn(global, 'window', 'get');
windowSpy.mockImplementation(() => ({
...originalWindow,
location: {
...originalWindow.location,
href: 'http://my.test/page',
search: 'ga-debug=true',
},
}));

trackingDebug = GA.default(
{
tracking: {
gaID: 'UA-123456',
trackErrors: true,
cookiesToDimensions: [{ cookie: 'page', dimension: 'dimension1' }],
},
},
'c0mm1ts',
'c0mm1tL'
);
});

it('isDebugMode = true', () => {
utils.logTrackingCalls = jest.fn();
trackingDebug.init();
trackingDebug.trackError();
trackingDebug.trackEvent('jaeger/some-category', 'some-action');
trackingDebug.trackPageView('a', 'b');
expect(utils.logTrackingCalls).toHaveBeenCalledTimes(4);
});
});
});
11 changes: 1 addition & 10 deletions packages/jaeger-ui/src/utils/tracking/ga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,12 @@ import convRavenToGa from './conv-raven-to-ga';
import { TNil } from '../../types';
import { Config } from '../../types/config';
import { IWebAnalyticsFunc } from '../../types/tracking';
import { logTrackingCalls } from './utils';

const isTruish = (value?: string | string[]) => {
return Boolean(value) && value !== '0' && value !== 'false';
};

/* istanbul ignore next */
const logTrackingCalls = () => {
const calls = ReactGA.testModeAPI.calls;
for (let i = 0; i < calls.length; i++) {
// eslint-disable-next-line no-console
console.log('[react-ga]', ...calls[i]);
}
calls.length = 0;
};

const GA: IWebAnalyticsFunc = (config: Config, versionShort: string, versionLong: string) => {
const isProd = process.env.NODE_ENV === 'production';
const isDev = process.env.NODE_ENV === 'development';
Expand Down
23 changes: 23 additions & 0 deletions packages/jaeger-ui/src/utils/tracking/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2021 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.
// 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.

import * as utils from './utils';

describe('utils', () => {
describe('logTrackingCalls', () => {
it('dry run', () => {
expect(utils.logTrackingCalls()).toBeUndefined();
});
});
});
24 changes: 24 additions & 0 deletions packages/jaeger-ui/src/utils/tracking/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2021 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.
// 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.

import ReactGA from 'react-ga';

export const logTrackingCalls = () => {
const calls = ReactGA.testModeAPI.calls;
for (let i = 0; i < calls.length; i++) {
// eslint-disable-next-line no-console
console.log('[react-ga]', ...calls[i]);
}
calls.length = 0;
};

0 comments on commit 186e6c8

Please sign in to comment.