koel/resources/assets/js/components/playlist/PlaylistSidebarItem.spec.ts

58 lines
1.7 KiB
TypeScript
Raw Normal View History

import factory from '@/__tests__/factory'
import { expect, it } from 'vitest'
import { fireEvent } from '@testing-library/vue'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import PlaylistSidebarItem from './PlaylistSidebarItem.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
renderComponent (playlist: Record<string, any>, type: PlaylistType = 'playlist') {
return this.render(PlaylistSidebarItem, {
props: {
playlist,
type
}
})
}
protected test () {
it('edits the name of a standard playlist', async () => {
const { getByTestId, queryByTestId } = this.renderComponent(factory<Playlist>('playlist', {
id: 99,
name: 'A Standard Playlist'
}))
expect(await queryByTestId('name-editor')).toBeNull()
await fireEvent.dblClick(getByTestId('playlist-sidebar-item'))
getByTestId('name-editor')
})
it('does not allow editing the name of the "Favorites" playlist', async () => {
const { getByTestId, queryByTestId } = this.renderComponent({
name: 'Favorites',
songs: []
}, 'favorites')
expect(await queryByTestId('name-editor')).toBeNull()
await fireEvent.dblClick(getByTestId('playlist-sidebar-item'))
expect(await queryByTestId('name-editor')).toBeNull()
})
it('does not allow editing the name of the "Recently Played" playlist', async () => {
const { getByTestId, queryByTestId } = this.renderComponent({
name: 'Recently Played',
songs: []
}, 'recently-played')
expect(await queryByTestId('name-editor')).toBeNull()
await fireEvent.dblClick(getByTestId('playlist-sidebar-item'))
expect(await queryByTestId('name-editor')).toBeNull()
})
}
}