test(analytics-module-ga): apply review suggestion

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2024-01-26 13:37:35 +01:00
parent e92f21f27a
commit 915773bf0a
@@ -521,12 +521,30 @@ describe('GoogleAnalytics', () => {
context,
});
const [command, data] = ReactGA.testModeAPI.calls[1];
let [command, data] = ReactGA.testModeAPI.calls[1];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'pageview',
page: '/',
});
api.captureEvent({
action: 'click',
subject: 'on something',
value: 42,
context,
});
[command, data] = ReactGA.testModeAPI.calls[2];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'event',
// expect to use the legacy default category
eventCategory: 'App',
eventAction: 'click',
eventLabel: 'on something',
eventValue: 42,
});
});
it('use lowercase app as the new default category', () => {
@@ -537,15 +555,41 @@ describe('GoogleAnalytics', () => {
api.captureEvent({
action: 'navigate',
subject: '/',
context: { ...context, extensionId: '', extension: '' },
context: {
...context,
extensionId: '',
extension: '',
},
});
const [command, data] = ReactGA.testModeAPI.calls[1];
let [command, data] = ReactGA.testModeAPI.calls[1];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'pageview',
page: '/',
});
api.captureEvent({
action: 'click',
subject: 'on something',
value: 42,
context: {
...context,
extensionId: '',
extension: '',
},
});
[command, data] = ReactGA.testModeAPI.calls[2];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'event',
// expect to use the new default category
eventCategory: 'app',
eventAction: 'click',
eventLabel: 'on something',
eventValue: 42,
});
});
it('prioritize new context extension id over old extension property', () => {
@@ -556,15 +600,41 @@ describe('GoogleAnalytics', () => {
api.captureEvent({
action: 'navigate',
subject: '/',
context: { ...context, extensionId: 'app', extension: '' },
context: {
...context,
extensionId: 'app',
extension: '',
},
});
const [command, data] = ReactGA.testModeAPI.calls[1];
let [command, data] = ReactGA.testModeAPI.calls[1];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'pageview',
page: '/',
});
api.captureEvent({
action: 'click',
subject: 'on something',
value: 42,
context: {
...context,
extensionId: 'page:index',
extension: '',
},
});
[command, data] = ReactGA.testModeAPI.calls[2];
expect(command).toBe('send');
expect(data).toMatchObject({
hitType: 'event',
// expect use the new context extension id
eventCategory: 'page:index',
eventAction: 'click',
eventLabel: 'on something',
eventValue: 42,
});
});
});
});