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

chore(PLAY-634): improve liveUi test #10

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all 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: 16 additions & 24 deletions test/puppeteer/tests/live-ui.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,10 @@ const Player = withComponents({

test("live-ui / player starts live", Player, async (t, page, player, live_ui) => {
await startPlayback(page, player, live_ui, true)
await page.evaluate((player) => {
const currentTime = player.currentTime
const edge = player.hls.liveSyncPosition

if (Math.abs(currentTime - edge) > 1) throw new Error("playback did not start from edge")
}, player)
})

test("live-ui / player starts from beginning", Player, async (t, page, player, live_ui) => {
await startPlayback(page, player, live_ui, false)
await page.evaluate((player) => {
const currentTime = player.currentTime
const start = player.hls.liveSyncPosition - player.live_state.dvr_window
if (Math.abs(currentTime - start) > 1) throw new Error("playback did not start from beginning")
}, player)
})

async function startPlayback(page, player, live_ui, live) {
Expand All @@ -37,17 +26,20 @@ async function startPlayback(page, player, live_ui, live) {
captureEvent(page, player, "loadeddata")
])

//wait for 10'' before starting playback
setTimeout(() => {
page.evaluate((live_ui, live) => {
const buttonSelector = live ? ".fp-live-edge" : ".fp-live-start"
live_ui.querySelector(buttonSelector).click()
}, live_ui, live)

}, 10_000)

await Promise.all([
captureEvent(page, player, "playing"),
captureEvent(page, player, "seeked"),
])
await page.evaluate((player, live_ui, live) => {
return new Promise((ok, err) => {
setTimeout(() => {
player.addEventListener("seeking", () => {
const currentTime = player.currentTime
const position = live ? player.hls.liveSyncPosition : player.hls.liveSyncPosition - player.live_state.dvr_window

if (Math.abs(position - currentTime) > 8) err(new Error(`The player did not seek at the ${live ? "edge" : "start"}`))
ok("")
})

const buttonSelector = live ? ".fp-live-edge" : ".fp-live-start"
live_ui.querySelector(buttonSelector).click()
}, 10_000)
})
}, player, live_ui, live)
}