Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic web analytics tracking implementation #681

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
  • Loading branch information
th3M1ke committed Feb 15, 2021
commit 85fec8476ea1ffee95829ef7aaa1ad55dac85581
3 changes: 2 additions & 1 deletion packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"!src/setup*.js",
"!src/utils/DraggableManager/demo/*.tsx",
"!src/utils/test/**/*.js",
"!src/demo/**/*.js"
"!src/demo/**/*.js",
"!src/types/*"
]
},
"browserslist": [
Expand Down
40 changes: 38 additions & 2 deletions packages/jaeger-ui/src/utils/tracking/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ const mockGA = {
init: jest.fn(),
context: jest.fn(),
isEnabled: jest.fn(),
trackPageView: jest.fn(),
trackError: jest.fn(),
};

const mockNoopWebAnalytics = {
init: jest.fn(),
context: jest.fn(),
isEnabled: jest.fn(),
trackPageView: jest.fn(),
trackError: jest.fn(),
};

jest.mock('./ga', () => ({
Expand Down Expand Up @@ -56,11 +60,17 @@ describe('generic analytics tracking', () => {
};
});

return import('.').then(() => {
return import('.').then(noopWA => {
expect(internalVersionShort).toBe('unknown');
expect(internalVersionLong).toBe('unknown');
expect(mockNoopWebAnalytics.init).toHaveBeenCalled();
expect(mockGA.init).not.toHaveBeenCalled();

noopWA.trackPageView('pathname', 'search');
noopWA.trackError('description');

expect(mockNoopWebAnalytics.trackPageView).toHaveBeenCalled();
expect(mockNoopWebAnalytics.trackError).toHaveBeenCalled();
});
});

Expand All @@ -76,9 +86,15 @@ describe('generic analytics tracking', () => {
};
});

return import('.').then(() => {
return import('.').then(noopWA => {
expect(mockNoopWebAnalytics.init).not.toHaveBeenCalled();
expect(mockGA.init).toHaveBeenCalled();

noopWA.trackPageView('pathname', 'search');
noopWA.trackError('description');

expect(mockGA.trackPageView).toHaveBeenCalled();
expect(mockGA.trackError).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -144,4 +160,24 @@ describe('generic analytics tracking', () => {
expect(mockGA.init).not.toHaveBeenCalled();
});
});

it('get versions as an object test(hasChanged:true)', () => {
const vShotCommitSHA = '48956d5';
const vShotChanges = '2f +20 -3 1?';
const vLong = ' | github.com/jaegertracing/jaeger-ui | 48956d5 | master';
process.env.REACT_APP_VSN_STATE = `{"remote":"github.com/jaegertracing/jaeger-ui","objName":"${vShotCommitSHA}","changed":{"hasChanged":true,"files":2,"insertions":20,"deletions":3,"untracked":1,"pretty":"${vShotChanges}"},"refName":"master","pretty":"${vLong}"}`;
jest.doMock('../config/get-config', () => {
return {
__esModule: true,
default: () => ({}),
};
});

return import('.').then(() => {
expect(internalVersionShort).toBe(`${vShotCommitSHA} ${vShotChanges}`);
expect(internalVersionLong).toBe(vLong);
expect(mockNoopWebAnalytics.init).toHaveBeenCalled();
expect(mockGA.init).not.toHaveBeenCalled();
});
});
});