react-code-dataset / wp-calypso /packages /calypso-e2e /src /lib /utils /test /editor-tracks-event-manager.test.ts
react-code-dataset / wp-calypso /packages /calypso-e2e /src /lib /utils /test /editor-tracks-event-manager.test.ts
Download wp-calypso/packages/calypso-e2e/src/lib/utils/test/editor-tracks-event-manager.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-e2e/src/lib/utils/test/editor-tracks-event-manager.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/calypso-e2e/src/lib/utils/test/editor-tracks-event-manager.test.ts
-
curl -L -o editor-tracks-event-manager.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-e2e/src/lib/utils/test/editor-tracks-event-manager.test.ts
1.91 kB
| import { it, describe, expect } from '@jest/globals'; | |
| import { createEventMatchingPredicate } from '../editor-tracks-event-manager'; | |
| import { TracksEvent } from '../types'; | |
| describe( 'Test: createEventMatchingPredicate', function () { | |
| const fakeTracksEvents: TracksEvent[] = [ | |
| [ 'wpcom_event_a', { prop_1: 'foo', prop_2: 'bar' } ], | |
| [ 'wpcom_event_b', {} ], | |
| ]; | |
| it( 'Finds a matching event by name', function () { | |
| const expectedEventName = 'wpcom_event_b'; | |
| const foundEvent = fakeTracksEvents.find( createEventMatchingPredicate( expectedEventName ) ); | |
| expect( foundEvent?.[ 0 ] ).toBe( expectedEventName ); | |
| } ); | |
| it( 'Does not match on an event that does not match by name', function () { | |
| const foundEvent = fakeTracksEvents.find( createEventMatchingPredicate( 'no_event_here' ) ); | |
| expect( foundEvent ).toBeUndefined(); | |
| } ); | |
| it( 'Does a partial match of expected event properties', function () { | |
| const expectedEventName = 'wpcom_event_a'; | |
| const foundEvent = fakeTracksEvents.find( | |
| createEventMatchingPredicate( expectedEventName, { prop_2: 'bar' } ) | |
| ); | |
| expect( foundEvent?.[ 0 ] ).toBe( expectedEventName ); | |
| } ); | |
| it( 'Does not match on an event if property value is incorrect', function () { | |
| const foundEvent = fakeTracksEvents.find( | |
| createEventMatchingPredicate( 'wpcom_event_a', { prop_2: 'wrong' } ) | |
| ); | |
| expect( foundEvent ).toBeUndefined(); | |
| } ); | |
| it( 'Does not match on an event if property key itself is incorrect', function () { | |
| const foundEvent = fakeTracksEvents.find( | |
| createEventMatchingPredicate( 'wpcom_event_a', { wrong_prop: 'foo' } ) | |
| ); | |
| expect( foundEvent ).toBeUndefined(); | |
| } ); | |
| it( 'Requires all provided properties to match', function () { | |
| const foundEvent = fakeTracksEvents.find( | |
| createEventMatchingPredicate( 'wpcom_event_a', { prop_1: 'foo', prop_2: 'second_is_wrong' } ) | |
| ); | |
| expect( foundEvent ).toBeUndefined(); | |
| } ); | |
| } ); | |