koel/resources/assets/js/components/ui/youtube/YouTubeVideoItem.spec.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import { screen } from '@testing-library/vue'
import { youTubeService } from '@/services'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import YouTubeVideoItem from './YouTubeVideoItem.vue'
let video: YouTubeVideo
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
2024-04-23 21:01:27 +00:00
protected test () {
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
it('plays', async () => {
const mock = this.mock(youTubeService, 'play')
this.renderComponent()
await this.user.click(screen.getByRole('button'))
expect(mock).toHaveBeenCalledWith(video)
})
}
private renderComponent () {
video = {
id: {
videoId: 'cLgJQ8Zj3AA',
},
snippet: {
title: 'Guess what it is',
description: 'From the LA Opening Gala 2014: John Williams Celebration',
thumbnails: {
default: {
url: 'https://i.ytimg.com/an_webp/cLgJQ8Zj3AA/mqdefault_6s.webp',
},
},
},
}
return this.render(YouTubeVideoItem, {
props: {
video,
},
})
}
}