Download wp-calypso/client/lib/analytics/test/gpc-opt-out.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/analytics/test/gpc-opt-out.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/analytics/test/gpc-opt-out.js
-
curl -L -o gpc-opt-out.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/analytics/test/gpc-opt-out.js
1.85 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import { isRegionInCcpaZone } from '@automattic/calypso-analytics'; | |
| import { mayWeTrackUserGpcInCcpaRegion } from '../utils'; | |
| // Return a predictable value for whether the user is in a CCPA region. | |
| jest.mock( '@automattic/calypso-analytics' ); | |
| let windowSpy = jest.SpyInstance; | |
| // Return a predictable value for window.navigator.globalPrivacyControl. | |
| const setMockGpcValue = ( gpcValue ) => { | |
| windowSpy.mockImplementation( () => ( { | |
| navigator: { | |
| globalPrivacyControl: gpcValue, | |
| }, | |
| } ) ); | |
| }; | |
| describe( 'global privacy control', () => { | |
| beforeEach( () => { | |
| windowSpy = jest.spyOn( global, 'window', 'get' ); | |
| } ); | |
| afterEach( () => { | |
| windowSpy.mockRestore(); | |
| } ); | |
| describe( 'mayWeTrackUserGpcInCcpaRegion', () => { | |
| test( 'we may track a user in CCPA if GPC is not set', () => { | |
| setMockGpcValue( undefined ); | |
| isRegionInCcpaZone.mockReturnValue( true ); | |
| expect( mayWeTrackUserGpcInCcpaRegion() ).toBe( true ); | |
| } ); | |
| test( 'we may track a user in CCPA if GPC is set to false', () => { | |
| setMockGpcValue( false ); | |
| isRegionInCcpaZone.mockReturnValue( true ); | |
| expect( mayWeTrackUserGpcInCcpaRegion() ).toBe( true ); | |
| } ); | |
| test( 'we may not track a user in CCPA if GPC is set', () => { | |
| setMockGpcValue( true ); | |
| isRegionInCcpaZone.mockReturnValue( true ); | |
| expect( mayWeTrackUserGpcInCcpaRegion() ).toBe( false ); | |
| } ); | |
| test( 'we may track a user outside CCPA if GPC is set', () => { | |
| setMockGpcValue( true ); | |
| isRegionInCcpaZone.mockReturnValue( false ); | |
| expect( mayWeTrackUserGpcInCcpaRegion() ).toBe( true ); | |
| } ); | |
| test( 'we may track a user outside CCPA if GPC is undefined', () => { | |
| setMockGpcValue( undefined ); | |
| isRegionInCcpaZone.mockReturnValue( false ); | |
| expect( mayWeTrackUserGpcInCcpaRegion() ).toBe( true ); | |
| } ); | |
| } ); | |
| } ); | |