|
| 1 | +/** |
| 2 | + * Analytics module widget registration tests. |
| 3 | + * |
| 4 | + * Site Kit by Google, Copyright 2026 Google LLC |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Internal dependencies |
| 21 | + */ |
| 22 | +import { enabledFeatures } from '@/js/features'; |
| 23 | +import { |
| 24 | + createWidgets, |
| 25 | + registerWidgets as registerDefaultWidgets, |
| 26 | +} from '@/js/googlesitekit/widgets'; |
| 27 | +import { CORE_WIDGETS } from '@/js/googlesitekit/widgets/datastore/constants'; |
| 28 | +import { AREA_MAIN_DASHBOARD_SITE_GOALS_PRIMARY } from '@/js/googlesitekit/widgets/default-areas'; |
| 29 | +import { |
| 30 | + createTestRegistry, |
| 31 | + provideSiteInfo, |
| 32 | +} from '../../../../../tests/js/utils'; |
| 33 | +import { registerWidgets } from './index'; |
| 34 | + |
| 35 | +describe( 'Analytics 4 widget registrations', () => { |
| 36 | + let registry; |
| 37 | + let widgets; |
| 38 | + |
| 39 | + beforeEach( () => { |
| 40 | + registry = createTestRegistry(); |
| 41 | + enabledFeatures.add( 'siteGoals' ); |
| 42 | + widgets = createWidgets( registry ); |
| 43 | + registerDefaultWidgets( widgets ); |
| 44 | + } ); |
| 45 | + |
| 46 | + afterEach( () => { |
| 47 | + enabledFeatures.delete( 'siteGoals' ); |
| 48 | + } ); |
| 49 | + |
| 50 | + describe( 'Site Goals widgets', () => { |
| 51 | + it.each( [ |
| 52 | + [ |
| 53 | + 'only ecommerce active', |
| 54 | + { |
| 55 | + hasActiveEcommerceEventProviders: true, |
| 56 | + hasActiveLeadEventProviders: false, |
| 57 | + }, |
| 58 | + [ 'analyticsOnlineStorePerformance' ], |
| 59 | + [ 'analyticsLeadGenerationPerformance' ], |
| 60 | + ], |
| 61 | + [ |
| 62 | + 'only lead active', |
| 63 | + { |
| 64 | + hasActiveEcommerceEventProviders: false, |
| 65 | + hasActiveLeadEventProviders: true, |
| 66 | + }, |
| 67 | + [ 'analyticsLeadGenerationPerformance' ], |
| 68 | + [ 'analyticsOnlineStorePerformance' ], |
| 69 | + ], |
| 70 | + [ |
| 71 | + 'both active', |
| 72 | + { |
| 73 | + hasActiveEcommerceEventProviders: true, |
| 74 | + hasActiveLeadEventProviders: true, |
| 75 | + }, |
| 76 | + [ |
| 77 | + 'analyticsOnlineStorePerformance', |
| 78 | + 'analyticsLeadGenerationPerformance', |
| 79 | + ], |
| 80 | + [], |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'neither active', |
| 84 | + { |
| 85 | + hasActiveEcommerceEventProviders: false, |
| 86 | + hasActiveLeadEventProviders: false, |
| 87 | + }, |
| 88 | + [], |
| 89 | + [ |
| 90 | + 'analyticsOnlineStorePerformance', |
| 91 | + 'analyticsLeadGenerationPerformance', |
| 92 | + ], |
| 93 | + ], |
| 94 | + ] )( |
| 95 | + 'should gate widgets correctly when %s', |
| 96 | + ( _, siteInfo, expectedPresent, expectedAbsent ) => { |
| 97 | + provideSiteInfo( registry, siteInfo ); |
| 98 | + registerWidgets( widgets ); |
| 99 | + |
| 100 | + const slugs = registry |
| 101 | + .select( CORE_WIDGETS ) |
| 102 | + .getWidgets( AREA_MAIN_DASHBOARD_SITE_GOALS_PRIMARY ) |
| 103 | + .map( ( w ) => w.slug ); |
| 104 | + |
| 105 | + expectedPresent.forEach( ( slug ) => { |
| 106 | + expect( slugs ).toContain( slug ); |
| 107 | + } ); |
| 108 | + expectedAbsent.forEach( ( slug ) => { |
| 109 | + expect( slugs ).not.toContain( slug ); |
| 110 | + } ); |
| 111 | + } |
| 112 | + ); |
| 113 | + } ); |
| 114 | +} ); |
0 commit comments