-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathKeyMetricsSetupApp.test.js
More file actions
729 lines (592 loc) · 20.3 KB
/
Copy pathKeyMetricsSetupApp.test.js
File metadata and controls
729 lines (592 loc) · 20.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/**
* KeyMetricsSetupApp component tests.
*
* Site Kit by Google, Copyright 2025 Google LLC
*
* 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
*
* https://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 {
render,
createTestRegistry,
provideUserAuthentication,
fireEvent,
provideSiteInfo,
freezeFetch,
waitForTimeouts,
waitFor,
muteFetch,
} from '../../../../tests/js/test-utils';
import { mockLocation } from '../../../../tests/js/mock-browser-utils';
import { CORE_USER } from '@/js/googlesitekit/datastore/user/constants';
import { VIEW_CONTEXT_KEY_METRICS_SETUP } from '@/js/googlesitekit/constants';
import KeyMetricsSetupApp from './KeyMetricsSetupApp';
import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants';
import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants';
import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants';
import { MODULES_SEARCH_CONSOLE } from '@/js/modules/search-console/datastore/constants';
import { withConnected } from '@/js/googlesitekit/modules/datastore/__fixtures__';
import * as tracking from '@/js/util/tracking';
import * as analyticsFixtures from '@/js/modules/analytics-4/datastore/__fixtures__';
import * as searchConsoleFixtures from '@/js/modules/search-console/datastore/__fixtures__';
const mockTrackEvent = jest.spyOn( tracking, 'trackEvent' );
mockTrackEvent.mockImplementation( () => Promise.resolve() );
describe( 'KeyMetricsSetupApp', () => {
mockLocation();
let registry;
const syncAudiencesEndpoint = new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/sync-audiences'
);
const syncCustomDimensionsEndpoint = new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/sync-custom-dimensions'
);
const coreUserInputSettingsEndpointRegExp = new RegExp(
'^/google-site-kit/v1/core/user/data/user-input-settings'
);
const initialSetupSettingsEndpoint = new RegExp(
'^/google-site-kit/v1/core/user/data/initial-setup-settings'
);
const searchAnalyticsRegexp = new RegExp(
'^/google-site-kit/v1/modules/search-console/data/searchanalytics'
);
const analytics4ReportRegexp = new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/report'
);
const searchConsoleDataAvailableRegexp = new RegExp(
'^/google-site-kit/v1/modules/search-console/data/data-available'
);
const analytics4DataAvailableRegexp = new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/data-available'
);
// The `UserInputSelectOptions` automatically focuses the first radio/checkbox
// 50 milliseconds after it renders, which causes inconsistencies in snapshots,
// so we advance the timer to make sure it's focused before we capture the snapshot.
async function waitForFocus() {
return await waitForTimeouts( 100 );
}
beforeEach( () => {
registry = createTestRegistry();
provideUserAuthentication( registry );
provideSiteInfo( registry );
registry.dispatch( CORE_USER ).receiveGetUserInputSettings( {} );
registry.dispatch( CORE_USER ).receiveGetDismissedItems( [] );
registry.dispatch( CORE_USER ).receiveGetDismissedPrompts( {} );
registry.dispatch( CORE_USER ).receiveGetCapabilities( {} );
fetchMock.post( syncAudiencesEndpoint, { body: [], status: 200 } );
fetchMock.post( syncCustomDimensionsEndpoint, {
body: [],
status: 200,
} );
fetchMock.getOnce( searchAnalyticsRegexp, {
body: searchConsoleFixtures.report,
} );
fetchMock.getOnce( analytics4ReportRegexp, {
body: analyticsFixtures.report,
} );
muteFetch( searchConsoleDataAvailableRegexp );
muteFetch( analytics4DataAvailableRegexp );
registry.dispatch( CORE_USER ).receiveGetUserAudienceSettings( {
configuredAudiences: null,
isAudienceSegmentationWidgetHidden: false,
didSetAudiences: false,
} );
registry.dispatch( CORE_USER ).receiveGetInitialSetupSettings( {
isAnalyticsSetupComplete: false,
} );
registry
.dispatch( CORE_MODULES )
.receiveGetModules( withConnected( MODULE_SLUG_ANALYTICS_4 ) );
registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetSettings( {} );
} );
afterEach( () => {
jest.resetAllMocks();
} );
it( 'should render correctly', async () => {
const { container, getByText, getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
await waitForFocus();
expect( container ).toMatchSnapshot();
expect(
getByText( 'Tell us your main goal to get tailored metrics' )
).toBeInTheDocument();
expect(
getByRole( 'button', { name: 'Complete setup' } )
).toBeInTheDocument();
} );
it( 'should exclude the "Other" option from the options list', async () => {
const { getAllByRole, getByRole, queryByRole, waitForRegistry } =
render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
[
'Sell products',
'Provide services',
'Monetize content',
'Publish a blog',
'Publish news content',
'Portfolio or business card',
].forEach( ( option ) => {
expect(
getByRole( 'radio', { name: option } )
).toBeInTheDocument();
} );
expect(
queryByRole( 'radio', { name: 'Other' } )
).not.toBeInTheDocument();
expect( getAllByRole( 'radio' ) ).toHaveLength( 6 );
} );
it( 'should save the answer when the CTA is clicked', async () => {
freezeFetch( coreUserInputSettingsEndpointRegExp );
const { getByRole, waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click( getByRole( 'button', { name: 'Complete setup' } ) );
await waitForRegistry();
expect( fetchMock ).toHaveFetched(
coreUserInputSettingsEndpointRegExp,
{
method: 'POST',
body: { data: { settings: { purpose: [ 'publish_blog' ] } } },
}
);
} );
it( 'should call saveInitialSetupSettings with isAnalyticsSetupComplete:true after successful setup', async () => {
fetchMock.postOnce( coreUserInputSettingsEndpointRegExp, {
body: {
purpose: {
values: [ 'publish_blog' ],
scope: 'site',
},
},
status: 200,
} );
fetchMock.postOnce( initialSetupSettingsEndpoint, {
body: { settings: { isAnalyticsSetupComplete: true } },
status: 200,
} );
const { getByRole, waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click( getByRole( 'button', { name: 'Complete setup' } ) );
await waitFor( () => {
expect( fetchMock ).toHaveFetched( initialSetupSettingsEndpoint, {
method: 'POST',
body: {
data: {
settings: { isAnalyticsSetupComplete: true },
},
},
} );
} );
} );
it( 'should show an error when the save fails', async () => {
fetchMock.postOnce( coreUserInputSettingsEndpointRegExp, {
body: {
code: 'internal_server_error',
message: 'Internal server error',
data: { status: 500 },
},
status: 500,
} );
const { container, getByRole, getByText, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
await waitForFocus();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click( getByRole( 'button', { name: 'Complete setup' } ) );
await waitForRegistry();
expect( container ).toMatchSnapshot();
expect(
getByText( 'Error: Internal server error (Please try again.)' )
).toBeInTheDocument();
expect( console ).toHaveErroredWith( [
'Google Site Kit API Error',
'method:POST',
'datapoint:user-input-settings',
'type:core',
'identifier:user',
'error:"Internal server error"',
] );
} );
it( 'should not navigate to the dashboard when saving fails', async () => {
fetchMock.postOnce( coreUserInputSettingsEndpointRegExp, {
body: {
code: 'internal_server_error',
message: 'Internal server error',
data: { status: 500 },
},
status: 500,
} );
const { getByRole, waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click( getByRole( 'button', { name: 'Complete setup' } ) );
await waitForRegistry();
expect( global.location.assign ).not.toHaveBeenCalled();
expect( console ).toHaveErrored();
} );
it( 'should show the analytics setup success toast notice', async () => {
const { container, getByText, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
await waitForFocus();
expect( container ).toMatchSnapshot();
expect(
getByText( 'Google Analytics was successfully set up' )
).toBeInTheDocument();
} );
it( 'should sync audiences and custom dimensions on render', async () => {
registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetAudienceSettings( {
availableAudiences: null,
} );
const { waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect( fetchMock ).toHaveFetched( syncAudiencesEndpoint );
expect( fetchMock ).toHaveFetched( syncCustomDimensionsEndpoint );
} );
it( 'should not sync audiences and custom dimensions until Analytics 4 settings have resolved', async () => {
const analytics4SettingsEndpoint = new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/settings'
);
// Create a fresh registry without pre-populated Analytics 4
// settings so getSettings resolution remains pending.
const freshRegistry = createTestRegistry();
provideUserAuthentication( freshRegistry );
provideSiteInfo( freshRegistry );
freshRegistry.dispatch( CORE_USER ).receiveGetUserInputSettings( {} );
freshRegistry.dispatch( CORE_USER ).receiveGetDismissedItems( [] );
freshRegistry.dispatch( CORE_USER ).receiveGetDismissedPrompts( {} );
freshRegistry.dispatch( CORE_USER ).receiveGetCapabilities( {} );
freshRegistry
.dispatch( CORE_USER )
.receiveGetUserAudienceSettings( {
configuredAudiences: null,
isAudienceSegmentationWidgetHidden: false,
didSetAudiences: false,
} );
freshRegistry.dispatch( CORE_USER ).receiveGetInitialSetupSettings( {
isAnalyticsSetupComplete: false,
} );
freshRegistry
.dispatch( CORE_MODULES )
.receiveGetModules( withConnected( MODULE_SLUG_ANALYTICS_4 ) );
// Freeze the Analytics 4 settings endpoint so the resolver
// never completes and hasFinishedResolution stays false.
freezeFetch( analytics4SettingsEndpoint );
fetchMock.post( syncAudiencesEndpoint, { body: [], status: 200 } );
fetchMock.post( syncCustomDimensionsEndpoint, {
body: [],
status: 200,
} );
fetchMock.getOnce( searchAnalyticsRegexp, {
body: searchConsoleFixtures.report,
} );
fetchMock.getOnce( analytics4ReportRegexp, {
body: analyticsFixtures.report,
} );
muteFetch( searchConsoleDataAvailableRegexp );
muteFetch( analytics4DataAvailableRegexp );
const { waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry: freshRegistry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
// Since Analytics 4 settings have not resolved, the sync
// actions should not have been dispatched yet.
expect( fetchMock ).not.toHaveFetched( syncAudiencesEndpoint );
expect( fetchMock ).not.toHaveFetched(
syncCustomDimensionsEndpoint
);
} );
it( 'should not attempt to sync again while syncing is already in progress', async () => {
registry.dispatch( MODULES_ANALYTICS_4 ).receiveGetAudienceSettings( {
availableAudiences: null,
} );
const { rerender, waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect( fetchMock ).toHaveFetchedTimes( 1, syncAudiencesEndpoint );
expect( fetchMock ).toHaveFetchedTimes(
1,
syncCustomDimensionsEndpoint
);
rerender( <KeyMetricsSetupApp /> );
await waitForRegistry();
expect( fetchMock ).toHaveFetchedTimes( 1, syncAudiencesEndpoint );
expect( fetchMock ).toHaveFetchedTimes(
1,
syncCustomDimensionsEndpoint
);
} );
it( 'should resolve data availability for both Analytics and Search Console on render', async () => {
expect(
registry
.select( MODULES_ANALYTICS_4 )
.hasStartedResolution( 'isGatheringData', [] )
).toBe( false );
expect(
registry
.select( MODULES_SEARCH_CONSOLE )
.hasStartedResolution( 'isGatheringData', [] )
).toBe( false );
const { waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect(
registry
.select( MODULES_ANALYTICS_4 )
.hasFinishedResolution( 'isGatheringData', [] )
).toBe( true );
expect(
registry
.select( MODULES_SEARCH_CONSOLE )
.hasFinishedResolution( 'isGatheringData', [] )
).toBe( true );
} );
it( 'should display the help menu in the header', async () => {
const { container, waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect(
container.querySelector( '.googlesitekit-help-menu__button' )
).toBeInTheDocument();
} );
describe( 'initial setup flow', () => {
beforeEach( () => {
global.location.href =
'http://example.com/wp-admin/admin.php?page=googlesitekit-key-metrics-setup&showProgress=true';
} );
it( 'should display the progress indicator when the showProgress query arg is present', async () => {
const { container, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
await waitForFocus();
expect( container ).toMatchSnapshot();
expect(
document.querySelector(
'.googlesitekit-subheader .googlesitekit-progress-indicator'
)
).toBeInTheDocument();
} );
it( 'should track `setup_flow_v3_view_key_metrics_step` event when key metric setup screen is mounted', async () => {
const { waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect( mockTrackEvent ).toHaveBeenCalledWith(
`${ VIEW_CONTEXT_KEY_METRICS_SETUP }_setup`,
'setup_flow_v3_view_key_metrics_step'
);
} );
it( 'should track `setup_flow_v3_select_key_metrics_answer` event when an answer is selected', async () => {
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
// Clear the event tracked on mount.
mockTrackEvent.mockClear();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
expect( mockTrackEvent ).toHaveBeenCalledWith(
`${ VIEW_CONTEXT_KEY_METRICS_SETUP }_setup`,
'setup_flow_v3_select_key_metrics_answer',
'publish_blog'
);
expect( mockTrackEvent ).toHaveBeenCalledTimes( 1 );
} );
it( 'should track `setup_flow_v3_exit_setup` event when the user clicks the "Exit setup" button', async () => {
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
features: [ 'setupFlowRefresh' ],
}
);
await waitForRegistry();
// Clear the event tracked on mount.
mockTrackEvent.mockClear();
fireEvent.click( getByRole( 'button', { name: 'Exit setup' } ) );
expect( mockTrackEvent ).toHaveBeenCalledWith(
`${ VIEW_CONTEXT_KEY_METRICS_SETUP }_setup`,
'setup_flow_v3_exit_setup',
'key-metrics'
);
expect( mockTrackEvent ).toHaveBeenCalledTimes( 1 );
} );
it( 'should navigate to the dashboard without the slug param when saving is successful', async () => {
fetchMock.postOnce( initialSetupSettingsEndpoint, {
body: { settings: { isAnalyticsSetupComplete: true } },
} );
fetchMock.postOnce( coreUserInputSettingsEndpointRegExp, {
body: {
purpose: {
values: [ 'publish_blog' ],
scope: 'site',
},
},
status: 200,
} );
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click(
getByRole( 'button', { name: 'Complete setup' } )
);
await waitFor( () => {
expect( global.location.assign ).toHaveBeenCalledWith(
'http://example.com/wp-admin/admin.php?page=googlesitekit-dashboard¬ification=initial_setup_success'
);
} );
} );
} );
describe( 'non-initial setup flow', () => {
beforeEach( () => {
global.location.href =
'http://example.com/wp-admin/admin.php?page=googlesitekit-key-metrics-setup';
} );
it( 'should navigate to the dashboard with notification and slug params when saving is successful', async () => {
fetchMock.postOnce( initialSetupSettingsEndpoint, {
body: { settings: { isAnalyticsSetupComplete: true } },
} );
fetchMock.postOnce( coreUserInputSettingsEndpointRegExp, {
body: {
purpose: {
values: [ 'publish_blog' ],
scope: 'site',
},
},
status: 200,
} );
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
fireEvent.click(
getByRole( 'button', { name: 'Complete setup' } )
);
await waitFor( () => {
expect( global.location.assign ).toHaveBeenCalledWith(
'http://example.com/wp-admin/admin.php?page=googlesitekit-dashboard¬ification=authentication_success&slug=analytics-4'
);
} );
} );
it( 'should track `view_key_metrics_step` event viewing key metrics step', async () => {
const { waitForRegistry } = render( <KeyMetricsSetupApp />, {
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
} );
await waitForRegistry();
expect( mockTrackEvent ).toHaveBeenCalledWith(
VIEW_CONTEXT_KEY_METRICS_SETUP,
'view_key_metrics_step'
);
} );
it( 'should track `select_key_metrics_answer` event when an answer is selected', async () => {
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
// Clear the event tracked on mount.
mockTrackEvent.mockClear();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
expect( mockTrackEvent ).toHaveBeenCalledWith(
VIEW_CONTEXT_KEY_METRICS_SETUP,
'select_key_metrics_answer',
'publish_blog'
);
expect( mockTrackEvent ).toHaveBeenCalledTimes( 1 );
} );
it( 'should track `complete_key_metrics_step` event when completing key metrics step by clicking `Complete setup` CTA', async () => {
freezeFetch( coreUserInputSettingsEndpointRegExp );
const { getByRole, waitForRegistry } = render(
<KeyMetricsSetupApp />,
{
registry,
viewContext: VIEW_CONTEXT_KEY_METRICS_SETUP,
}
);
await waitForRegistry();
fireEvent.click( getByRole( 'radio', { name: 'Publish a blog' } ) );
// Clear the events tracked so far.
mockTrackEvent.mockClear();
fireEvent.click(
getByRole( 'button', { name: 'Complete setup' } )
);
expect( mockTrackEvent ).toHaveBeenCalledWith(
VIEW_CONTEXT_KEY_METRICS_SETUP,
'complete_key_metrics_step'
);
expect( mockTrackEvent ).toHaveBeenCalledTimes( 1 );
} );
} );
} );