Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial set of player tests #340

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions integration_test/tests/exampleSpec.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this as we have actual tests now

This file was deleted.

5 changes: 5 additions & 0 deletions integration_test/tests/helper/Sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ export const Sources = {
url: 'https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd',
type: SourceType.DASH,
} as SourceConfig,

akamaiTestLiveHls: {
url: 'https://cph-msl.akamaized.net/hls/live/2000341/test/master.m3u8',
type: SourceType.HLS,
} as SourceConfig,
};
6 changes: 4 additions & 2 deletions integration_test/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ExampleSpec from './exampleSpec';
import PlaybackTest from './playbackTest';
import LoadingTest from './loadingTest';
import UnloadingTest from './unloadingTest';

export default [ExampleSpec];
export default [PlaybackTest, LoadingTest, UnloadingTest];
61 changes: 61 additions & 0 deletions integration_test/tests/loadingTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { TestScope } from 'cavy';
import {
callPlayerAndExpectEvent,
callPlayerAndExpectEvents,
EventBag,
EventSequence,
EventType,
FilteredEvent,
startPlayerTest,
} from '../playertesting';
import { Sources } from './helper/Sources';
import {
DownloadFinishedEvent,
HttpRequestType,
SourceConfig,
} from 'bitmovin-player-react-native';

export default (spec: TestScope) => {
function loadingSourceTests(sourceConfig: SourceConfig, label: string) {
spec.describe(`loading a ${label} source`, () => {
spec.it('emits ReadyEvent event', async () => {
await startPlayerTest({}, async () => {
await callPlayerAndExpectEvent((player) => {
player.load(sourceConfig);
}, EventType.Ready);
});
});
spec.it('emits SourceLoad and SourceLoaded events', async () => {
await startPlayerTest({}, async () => {
await callPlayerAndExpectEvents((player) => {
player.load(sourceConfig);
}, EventSequence(EventType.SourceLoad, EventType.SourceLoaded));
});
});
spec.it('emits DownloadFinished events', async () => {
await startPlayerTest({}, async () => {
await callPlayerAndExpectEvents(
(player) => {
player.load(sourceConfig);
},
EventBag(
FilteredEvent<DownloadFinishedEvent>(
EventType.DownloadFinished,
(event) =>
event.requestType === HttpRequestType.ManifestHlsMaster
),
FilteredEvent<DownloadFinishedEvent>(
EventType.DownloadFinished,
(event) =>
event.requestType === HttpRequestType.ManifestHlsVariant
)
)
);
});
});
});
}

loadingSourceTests(Sources.artOfMotionHls, 'VOD');
loadingSourceTests(Sources.akamaiTestLiveHls, 'live');
};
61 changes: 61 additions & 0 deletions integration_test/tests/playbackTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { TestScope } from 'cavy';
import {
callPlayerAndExpectEvent,
callPlayerAndExpectEvents,
EventSequence,
EventType,
expectEvents,
loadSourceConfig,
playFor,
RepeatedEvent,
startPlayerTest,
} from '../playertesting';
import { Sources } from './helper/Sources';

export default (spec: TestScope) => {
spec.describe('calling player API when a source is loaded', () => {
spec.it(
'emits a Play and Playing events after calling play API',
async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await callPlayerAndExpectEvents((player) => {
player.play();
}, EventSequence(EventType.Play, EventType.Playing));
});
}
);
spec.it('emits a Paused event after calling pause API', async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await playFor(1);
await callPlayerAndExpectEvent((player) => {
player.pause();
}, EventType.Paused);
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be two separate blocks I think.

Suggested change
spec.describe('calling player API when a source is loaded', () => {
spec.it(
'emits a Play and Playing events after calling play API',
async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await callPlayerAndExpectEvents((player) => {
player.play();
}, EventSequence(EventType.Play, EventType.Playing));
});
}
);
spec.it('emits a Paused event after calling pause API', async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await playFor(1);
await callPlayerAndExpectEvent((player) => {
player.pause();
}, EventType.Paused);
});
});
});
spec.describe('calling play when a source is loaded', () => {
spec.it(
'emits a Play and Playing events',
async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await callPlayerAndExpectEvents((player) => {
player.play();
}, EventSequence(EventType.Play, EventType.Playing));
});
}
);
});
spec.describe('calling pause when a source is loaded', () => {
spec.it('emits a Paused event', async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await playFor(1);
await callPlayerAndExpectEvent((player) => {
player.pause();
}, EventType.Paused);
});
});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied feedback in 118b30c

spec.describe('playing a source', () => {
spec.it('emits TimeChanged events', async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await callPlayerAndExpectEvents((player) => {
player.play();
}, EventSequence(EventType.Play, EventType.Playing));
await expectEvents(RepeatedEvent(EventType.TimeChanged, 5));
});
});
});
spec.describe('playing a source to its end', () => {
spec.it('emits PlaybackFinished event', async () => {
await startPlayerTest({}, async () => {
await loadSourceConfig(Sources.artOfMotionHls);
await callPlayerAndExpectEvent(async (player) => {
player.play();
const duration = await player.getDuration();
player.seek(duration - 3);
}, EventType.PlaybackFinished);
});
});
});
};
22 changes: 22 additions & 0 deletions integration_test/tests/unloadingTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TestScope } from 'cavy';
import {
callPlayerAndExpectEvent,
EventType,
startPlayerTest,
} from '../playertesting';
import { Sources } from './helper/Sources';

export default (spec: TestScope) => {
spec.describe('unloading the player', () => {
spec.it('emits SourceUnloaded event', async () => {
await startPlayerTest({}, async () => {
await callPlayerAndExpectEvent((player) => {
player.load(Sources.artOfMotionHls);
}, EventType.Ready);
await callPlayerAndExpectEvent((player) => {
player.unload();
}, EventType.SourceUnloaded);
});
});
});
};