Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions packages/taro-h5/__tests__/media/video-context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Current } from '@tarojs/runtime'
import { createVideoContext } from '@tarojs/taro-h5'

describe('createVideoContext ID lookup', () => {
const previous = Current.page
afterEach(() => {
Current.page = previous
document.body.replaceChildren()
})

it.each(['clip', 'clip:1', 'clip"one', 'clip[1]', 'clip one'])('finds a literal ID %s in the current page', id => {
const page = document.createElement('div')
page.id = '/video-test'
const otherPage = document.createElement('div')
const other = document.createElement('taro-video-core')
other.id = id
otherPage.appendChild(other)
const video = document.createElement('taro-video-core')
video.id = id
page.appendChild(video)
document.body.append(otherPage, page)
Current.page = { path: page.id }
expect(createVideoContext(id)).toBe(video)
expect(createVideoContext('missing')).toBeUndefined()
})
})
2 changes: 1 addition & 1 deletion packages/taro-h5/src/api/media/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export * from './getVideoInfo'
export const createVideoContext: typeof Taro.createVideoContext = (id, inst) => {
const el = findDOM(inst) as HTMLVideoElement
// TODO HTMLVideoElement to VideoContext
return el?.querySelector(`taro-video-core[id=${id}]`) as unknown as Taro.VideoContext
return Array.from(el?.querySelectorAll('taro-video-core[id]') || []).find(video => video.id === id) as unknown as Taro.VideoContext
}

export const compressVideo = /* @__PURE__ */ temporarilyNotSupport('compressVideo')
Expand Down
Loading