Skip to content

Commit

Permalink
Merge branch 'player-testing/add-player-testing-framework' into playe…
Browse files Browse the repository at this point in the history
…r-testing/add-more-documentation
  • Loading branch information
rolandkakonyi committed Nov 29, 2023
2 parents 78c0994 + 0d97cc6 commit 7e10e11
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions integration_test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AppRegistry } from 'react-native';
import TestableApp from './src/TestableApp';
import PlayerWorld from './playertesting/PlayerWorld';
import PlayerTestWorld from './playertesting/PlayerTestWorld';
import { name as appName, licenseKey } from './app.json';

PlayerWorld.defaultLicenseKey = licenseKey;
PlayerTestWorld.defaultLicenseKey = licenseKey;

AppRegistry.registerComponent(appName, () => TestableApp);
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import {
EventSequence,
} from './expectations/MultipleEventsExpectation';

export default class PlayerWorld {
export default class PlayerTestWorld {
static defaultLicenseKey: string | undefined;
private static shared_: PlayerWorld | undefined;
private static shared_: PlayerTestWorld | undefined;
private player_: Player | undefined;
private isFinished_: boolean = false;
private eventListeners: { [key: string]: (event: Event) => void } = {};

static get shared(): PlayerWorld {
if (PlayerWorld.shared_ === undefined) {
throw new Error('PlayerWorld.shared not initialized');
static get shared(): PlayerTestWorld {
if (PlayerTestWorld.shared_ === undefined) {
throw new Error('PlayerTestWorld.shared not initialized');
}
return PlayerWorld.shared_;
return PlayerTestWorld.shared_;
}

static set shared(playerWorld: PlayerWorld | undefined) {
PlayerWorld.shared_ = playerWorld;
static set shared(playerTestWorld: PlayerTestWorld | undefined) {
PlayerTestWorld.shared_ = playerTestWorld;
}

get player(): Player | undefined {
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class PlayerWorld {
fn: () => Promise<void>
): Promise<void> => {
if (config.licenseKey === undefined) {
config.licenseKey = PlayerWorld.defaultLicenseKey;
config.licenseKey = PlayerTestWorld.defaultLicenseKey;
}

const player = new Player({
Expand Down
20 changes: 10 additions & 10 deletions integration_test/playertesting/PlayerTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TimeChangedEvent,
} from 'bitmovin-player-react-native';
import { EventType } from './EventType';
import PlayerWorld from './PlayerWorld';
import PlayerTestWorld from './PlayerTestWorld';
import {
SingleEventExpectation,
MultipleEventsExpectation,
Expand All @@ -31,7 +31,7 @@ export const startPlayerTest = async (
config: PlayerConfig,
fn: () => Promise<void>
): Promise<void> => {
return await PlayerWorld.shared.startPlayerTest(config, fn);
return await PlayerTestWorld.shared.startPlayerTest(config, fn);
};

/**
Expand All @@ -49,7 +49,7 @@ export const startPlayerTest = async (
export const callPlayer = async <T>(
fn: (player: Player) => Promise<T>
): Promise<T> => {
return await PlayerWorld.shared.callPlayer(fn);
return await PlayerTestWorld.shared.callPlayer(fn);
};

/**
Expand All @@ -72,7 +72,7 @@ export const expectEvent = async <T extends Event>(
expectationConvertible: SingleEventExpectation | EventType,
timeoutSeconds: number = 10
): Promise<T> => {
return await PlayerWorld.shared.expectEvent(
return await PlayerTestWorld.shared.expectEvent(
expectationConvertible,
timeoutSeconds
);
Expand Down Expand Up @@ -104,7 +104,7 @@ export const expectEvents = async (
expectationsConvertible: MultipleEventsExpectation | EventType[],
timeoutSeconds: number = 10
): Promise<Event[]> => {
return await PlayerWorld.shared.expectEvents(
return await PlayerTestWorld.shared.expectEvents(
expectationsConvertible,
timeoutSeconds
);
Expand All @@ -131,7 +131,7 @@ export const callPlayerAndExpectEvent = async <E extends Event, P>(
expectationConvertible: SingleEventExpectation | EventType,
timeoutSeconds: number = 10
): Promise<E> => {
return await PlayerWorld.shared.callPlayerAndExpectEvent(
return await PlayerTestWorld.shared.callPlayerAndExpectEvent(
fn,
expectationConvertible,
timeoutSeconds
Expand Down Expand Up @@ -165,7 +165,7 @@ export const callPlayerAndExpectEvents = async (
expectationsConvertible: MultipleEventsExpectation | EventType[],
timeoutSeconds: number = 10
): Promise<Event[]> => {
return await PlayerWorld.shared.callPlayerAndExpectEvents(
return await PlayerTestWorld.shared.callPlayerAndExpectEvents(
fn,
expectationsConvertible,
timeoutSeconds
Expand Down Expand Up @@ -193,7 +193,7 @@ export const loadSourceConfig = async (
sourceConfig: SourceConfig,
timeoutSeconds: number = 10
): Promise<ReadyEvent> => {
return await PlayerWorld.shared.loadSourceConfig(
return await PlayerTestWorld.shared.loadSourceConfig(
sourceConfig,
timeoutSeconds
);
Expand All @@ -215,7 +215,7 @@ export const playFor = async (
time: number,
timeoutSeconds: number = 10
): Promise<TimeChangedEvent> => {
return await PlayerWorld.shared.playFor(time, timeoutSeconds);
return await PlayerTestWorld.shared.playFor(time, timeoutSeconds);
};

/**
Expand All @@ -234,5 +234,5 @@ export const playUntil = async (
time: number,
timeoutSeconds: number = 10
): Promise<TimeChangedEvent> => {
return await PlayerWorld.shared.playUntil(time, timeoutSeconds);
return await PlayerTestWorld.shared.playUntil(time, timeoutSeconds);
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function EventBag(
export function RepeatedEvent(
singleExpectationConvertible: SingleEventExpectation | EventType,
count: number
): EventSequenceExpectation {
): RepeatedEventExpectation {
return new RepeatedEventExpectation(singleExpectationConvertible, count);
}

Expand Down
12 changes: 6 additions & 6 deletions integration_test/src/TestableApp.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React, { useEffect, useState } from 'react';
import { Tester, TestHookStore } from 'cavy';
import Specs from '../tests';
import PlayerWorld from '../playertesting/PlayerWorld';
import PlayerTestWorld from '../playertesting/PlayerTestWorld';
import TestablePlayer from './TestablePlayer';

const testHookStore = new TestHookStore();

function TestableApp(): JSX.Element {
const playerWorld = useState(new PlayerWorld())[0];
const playerTestWorld = useState(new PlayerTestWorld())[0];
useEffect(() => {
PlayerWorld.shared = playerWorld;
PlayerTestWorld.shared = playerTestWorld;
return () => {
PlayerWorld.shared = undefined;
PlayerTestWorld.shared = undefined;
};
}, [playerWorld]);
}, [playerTestWorld]);
return (
<Tester
specs={Specs}
store={testHookStore}
startDelay={1000}
waitTime={3000}
>
<TestablePlayer playerWorld={playerWorld} />
<TestablePlayer playerTestWorld={playerTestWorld} />
</Tester>
);
}
Expand Down
16 changes: 8 additions & 8 deletions integration_test/src/TestablePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import React, { useState } from 'react';
import { useCavy, wrap } from 'cavy';
import { SafeAreaView, StyleSheet, Text } from 'react-native';
import { PlayerView } from 'bitmovin-player-react-native';
import PlayerWorld from '../playertesting/PlayerWorld';
import PlayerTestWorld from '../playertesting/PlayerTestWorld';
import { Colors } from 'react-native/Libraries/NewAppScreen';

interface TestablePlayerProps {
playerWorld: PlayerWorld;
playerTestWorld: PlayerTestWorld;
}

export default function TestablePlayer({
playerWorld,
playerTestWorld,
}: TestablePlayerProps): JSX.Element {
const generateTestHook = useCavy();
const [renderCount, setRenderCount] = useState(0);
playerWorld.onReRender = () => setRenderCount((count) => count + 1);
playerTestWorld.onReRender = () => setRenderCount((count) => count + 1);

const TestablePlayerView = wrap(PlayerView);
return (
<SafeAreaView style={styles.container}>
{(playerWorld.player && (
{(playerTestWorld.player && (
<>
<Text style={styles.text}>Tests are running...🧪</Text>
<TestablePlayerView
key={renderCount}
ref={generateTestHook('PlayerView')}
player={playerWorld.player}
player={playerTestWorld.player}
style={styles.player}
onEvent={playerWorld.onEvent}
onEvent={playerTestWorld.onEvent}
/>
</>
)) || (
<Text style={styles.text}>
{playerWorld.isFinished
{playerTestWorld.isFinished
? 'Tests have finished!'
: 'Waiting for tests to start...'}
</Text>
Expand Down

0 comments on commit 7e10e11

Please sign in to comment.