test: add album tests

This commit is contained in:
Phan An 2022-05-03 19:39:46 +02:00
parent 729734da50
commit 17e3728023
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
11 changed files with 154 additions and 119 deletions

View file

@ -47,7 +47,7 @@
"@types/nprogress": "^0.2.0",
"@types/pusher-js": "^4.2.2",
"@types/youtube-player": "^5.5.2",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^4.11.1",
"@vitejs/plugin-vue": "^2.3.1",
"@vue/compiler-sfc": "^3.2.32",

View file

@ -21,7 +21,7 @@ export const mockHelper = {
return m
},
restoreMocks () {
restoreAllMocks () {
this.backup.forEach((fn, [obj, methodName]) => (obj[methodName] = fn))
this.backup = new Map()
}

View file

@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`componnents/song/track-list-item renders 1`] = `
<li title="" role="button" tabindex="0" class=""><span class="no">2</span> <span class="title">Foo and bar</span> <a href="http://koel.local/itunes/song/42?q=Foo%20and%20bar&amp;api_token=abcdef" target="_blank" title="View on iTunes" class="view-on-itunes">
iTunes
</a> <span class="length">00:42</span></li>
`;

View file

@ -1,57 +0,0 @@
import Component from '@/components/album/track-list-item.vue'
import { commonStore, songStore, queueStore } from '@/stores'
import { playbackService, localStorageService } from '@/services'
import factory from '@/__tests__/factory'
import { mock } from '@/__tests__/__helpers__'
import { shallow } from '@/__tests__/adapter'
describe('componnents/song/track-list-item', () => {
let song: Song
const track = {
title: 'Foo and bar',
fmtLength: '00:42'
}
const album = factory('album', { id: 42 })
window.BASE_URL = 'http://koel.local/'
beforeEach(() => {
commonStore.state.useiTunes = true
song = factory('song')
mock(localStorageService, 'get', 'abcdef')
})
afterEach(() => {
jest.resetModules()
jest.clearAllMocks()
})
it('renders', () => {
const wrapper = shallow(Component, {
propsData: {
track,
album,
index: 1
}
})
expect(wrapper).toMatchSnapshot()
})
it('plays', () => {
mock(songStore, 'guess', song)
const containsStub = mock(queueStore, 'contains', false)
const queueStub = mock(queueStore, 'queueAfterCurrent')
const playStub = mock(playbackService, 'play')
shallow(Component, {
propsData: {
track,
album,
index: 1
}
}).click('li')
expect(containsStub).toHaveBeenCalledWith(song)
expect(queueStub).toHaveBeenCalledWith(song)
expect(playStub).toHaveBeenCalledWith(song)
})
})

View file

@ -1,17 +0,0 @@
import Component from '@/components/album/AlbumTrackList.vue'
import TrackListItem from '@/components/album/track-list-item.vue'
import factory from '@/__tests__/factory'
import { mount } from '@/__tests__/adapter'
describe('components/album/track-list', () => {
it('lists the correct number of tracks', async () => {
const wrapper = mount(Component, {
propsData: {
album: factory('album')
}
})
await wrapper.vm.$nextTick()
expect(wrapper.findAll(TrackListItem)).toHaveLength(2)
})
})

View file

