feat(test): add home component tests

This commit is contained in:
Phan An 2022-07-10 18:12:04 +02:00
parent 79bfc29ec7
commit 12771c3194
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
8 changed files with 97 additions and 2 deletions

View file

@ -14,7 +14,7 @@
</div>
<MostPlayedArtists/>
<MostPlayedAlbum/>
<MostPlayedAlbums/>
<ToTopButton/>
</div>
@ -34,7 +34,7 @@ import RecentlyPlayedSongs from '@/components/screens/home/RecentlyPlayedSongs.v
import RecentlyAddedAlbums from '@/components/screens/home/RecentlyAddedAlbums.vue'
import RecentlyAddedSongs from '@/components/screens/home/RecentlyAddedSongs.vue'
import MostPlayedArtists from '@/components/screens/home/MostPlayedArtists.vue'
import MostPlayedAlbum from '@/components/screens/home/MostPlayedAlbum.vue'
import MostPlayedAlbums from '@/components/screens/home/MostPlayedAlbums.vue'
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
const { ToTopButton, scrolling } = useInfiniteScroll(() => noop())

View file

@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { overviewStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import MostPlayedAlbums from './MostPlayedAlbums.vue'
new class extends UnitTestCase {
protected test () {
it('displays the albums', () => {
overviewStore.state.mostPlayedAlbums = factory<Album[]>('album', 6)
expect(this.render(MostPlayedAlbums).getAllByTestId('album-card')).toHaveLength(6)
})
}
}

View file

@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { overviewStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import MostPlayedArtists from './MostPlayedArtists.vue'
new class extends UnitTestCase {
protected test () {
it('displays the artists', () => {
overviewStore.state.mostPlayedArtists = factory<Artist[]>('artist', 6)
expect(this.render(MostPlayedArtists).getAllByTestId('artist-card')).toHaveLength(6)
})
}
}

View file

@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { overviewStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import MostPlayedSongs from './MostPlayedSongs.vue'
new class extends UnitTestCase {
protected test () {
it('displays the songs', () => {
overviewStore.state.mostPlayedSongs = factory<Song[]>('song', 6)
expect(this.render(MostPlayedSongs).getAllByTestId('song-card')).toHaveLength(6)
})
}
}

View file

@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { overviewStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import RecentlyAddedAlbums from './RecentlyAddedAlbums.vue'
new class extends UnitTestCase {
protected test () {
it('displays the albums', () => {
overviewStore.state.recentlyAddedAlbums = factory<Album[]>('album', 6)
expect(this.render(RecentlyAddedAlbums).getAllByTestId('album-card')).toHaveLength(6)
})
}
}

View file

@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { overviewStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import RecentlyAddedSongs from './RecentlyAddedSongs.vue'
new class extends UnitTestCase {
protected test () {
it('displays the songs', () => {
overviewStore.state.recentlyAddedSongs = factory<Song[]>('song', 6)
expect(this.render(RecentlyAddedSongs).getAllByTestId('song-card')).toHaveLength(6)
})
}
}

View file

@ -0,0 +1,25 @@
import { expect, it } from 'vitest'
import { recentlyPlayedStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import RecentlyPlayedSongs from './RecentlyPlayedSongs.vue'
import { fireEvent } from '@testing-library/vue'
import router from '@/router'
new class extends UnitTestCase {
protected test () {
it('displays the songs', () => {
recentlyPlayedStore.excerptState.songs = factory<Song[]>('song', 6)
expect(this.render(RecentlyPlayedSongs).getAllByTestId('song-card')).toHaveLength(6)
})
it('goes to dedicated screen', async () => {
const mock = this.mock(router, 'go')
const { getByTestId } = this.render(RecentlyPlayedSongs)
await fireEvent.click(getByTestId('home-view-all-recently-played-btn'))
expect(mock).toHaveBeenCalledWith('recently-played')
})
}
}