File size: 1,912 Bytes
1e92f2d |
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 |
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();
} );
} );
|