mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 08:26:16 -08:00
refactor(core): CORE-01 migrate utility contracts to TypeScript
This commit is contained in:
1 parent
e005e5f249
commit
d3c695024a
33 files changed
+1269
-305
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { expect, test } from './fixtures.js'
|
||||
|
||||
for (const core of ['published', 'candidate']) {
|
||||
test(`${core}: subtitle object URL contains real VTT data`, async ({ page }) => {
|
||||
await page.goto(`/test/player.html?core=${core}&chapter=published`)
|
||||
expect(await page.evaluate(async () => {
|
||||
const content = 'WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nText\n'
|
||||
const url = window.Artplayer.utils.vttToBlob(content)
|
||||
try {
|
||||
const response = await fetch(url)
|
||||
return { blob: url.startsWith('blob:'), type: response.headers.get('content-type'), text: await response.text() }
|
||||
}
|
||||
finally {
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
})).toEqual({ blob: true, type: 'text/vtt', text: 'WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nText\n' })
|
||||
})
|
||||
|
||||
test(`${core}: download starts and removes its temporary anchor`, async ({ page }) => {
|
||||
await page.goto(`/test/player.html?core=${core}&chapter=published`)
|
||||
const download = page.waitForEvent('download')
|
||||
await page.evaluate(() => window.Artplayer.utils.download('/test/pattern.mp4', 'sample.mp4'))
|
||||
const result = await download
|
||||
expect(result.suggestedFilename()).toBe('sample.mp4')
|
||||
expect(await result.failure()).toBeNull()
|
||||
await expect(page.locator('a[download]')).toHaveCount(0)
|
||||
})
|
||||
}
|
||||
|
||||
test('candidate download releases the anchor even when click fails', async ({ page }) => {
|
||||
await page.goto('/test/player.html?core=candidate&chapter=published')
|
||||
expect(await page.evaluate(() => {
|
||||
const click = HTMLAnchorElement.prototype.click
|
||||
HTMLAnchorElement.prototype.click = () => {
|
||||
throw new Error('controlled click failure')
|
||||
}
|
||||
try {
|
||||
window.Artplayer.utils.download('/test/pattern.mp4', 'sample.mp4')
|
||||
}
|
||||
catch (error) {
|
||||
return error.message
|
||||
}
|
||||
finally {
|
||||
HTMLAnchorElement.prototype.click = click
|
||||
}
|
||||
})).toBe('controlled click failure')
|
||||
await expect(page.locator('a[download]')).toHaveCount(0)
|
||||
})
|
||||
Reference in new issue
Block a user