@ -10,7 +10,7 @@ let album: Album
beforeEach(() => {
vi.restoreAllMocks()
mockHelper.restoreMocks()
mockHelper.restoreAllMocks()
cleanup()
album = factory<Album>('album', {

View file

@ -9,7 +9,7 @@ let album: Album
beforeEach(() => {
vi.restoreAllMocks()
mockHelper.restoreMocks()
mockHelper.restoreAllMocks()
cleanup()
album = factory<Album>('album', {

View file

@ -1,13 +1,13 @@
import { render } from '@/__tests__/__helpers__'
import factory from '@/__tests__/factory'
import { cleanup } from '@testing-library/vue'
import { beforeEach, expect, test } from 'vitest'
import { beforeEach, expect, it } from 'vitest'
import AlbumTrackList from './AlbumTrackList.vue'
import TrackListItem from './AlbumTrackListItem.vue'
beforeEach(() => cleanup())
test('list the correct number of tracks', () => {
it('lists the correct number of tracks', () => {
const { queryAllByTestId } = render(AlbumTrackList, {
props: {
album: factory<Album>('album')

View file

@ -0,0 +1,54 @@
import { cleanup, fireEvent } from '@testing-library/vue'
import { beforeEach, expect, it } from 'vitest'
import factory from '@/__tests__/factory'
import { mockHelper, render } from '@/__tests__/__helpers__'
import { commonStore, queueStore, songStore } from '@/stores'
import { playbackService } from '@/services'
import AlbumTrackListItem from './AlbumTrackListItem.vue'
let song: Song
const track = {
title: 'Fahrstuhl to Heaven',
fmtLength: '00:42'
}
const album = factory<Album>('album', { id: 42 })
beforeEach(() => {
cleanup()
mockHelper.restoreAllMocks()
song = factory<Song>('song')
commonStore.state.useiTunes = true
})
it('renders', () => {
const { html } = render(AlbumTrackListItem, {
props: {
album,
track
}
})
expect(html()).toMatchSnapshot()
})
it('plays', async () => {
const guessMock = mockHelper.mock(songStore, 'guess', song)
const queueMock = mockHelper.mock(queueStore, 'queueIfNotQueued')
const playMock = mockHelper.mock(playbackService, 'play')
const { getByTitle } = render(AlbumTrackListItem, {
props: {
album,
track
}
})
await fireEvent.click(getByTitle('Click to play'))
expect(guessMock).toHaveBeenCalledWith('Fahrstuhl to Heaven', album)
expect(queueMock).toHaveBeenNthCalledWith(1, song)
expect(playMock).toHaveBeenNthCalledWith(1, song)
})

View file

@ -0,0 +1,3 @@
// Vitest Snapshot v1
exports[`renders 1`] = `"<li class=\\"\\" title=\\"\\" tabindex=\\"0\\" data-v-d8ad5538=\\"\\"><span class=\\"title\\" data-v-d8ad5538=\\"\\">Fahrstuhl to Heaven</span><a href=\\"undefineditunes/song/42?q=Fahrstuhl%20to%20Heaven&amp;api_token=null\\" class=\\"view-on-itunes\\" target=\\"_blank\\" title=\\"View on iTunes\\" data-v-d8ad5538=\\"\\"> iTunes </a><span class=\\"length\\" data-v-d8ad5538=\\"\\">00:42</span></li>"`;

123
yarn.lock
View file

@ -1328,11 +1328,6 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
"@types/json-schema@^7.0.3":
version "7.0.6"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==
"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
@ -1464,30 +1459,20 @@
resolved "https://registry.yarnpkg.com/@types/youtube-player/-/youtube-player-5.5.6.tgz#d9ee9c8c6cc6f313cd7d52ef94d303148791c7b9"
integrity sha512-RcWWUEuAZZX24dG55Xk558/HHCZxYf798/xPnV6wTwDlUF8HZNAmqyXyi+4QgN2l9juP9GRjCwILxXLSPKQBBw==
"@typescript-eslint/eslint-plugin@^4.11.1":
version "4.11.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.11.1.tgz#7579c6d17ad862154c10bc14b40e5427b729e209"
integrity sha512-fABclAX2QIEDmTMk6Yd7Muv1CzFLwWM4505nETzRHpP3br6jfahD9UUJkhnJ/g2m7lwfz8IlswcwGGPGiq9exw==
"@typescript-eslint/eslint-plugin@^5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.22.0.tgz#7b52a0de2e664044f28b36419210aea4ab619e2a"
integrity sha512-YCiy5PUzpAeOPGQ7VSGDEY2NeYUV1B0swde2e0HzokRsHBYjSdF6DZ51OuRZxVPHx0032lXGLvOMls91D8FXlg==
dependencies:
"@typescript-eslint/experimental-utils" "4.11.1"
"@typescript-eslint/scope-manager" "4.11.1"
debug "^4.1.1"
"@typescript-eslint/scope-manager" "5.22.0"
"@typescript-eslint/type-utils" "5.22.0"
"@typescript-eslint/utils" "5.22.0"
debug "^4.3.2"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/experimental-utils@4.11.1":
version "4.11.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.11.1.tgz#2dad3535b878c25c7424e40bfa79d899f3f485bc"
integrity sha512-mAlWowT4A6h0TC9F+J5pdbEhjNiEMO+kqPKQ4sc3fVieKL71dEqfkKgtcFVSX3cjSBwYwhImaQ/mXQF0oaI38g==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/scope-manager" "4.11.1"
"@typescript-eslint/types" "4.11.1"
"@typescript-eslint/typescript-estree" "4.11.1"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
ignore "^5.1.8"
regexpp "^3.2.0"
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/parser@^4.11.1":
version "4.11.1"
@ -1507,11 +1492,33 @@
"@typescript-eslint/types" "4.11.1"
"@typescript-eslint/visitor-keys" "4.11.1"
"@typescript-eslint/scope-manager@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.22.0.tgz#590865f244ebe6e46dc3e9cab7976fc2afa8af24"
integrity sha512-yA9G5NJgV5esANJCO0oF15MkBO20mIskbZ8ijfmlKIvQKg0ynVKfHZ15/nhAJN5m8Jn3X5qkwriQCiUntC9AbA==
dependencies:
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/visitor-keys" "5.22.0"
"@typescript-eslint/type-utils@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.22.0.tgz#0c0e93b34210e334fbe1bcb7250c470f4a537c19"
integrity sha512-iqfLZIsZhK2OEJ4cQ01xOq3NaCuG5FQRKyHicA3xhZxMgaxQazLUHbH/B2k9y5i7l3+o+B5ND9Mf1AWETeMISA==
dependencies:
"@typescript-eslint/utils" "5.22.0"
debug "^4.3.2"
tsutils "^3.21.0"
"@typescript-eslint/types@4.11.1":
version "4.11.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.11.1.tgz#3ba30c965963ef9f8ced5a29938dd0c465bd3e05"
integrity sha512-5kvd38wZpqGY4yP/6W3qhYX6Hz0NwUbijVsX2rxczpY6OXaMxh0+5E5uLJKVFwaBM7PJe1wnMym85NfKYIh6CA==
"@typescript-eslint/types@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.22.0.tgz#50a4266e457a5d4c4b87ac31903b28b06b2c3ed0"
integrity sha512-T7owcXW4l0v7NTijmjGWwWf/1JqdlWiBzPqzAWhobxft0SiEvMJB56QXmeCQjrPuM8zEfGUKyPQr/L8+cFUBLw==
"@typescript-eslint/typescript-estree@4.11.1":
version "4.11.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.11.1.tgz#a4416b4a65872a48773b9e47afabdf7519eb10bc"
@ -1526,6 +1533,31 @@
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.22.0.tgz#e2116fd644c3e2fda7f4395158cddd38c0c6df97"
integrity sha512-EyBEQxvNjg80yinGE2xdhpDYm41so/1kOItl0qrjIiJ1kX/L/L8WWGmJg8ni6eG3DwqmOzDqOhe6763bF92nOw==
dependencies:
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/visitor-keys" "5.22.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/utils@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.22.0.tgz#1f2c4897e2cf7e44443c848a13c60407861babd8"
integrity sha512-HodsGb037iobrWSUMS7QH6Hl1kppikjA1ELiJlNSTYf/UdMEwzgj0WIp+lBNb6WZ3zTwb0tEz51j0Wee3iJ3wQ==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.22.0"
"@typescript-eslint/types" "5.22.0"
"@typescript-eslint/typescript-estree" "5.22.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
"@typescript-eslint/visitor-keys@4.11.1":
version "4.11.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.11.1.tgz#4c050a4c1f7239786e2dd4e69691436143024e05"
@ -1534,6 +1566,14 @@
"@typescript-eslint/types" "4.11.1"
eslint-visitor-keys "^2.0.0"
"@typescript-eslint/visitor-keys@5.22.0":
version "5.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.22.0.tgz#f49c0ce406944ffa331a1cfabeed451ea4d0909c"
integrity sha512-DbgTqn2Dv5RFWluG88tn0pP6Ex0ROF+dpDO1TNNZdRtLjUr6bdznjA6f/qNqJLjd2PgguAES2Zgxh/JzwzETDg==
dependencies:
"@typescript-eslint/types" "5.22.0"
eslint-visitor-keys "^3.0.0"
"@vitejs/plugin-vue@^2.3.1":
version "2.3.1"
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz#5f286b8d3515381c6d5c8fa8eee5e6335f727e14"
@ -3908,7 +3948,7 @@ eslint-plugin-vue@^8.7.1:
semver "^7.3.5"
vue-eslint-parser "^8.0.1"
eslint-scope@5.1.1, eslint-scope@^5.0.0:
eslint-scope@5.1.1, eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==
@ -3948,7 +3988,7 @@ eslint-visitor-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==
eslint-visitor-keys@^3.1.0, eslint-visitor-keys@^3.3.0:
eslint-visitor-keys@^3.0.0, eslint-visitor-keys@^3.1.0, eslint-visitor-keys@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
@ -4212,7 +4252,7 @@ fast-deep-equal@^3.1.3:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
fast-glob@^3.0.3:
fast-glob@^3.0.3, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
@ -4657,6 +4697,18 @@ globby@^11.0.1:
merge2 "^1.3.0"
slash "^3.0.0"
globby@^11.0.4:
version "11.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
dependencies:
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.2.9"
ignore "^5.2.0"
merge2 "^1.4.1"
slash "^3.0.0"
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.2, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
@ -4969,7 +5021,7 @@ ieee754@^1.1.13, ieee754@^1.1.4:
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
ignore@^5.1.1, ignore@^5.2.0:
ignore@^5.1.1, ignore@^5.1.8, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
@ -5830,7 +5882,7 @@ merge-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
merge2@^1.2.3, merge2@^1.3.0:
merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
@ -8301,6 +8353,13 @@ tsutils@^3.17.1:
dependencies:
tslib "^1.8.1"
tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==
dependencies:
tslib "^1.8.1"
tty-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"