Skip to content

Commit

Permalink
feat(playertesting): make event expectation helpers more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandkakonyi committed Nov 28, 2023
1 parent 150bc5e commit fe5f4ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
16 changes: 8 additions & 8 deletions integration_test/playertesting/PlayerWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { Event } from 'bitmovin-player-react-native';
import { EventType } from './EventType';
import {
SingleEventExpectation,
P,
F,
PlainEvent,
FilteredEvent,
} from './expectations/SingleEventExpectation';
import {
MultipleEventsExpectation,
S,
EventSequence,
} from './expectations/MultipleEventsExpectation';

export default class PlayerWorld {
Expand Down Expand Up @@ -151,7 +151,7 @@ export default class PlayerWorld {
(player) => {
player.play();
},
new F<TimeChangedEvent>(
FilteredEvent<TimeChangedEvent>(
EventType.TimeChanged,
(event) => event.currentTime >= time
),
Expand Down Expand Up @@ -187,7 +187,7 @@ export default class PlayerWorld {
if (expectationConvertible instanceof SingleEventExpectation) {
actualExpectation = expectationConvertible;
} else {
actualExpectation = new P(expectationConvertible as EventType);
actualExpectation = PlainEvent(expectationConvertible as EventType);
}
let resolve: (event: T) => void = () => {};
let reject: (error: Error) => void = () => {};
Expand Down Expand Up @@ -223,9 +223,9 @@ export default class PlayerWorld {
if (expectationsConvertible instanceof MultipleEventsExpectation) {
actualExpectation = expectationsConvertible;
} else {
actualExpectation = new S(
Array.from(expectationsConvertible as EventType[]).map(
(eventType) => new P(eventType)
actualExpectation = EventSequence(
Array.from(expectationsConvertible as EventType[]).map((eventType) =>
PlainEvent(eventType)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,27 @@ export class AnyEventExpectation extends MultipleEventsExpectation {
}
}

export class S extends EventSequenceExpectation {}
export class B extends EventBagExpectation {}
export class R extends RepeatedEventExpectation {}
export class A extends AnyEventExpectation {}
export function EventSequence(
singleExpectationConvertibles: SingleEventExpectation[] | EventType[]
): EventSequenceExpectation {
return new EventSequenceExpectation(singleExpectationConvertibles);
}

export function EventBag(
singleExpectationConvertibles: SingleEventExpectation[] | EventType[]
): EventBagExpectation {
return new EventBagExpectation(singleExpectationConvertibles);
}

export function RepeatedEvent(
singleExpectationConvertible: SingleEventExpectation | EventType,
count: number
): EventSequenceExpectation {
return new RepeatedEventExpectation(singleExpectationConvertible, count);
}

export function AnyEvent(
singleExpectationConvertibles: SingleEventExpectation[] | EventType[]
): AnyEventExpectation {
return new AnyEventExpectation(singleExpectationConvertibles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ export class FilteredEventExpectation<
}
}

export class P extends PlainEventExpectation {}
export class F<E extends Event> extends FilteredEventExpectation<E> {}
export function PlainEvent(eventType: EventType): PlainEventExpectation {
return new PlainEventExpectation(eventType);
}

export function FilteredEvent<E extends Event>(
eventType: EventType,
filter: (event: E) => boolean
): FilteredEventExpectation<E> {
return new FilteredEventExpectation(eventType, filter);
}

0 comments on commit fe5f4ea

Please sign in to comment.