Reintroduce unit testing for the frontend

This commit is contained in:
Georg Krause 2022-03-01 12:50:19 +01:00
parent 7dff941979
commit 8127bc10ba
No known key found for this signature in database
GPG Key ID: FD479B9A4D48E632
16 changed files with 213 additions and 283 deletions

View File

@ -10,7 +10,7 @@
"build:deployment": "vite build --base /front/", "build:deployment": "vite build --base /front/",
"serve": "vite preview", "serve": "vite preview",
"test:unit": "vitest run --dom --coverage", "test:unit": "vitest run --dom --coverage",
"lint": "eslint --ext .js,.vue src", "lint": "eslint --ext .js,.vue src tests",
"fix-fomantic-css": "scripts/fix-fomantic-css.sh", "fix-fomantic-css": "scripts/fix-fomantic-css.sh",
"i18n-compile": "scripts/i18n-compile.sh", "i18n-compile": "scripts/i18n-compile.sh",
"i18n-extract": "scripts/i18n-extract.sh", "i18n-extract": "scripts/i18n-extract.sh",

View File

@ -3,23 +3,23 @@ import { describe, it, expect } from 'vitest'
import { toLinearVolumeScale, toLogarithmicVolumeScale } from '@/audio/volume' import { toLinearVolumeScale, toLogarithmicVolumeScale } from '@/audio/volume'
describe('store/auth', () => { describe('store/auth', () => {
describe('toLinearVolumeScale', () => { describe('toLinearVolumeScale', () => {
it('it should return real 0', () => { it('it should return real 0', () => {
expect(toLinearVolumeScale(0.0)).to.equal(0.0) expect(toLinearVolumeScale(0.0)).to.equal(0.0)
})
it('it should return full volume', () => {
expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
})
}) })
describe('toLogarithmicVolumeScale', () => { it('it should return full volume', () => {
it('it should return real 0', () => { expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
expect(toLogarithmicVolumeScale(0.0)).to.equal(0.0)
})
it('it should return full volume', () => {
expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
})
}) })
})
describe('toLogarithmicVolumeScale', () => {
it('it should return real 0', () => {
expect(toLogarithmicVolumeScale(0.0)).to.equal(0.0)
})
it('it should return full volume', () => {
expect(toLogarithmicVolumeScale(1.0)).to.be.closeTo(1.0, 0.001)
})
})
}) })

View File

@ -3,8 +3,6 @@ import { mount } from '@vue/test-utils'
import Username from '@/components/common/Username.vue' import Username from '@/components/common/Username.vue'
import { render } from '../../utils'
describe('Username', () => { describe('Username', () => {
it('displays username', () => { it('displays username', () => {
const wrapper = mount(Username, { const wrapper = mount(Username, {
@ -12,7 +10,6 @@ describe('Username', () => {
username: 'Hello' username: 'Hello'
} }
}) })
const vm = render(Username, {username: 'Hello'})
expect(wrapper.text()).to.equal('Hello') expect(wrapper.text()).to.equal('Hello')
}) })
}) })

View File

@ -18,7 +18,7 @@ describe('PasswordInput', () => {
const inputElement = wrapper.find('input') const inputElement = wrapper.find('input')
expect(inputElement.element.value).to.equal(password) expect(inputElement.element.value).to.equal(password)
}) })
//it('copy password function called', () => { // it('copy password function called', () => {
// const spy = sandbox.spy() // const spy = sandbox.spy()
// wrapper.setMethods({ // wrapper.setMethods({
// copyPassword: spy // copyPassword: spy
@ -27,5 +27,5 @@ describe('PasswordInput', () => {
// const copyButton = wrapper.findAll('button').at(1) // const copyButton = wrapper.findAll('button').at(1)
// copyButton.trigger('click') // copyButton.trigger('click')
// sandbox.assert.calledOnce(spy) // sandbox.assert.calledOnce(spy)
//}) // })
}) })

View File

@ -1,51 +1,51 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import moment from 'moment' import moment from 'moment'
import {truncate, ago, capitalize, year} from '@/filters' import { truncate, ago, capitalize, year } from '@/filters'
describe('filters', () => { describe('filters', () => {
describe('truncate', () => { describe('truncate', () => {
it('leave strings as it if correct size', () => { it('leave strings as it if correct size', () => {
const input = 'Hello world' const input = 'Hello world'
let output = truncate(input, 100) const output = truncate(input, 100)
expect(output).to.equal(input) expect(output).to.equal(input)
}) })
it('returns shorter string with character', () => { it('returns shorter string with character', () => {
const input = 'Hello world' const input = 'Hello world'
let output = truncate(input, 5) const output = truncate(input, 5)
expect(output).to.equal('Hello…') expect(output).to.equal('Hello…')
}) })
it('custom ellipsis', () => { it('custom ellipsis', () => {
const input = 'Hello world' const input = 'Hello world'
let output = truncate(input, 5, ' pouet') const output = truncate(input, 5, ' pouet')
expect(output).to.equal('Hello pouet') expect(output).to.equal('Hello pouet')
}) })
}) })
describe('ago', () => { describe('ago', () => {
it('works', () => { it('works', () => {
const input = new Date() const input = new Date()
let output = ago(input) const output = ago(input)
let expected = moment(input).calendar(input, { const expected = moment(input).calendar(input, {
sameDay: 'LT', sameDay: 'LT',
nextDay: 'L', nextDay: 'L',
nextWeek: 'L', nextWeek: 'L',
lastDay: 'L', lastDay: 'L',
lastWeek: 'L', lastWeek: 'L',
sameElse: 'L' sameElse: 'L'
}) })
expect(output).to.equal(expected) expect(output).to.equal(expected)
}) })
}) })
describe('year', () => { describe('year', () => {
it('works', () => { it('works', () => {
const input = '2017-07-13' const input = '2017-07-13'
let output = year(input) const output = year(input)
expect(output).to.equal(2017) expect(output).to.equal(2017)
}) })
}) })
describe('capitalize', () => { describe('capitalize', () => {
it('works', () => { it('works', () => {
const input = 'hello world' const input = 'hello world'
let output = capitalize(input) const output = capitalize(input)
expect(output).to.equal('Hello world') expect(output).to.equal('Hello world')
}) })
}) })

View File

@ -1,65 +1,65 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import {normalizeQuery, parseTokens, compileTokens} from '@/search' import { normalizeQuery, parseTokens, compileTokens } from '@/search'
describe('search', () => { describe('search', () => {
it('normalizeQuery returns correct tokens', () => { it('normalizeQuery returns correct tokens', () => {
const input = 'this is a "search query" yeah' const input = 'this is a "search query" yeah'
let output = normalizeQuery(input) const output = normalizeQuery(input)
expect(output).to.deep.equal(['this', 'is', 'a', 'search query', 'yeah']) expect(output).to.deep.equal(['this', 'is', 'a', 'search query', 'yeah'])
}) })
it('parseTokens can extract fields and values from tokens', () => { it('parseTokens can extract fields and values from tokens', () => {
const input = ['unhandled', 'key:value', 'status:pending', 'title:"some title"', 'anotherunhandled'] const input = ['unhandled', 'key:value', 'status:pending', 'title:"some title"', 'anotherunhandled']
let output = parseTokens(input) const output = parseTokens(input)
let expected = [ const expected = [
{ {
'field': null, field: null,
'value': 'unhandled' value: 'unhandled'
}, },
{ {
'field': 'key', field: 'key',
'value': 'value' value: 'value'
}, },
{ {
'field': 'status', field: 'status',
'value': 'pending', value: 'pending'
}, },
{ {
'field': 'title', field: 'title',
'value': 'some title' value: 'some title'
}, },
{ {
'field': null, field: null,
'value': 'anotherunhandled' value: 'anotherunhandled'
} }
] ]
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
it('compileTokens returns proper query string', () => { it('compileTokens returns proper query string', () => {
let input = [ const input = [
{ {
'field': null, field: null,
'value': 'unhandled' value: 'unhandled'
}, },
{ {
'field': 'key', field: 'key',
'value': 'value' value: 'value'
}, },
{ {
'field': 'status', field: 'status',
'value': 'pending', value: 'pending'
}, },
{ {
'field': 'title', field: 'title',
'value': 'some title' value: 'some title'
}, },
{ {
'field': null, field: null,
'value': 'anotherunhandled' value: 'anotherunhandled'
} }
] ]
const expected = 'unhandled key:value status:pending title:"some title" anotherunhandled' const expected = 'unhandled key:value status:pending title:"some title" anotherunhandled'
let output = compileTokens(input) const output = compileTokens(input)
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
}) })

View File

@ -4,7 +4,6 @@ import store from '@/store/auth'
import { testAction } from '../../utils' import { testAction } from '../../utils'
describe('store/auth', () => { describe('store/auth', () => {
describe('mutations', () => { describe('mutations', () => {
it('profile', () => { it('profile', () => {
const state = {} const state = {}
@ -42,47 +41,47 @@ describe('store/auth', () => {
}) })
it('token real', () => { it('token real', () => {
const state = {} const state = {}
let token = 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTUxNTUzMzQyOSwiZXhwIjoxNTE1NTM3MDI5LCJpYXQiOjE1MTU1MzM0MjksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.' const token = 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTUxNTUzMzQyOSwiZXhwIjoxNTE1NTM3MDI5LCJpYXQiOjE1MTU1MzM0MjksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.'
store.mutations.token(state, token) store.mutations.token(state, token)
expect(state.token).to.equal(token) expect(state.token).to.equal(token)
}) })
it('permissions', () => { it('permissions', () => {
const state = { availablePermissions: {} } const state = { availablePermissions: {} }
store.mutations.permission(state, {key: 'admin', status: true}) store.mutations.permission(state, { key: 'admin', status: true })
expect(state.availablePermissions).to.deep.equal({admin: true}) expect(state.availablePermissions).to.deep.equal({ admin: true })
}) })
}) })
describe('getters', () => { describe('getters', () => {
it('header', () => { it('header', () => {
const state = { oauth: {accessToken: 'helloworld' }} const state = { oauth: { accessToken: 'helloworld' } }
expect(store.getters['header'](state)).to.equal('Bearer helloworld') expect(store.getters.header(state)).to.equal('Bearer helloworld')
}) })
}) })
describe('actions', () => { describe('actions', () => {
it('logout', () => { it('logout', () => {
testAction({ testAction({
action: store.actions.logout, action: store.actions.logout,
params: {state: {}}, params: { state: {} },
expectedMutations: [ expectedMutations: [
{ type: 'auth/reset', payload: null, options: {root: true} }, { type: 'auth/reset', payload: null, options: { root: true } },
{ type: 'favorites/reset', payload: null, options: {root: true} }, { type: 'favorites/reset', payload: null, options: { root: true } },
{ type: 'player/reset', payload: null, options: {root: true} }, { type: 'player/reset', payload: null, options: { root: true } },
{ type: 'playlists/reset', payload: null, options: {root: true} }, { type: 'playlists/reset', payload: null, options: { root: true } },
{ type: 'queue/reset', payload: null, options: {root: true} }, { type: 'queue/reset', payload: null, options: { root: true } },
{ type: 'radios/reset', payload: null, options: {root: true} } { type: 'radios/reset', payload: null, options: { root: true } }
] ]
}) })
}) })
it('check jwt null', () => { it('check jwt null', () => {
testAction({ testAction({
action: store.actions.check, action: store.actions.check,
params: {state: {}}, params: { state: {} },
expectedMutations: [ expectedMutations: [
{ type: 'authenticated', payload: false }, { type: 'authenticated', payload: false },
{ type: 'authenticated', payload: true }, { type: 'authenticated', payload: true }
], ],
expectedActions: [ expectedActions: [
{ type: 'fetchProfile' }, { type: 'fetchProfile' }
] ]
}) })
}) })
@ -99,17 +98,17 @@ describe('store/auth', () => {
{ type: 'authenticated', payload: true }, { type: 'authenticated', payload: true },
{ type: 'profile', payload: profile }, { type: 'profile', payload: profile },
{ type: 'username', payload: profile.username }, { type: 'username', payload: profile.username },
{ type: 'permission', payload: {key: 'admin', status: true} } { type: 'permission', payload: { key: 'admin', status: true } }
], ],
expectedActions: [ expectedActions: [
{ type: 'ui/initSettings', payload: { root: true } }, { type: 'ui/initSettings', payload: { root: true } },
{ type: 'updateProfile', payload: profile }, { type: 'updateProfile', payload: profile },
{ type: 'ui/fetchUnreadNotifications', payload: null }, { type: 'ui/fetchUnreadNotifications', payload: null },
{ type: 'favorites/fetch', payload: null, options: {root: true} }, { type: 'favorites/fetch', payload: null, options: { root: true } },
{ type: 'channels/fetchSubscriptions', payload: null, options: {root: true} }, { type: 'channels/fetchSubscriptions', payload: null, options: { root: true } },
{ type: 'libraries/fetchFollows', payload: null, options: {root: true} }, { type: 'libraries/fetchFollows', payload: null, options: { root: true } },
{ type: 'moderation/fetchContentFilters', payload: null, options: {root: true} }, { type: 'moderation/fetchContentFilters', payload: null, options: { root: true } },
{ type: 'playlists/fetchOwn', payload: null, options: {root: true} } { type: 'playlists/fetchOwn', payload: null, options: { root: true } }
] ]
}) })
}) })

View File

@ -8,13 +8,13 @@ describe('store/favorites', () => {
describe('mutations', () => { describe('mutations', () => {
it('track true', () => { it('track true', () => {
const state = { tracks: [] } const state = { tracks: [] }
store.mutations.track(state, {id: 1, value: true}) store.mutations.track(state, { id: 1, value: true })
expect(state.tracks).to.deep.equal([1]) expect(state.tracks).to.deep.equal([1])
expect(state.count).to.deep.equal(1) expect(state.count).to.deep.equal(1)
}) })
it('track false', () => { it('track false', () => {
const state = { tracks: [1] } const state = { tracks: [1] }
store.mutations.track(state, {id: 1, value: false}) store.mutations.track(state, { id: 1, value: false })
expect(state.tracks).to.deep.equal([]) expect(state.tracks).to.deep.equal([])
expect(state.count).to.deep.equal(0) expect(state.count).to.deep.equal(0)
}) })
@ -22,11 +22,11 @@ describe('store/favorites', () => {
describe('getters', () => { describe('getters', () => {
it('isFavorite true', () => { it('isFavorite true', () => {
const state = { tracks: [1] } const state = { tracks: [1] }
expect(store.getters['isFavorite'](state)(1)).to.equal(true) expect(store.getters.isFavorite(state)(1)).to.equal(true)
}) })
it('isFavorite false', () => { it('isFavorite false', () => {
const state = { tracks: [] } const state = { tracks: [] }
expect(store.getters['isFavorite'](state)(1)).to.equal(false) expect(store.getters.isFavorite(state)(1)).to.equal(false)
}) })
}) })
describe('actions', () => { describe('actions', () => {
@ -34,9 +34,9 @@ describe('store/favorites', () => {
testAction({ testAction({
action: store.actions.toggle, action: store.actions.toggle,
payload: 1, payload: 1,
params: {getters: {isFavorite: () => false}}, params: { getters: { isFavorite: () => false } },
expectedActions: [ expectedActions: [
{ type: 'set', payload: {id: 1, value: true} } { type: 'set', payload: { id: 1, value: true } }
] ]
}) })
}) })
@ -44,9 +44,9 @@ describe('store/favorites', () => {
testAction({ testAction({
action: store.actions.toggle, action: store.actions.toggle,
payload: 1, payload: 1,
params: {getters: {isFavorite: () => true}}, params: { getters: { isFavorite: () => true } },
expectedActions: [ expectedActions: [
{ type: 'set', payload: {id: 1, value: false} } { type: 'set', payload: { id: 1, value: false } }
] ]
}) })
}) })

View File

@ -1,23 +1,22 @@
import { describe, beforeEach, afterEach, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import store from '@/store/instance' import store from '@/store/instance'
import { testAction } from '../../utils' import { testAction } from '../../utils'
describe('store/instance', () => { describe('store/instance', () => {
describe('mutations', () => { describe('mutations', () => {
it('settings', () => { it('settings', () => {
const state = {settings: {users: {upload_quota: {value: 1}}}} const state = { settings: { users: { upload_quota: { value: 1 } } } }
let settings = {users: {registration_enabled: {value: true}}} const settings = { users: { registration_enabled: { value: true } } }
store.mutations.settings(state, settings) store.mutations.settings(state, settings)
expect(state.settings).to.deep.equal({ expect(state.settings).to.deep.equal({
users: {upload_quota: {value: 1}, registration_enabled: {value: true}} users: { upload_quota: { value: 1 }, registration_enabled: { value: true } }
}) })
}) })
it('instanceUrl', () => { it('instanceUrl', () => {
const state = {instanceUrl: null, knownInstances: ['http://test2/', 'http://test/']} const state = { instanceUrl: null, knownInstances: ['http://test2/', 'http://test/'] }
store.mutations.instanceUrl(state, 'http://test') store.mutations.instanceUrl(state, 'http://test')
expect(state).to.deep.equal({ expect(state).to.deep.equal({
instanceUrl: 'http://test/', // trailing slash added instanceUrl: 'http://test/', // trailing slash added
knownInstances: ['http://test/', 'http://test2/'] knownInstances: ['http://test/', 'http://test2/']
}) })
}) })

View File

@ -90,15 +90,15 @@ describe('store/player', () => {
describe('getters', () => { describe('getters', () => {
it('durationFormatted', () => { it('durationFormatted', () => {
const state = { duration: 12.51 } const state = { duration: 12.51 }
expect(store.getters['durationFormatted'](state)).to.equal('0:13') expect(store.getters.durationFormatted(state)).to.equal('0:13')
}) })
it('currentTimeFormatted', () => { it('currentTimeFormatted', () => {
const state = { currentTime: 12.51 } const state = { currentTime: 12.51 }
expect(store.getters['currentTimeFormatted'](state)).to.equal('0:13') expect(store.getters.currentTimeFormatted(state)).to.equal('0:13')
}) })
it('progress', () => { it('progress', () => {
const state = { currentTime: 4, duration: 10 } const state = { currentTime: 4, duration: 10 }
expect(store.getters['progress'](state)).to.equal(40) expect(store.getters.progress(state)).to.equal(40)
}) })
}) })
describe('actions', () => { describe('actions', () => {
@ -106,7 +106,7 @@ describe('store/player', () => {
testAction({ testAction({
action: store.actions.incrementVolume, action: store.actions.incrementVolume,
payload: 0.2, payload: 0.2,
params: {state: {volume: 0.7}}, params: { state: { volume: 0.7 } },
expectedMutations: [ expectedMutations: [
{ type: 'volume', payload: 0.7 + 0.2 } { type: 'volume', payload: 0.7 + 0.2 }
] ]
@ -115,7 +115,7 @@ describe('store/player', () => {
it('toggle playback false', () => { it('toggle playback false', () => {
testAction({ testAction({
action: store.actions.togglePlayback, action: store.actions.togglePlayback,
params: {state: {playing: false}}, params: { state: { playing: false } },
expectedMutations: [ expectedMutations: [
{ type: 'playing', payload: true } { type: 'playing', payload: true }
] ]
@ -124,7 +124,7 @@ describe('store/player', () => {
it('toggle playback true', () => { it('toggle playback true', () => {
testAction({ testAction({
action: store.actions.togglePlayback, action: store.actions.togglePlayback,
params: {state: {playing: true}}, params: { state: { playing: true } },
expectedMutations: [ expectedMutations: [
{ type: 'playing', payload: false } { type: 'playing', payload: false }
] ]
@ -133,7 +133,7 @@ describe('store/player', () => {
it('resume playback', () => { it('resume playback', () => {
testAction({ testAction({
action: store.actions.resumePlayback, action: store.actions.resumePlayback,
params: {state: {}}, params: { state: {} },
expectedMutations: [ expectedMutations: [
{ type: 'playing', payload: true } { type: 'playing', payload: true }
] ]
@ -150,35 +150,35 @@ describe('store/player', () => {
it('trackEnded', () => { it('trackEnded', () => {
testAction({ testAction({
action: store.actions.trackEnded, action: store.actions.trackEnded,
payload: {test: 'track'}, payload: { test: 'track' },
params: {rootState: {queue: {currentIndex: 0, tracks: [1, 2]}}}, params: { rootState: { queue: { currentIndex: 0, tracks: [1, 2] } } },
expectedActions: [ expectedActions: [
{ type: 'queue/next', payload: null, options: {root: true} } { type: 'queue/next', payload: null, options: { root: true } }
] ]
}) })
}) })
it('trackEnded calls populateQueue if last', () => { it('trackEnded calls populateQueue if last', () => {
testAction({ testAction({
action: store.actions.trackEnded, action: store.actions.trackEnded,
payload: {test: 'track'}, payload: { test: 'track' },
params: {rootState: {queue: {currentIndex: 1, tracks: [1, 2]}}}, params: { rootState: { queue: { currentIndex: 1, tracks: [1, 2] } } },
expectedActions: [ expectedActions: [
{ type: 'radios/populateQueue', payload: null, options: {root: true} }, { type: 'radios/populateQueue', payload: null, options: { root: true } },
{ type: 'queue/next', payload: null, options: {root: true} } { type: 'queue/next', payload: null, options: { root: true } }
] ]
}) })
}) })
it('trackErrored', () => { it('trackErrored', () => {
testAction({ testAction({
action: store.actions.trackErrored, action: store.actions.trackErrored,
payload: {test: 'track'}, payload: { test: 'track' },
params: {state: {errorCount: 0, maxConsecutiveErrors: 5}}, params: { state: { errorCount: 0, maxConsecutiveErrors: 5 } },
expectedMutations: [ expectedMutations: [
{ type: 'errored', payload: true }, { type: 'errored', payload: true },
{ type: 'incrementErrorCount' } { type: 'incrementErrorCount' }
], ],
expectedActions: [ expectedActions: [
{ type: 'queue/next', payload: null, options: {root: true} } { type: 'queue/next', payload: null, options: { root: true } }
] ]
}) })
}) })
@ -194,19 +194,19 @@ describe('store/player', () => {
it('mute', () => { it('mute', () => {
testAction({ testAction({
action: store.actions.mute, action: store.actions.mute,
params: {state: { volume: 0.7, tempVolume: 0}}, params: { state: { volume: 0.7, tempVolume: 0 } },
expectedMutations: [ expectedMutations: [
{ type: 'tempVolume', payload: 0.7 }, { type: 'tempVolume', payload: 0.7 },
{ type: 'volume', payload: 0 }, { type: 'volume', payload: 0 }
] ]
}) })
}) })
it('unmute', () => { it('unmute', () => {
testAction({ testAction({
action: store.actions.unmute, action: store.actions.unmute,
params: {state: { volume: 0, tempVolume: 0.8}}, params: { state: { volume: 0, tempVolume: 0.8 } },
expectedMutations: [ expectedMutations: [
{ type: 'volume', payload: 0.8 }, { type: 'volume', payload: 0.8 }
] ]
}) })
}) })

View File

@ -1,15 +1,14 @@
import { describe, beforeEach, afterEach, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import store from '@/store/playlists' import store from '@/store/playlists'
import { testAction } from '../../utils' import { testAction } from '../../utils'
describe('store/playlists', () => { describe('store/playlists', () => {
describe('mutations', () => { describe('mutations', () => {
it('set playlists', () => { it('set playlists', () => {
const state = { playlists: [] } const state = { playlists: [] }
store.mutations.playlists(state, [{id: 1, name: 'test'}]) store.mutations.playlists(state, [{ id: 1, name: 'test' }])
expect(state.playlists).to.deep.equal([{id: 1, name: 'test'}]) expect(state.playlists).to.deep.equal([{ id: 1, name: 'test' }])
}) })
}) })
describe('actions', () => { describe('actions', () => {
@ -17,7 +16,7 @@ describe('store/playlists', () => {
testAction({ testAction({
action: store.actions.fetchOwn, action: store.actions.fetchOwn,
payload: null, payload: null,
params: {state: { playlists: [] }, rootState: {auth: {profile: {}}}}, params: { state: { playlists: [] }, rootState: { auth: { profile: {} } } },
expectedMutations: [] expectedMutations: []
}) })
}) })

View File

@ -1,12 +1,9 @@
import { it, describe, expect } from 'vitest' import { it, describe, expect } from 'vitest'
import _ from 'lodash'
import store from '@/store/queue' import store from '@/store/queue'
import { testAction } from '../../utils' import { testAction } from '../../utils'
describe('store/queue', () => { describe('store/queue', () => {
describe('mutations', () => { describe('mutations', () => {
it('currentIndex', () => { it('currentIndex', () => {
const state = {} const state = {}
@ -24,97 +21,97 @@ describe('store/queue', () => {
expect(state.tracks).to.deep.equal([1, 2]) expect(state.tracks).to.deep.equal([1, 2])
}) })
it('splice', () => { it('splice', () => {
const state = {tracks: [1, 2, 3]} const state = { tracks: [1, 2, 3] }
store.mutations.splice(state, {start: 1, size: 2}) store.mutations.splice(state, { start: 1, size: 2 })
expect(state.tracks).to.deep.equal([1]) expect(state.tracks).to.deep.equal([1])
}) })
it('insert', () => { it('insert', () => {
const state = {tracks: [1, 3]} const state = { tracks: [1, 3] }
store.mutations.insert(state, {track: 2, index: 1}) store.mutations.insert(state, { track: 2, index: 1 })
expect(state.tracks).to.deep.equal([1, 2, 3]) expect(state.tracks).to.deep.equal([1, 2, 3])
}) })
it('reorder before', () => { it('reorder before', () => {
const state = {currentIndex: 3} const state = { currentIndex: 3 }
store.mutations.reorder(state, {oldIndex: 2, newIndex: 1}) store.mutations.reorder(state, { oldIndex: 2, newIndex: 1 })
expect(state.currentIndex).to.equal(3) expect(state.currentIndex).to.equal(3)
}) })
it('reorder from after to before', () => { it('reorder from after to before', () => {
const state = {currentIndex: 3} const state = { currentIndex: 3 }
store.mutations.reorder(state, {oldIndex: 4, newIndex: 1}) store.mutations.reorder(state, { oldIndex: 4, newIndex: 1 })
expect(state.currentIndex).to.equal(4) expect(state.currentIndex).to.equal(4)
}) })
it('reorder after', () => { it('reorder after', () => {
const state = {currentIndex: 3} const state = { currentIndex: 3 }
store.mutations.reorder(state, {oldIndex: 4, newIndex: 5}) store.mutations.reorder(state, { oldIndex: 4, newIndex: 5 })
expect(state.currentIndex).to.equal(3) expect(state.currentIndex).to.equal(3)
}) })
it('reorder before to after', () => { it('reorder before to after', () => {
const state = {currentIndex: 3} const state = { currentIndex: 3 }
store.mutations.reorder(state, {oldIndex: 1, newIndex: 5}) store.mutations.reorder(state, { oldIndex: 1, newIndex: 5 })
expect(state.currentIndex).to.equal(2) expect(state.currentIndex).to.equal(2)
}) })
it('reorder current', () => { it('reorder current', () => {
const state = {currentIndex: 3} const state = { currentIndex: 3 }
store.mutations.reorder(state, {oldIndex: 3, newIndex: 1}) store.mutations.reorder(state, { oldIndex: 3, newIndex: 1 })
expect(state.currentIndex).to.equal(1) expect(state.currentIndex).to.equal(1)
}) })
}) })
describe('getters', () => { describe('getters', () => {
it('currentTrack', () => { it('currentTrack', () => {
const state = { tracks: [1, 2, 3], currentIndex: 2 } const state = { tracks: [1, 2, 3], currentIndex: 2 }
expect(store.getters['currentTrack'](state)).to.equal(3) expect(store.getters.currentTrack(state)).to.equal(3)
}) })
it('hasNext true', () => { it('hasNext true', () => {
const state = { tracks: [1, 2, 3], currentIndex: 1 } const state = { tracks: [1, 2, 3], currentIndex: 1 }
expect(store.getters['hasNext'](state)).to.equal(true) expect(store.getters.hasNext(state)).to.equal(true)
}) })
it('hasNext false', () => { it('hasNext false', () => {
const state = { tracks: [1, 2, 3], currentIndex: 2 } const state = { tracks: [1, 2, 3], currentIndex: 2 }
expect(store.getters['hasNext'](state)).to.equal(false) expect(store.getters.hasNext(state)).to.equal(false)
}) })
}) })
describe('actions', () => { describe('actions', () => {
it('append at end', () => { it('append at end', () => {
testAction({ testAction({
action: store.actions.append, action: store.actions.append,
payload: {track: 4}, payload: { track: 4 },
params: {state: {tracks: [1, 2, 3]}}, params: { state: { tracks: [1, 2, 3] } },
expectedMutations: [ expectedMutations: [
{ type: 'insert', payload: {track: 4, index: 3} } { type: 'insert', payload: { track: 4, index: 3 } }
] ]
}) })
}) })
it('append at index', () => { it('append at index', () => {
testAction({ testAction({
action: store.actions.append, action: store.actions.append,
payload: {track: 2, index: 1}, payload: { track: 2, index: 1 },
params: {state: {tracks: [1, 3]}}, params: { state: { tracks: [1, 3] } },
expectedMutations: [ expectedMutations: [
{ type: 'insert', payload: {track: 2, index: 1} } { type: 'insert', payload: { track: 2, index: 1 } }
] ]
}) })
}) })
it('appendMany', () => { it('appendMany', () => {
const tracks = [{title: 1}, {title: 2}] const tracks = [{ title: 1 }, { title: 2 }]
testAction({ testAction({
action: store.actions.appendMany, action: store.actions.appendMany,
payload: {tracks: tracks}, payload: { tracks: tracks },
params: {state: {tracks: []}}, params: { state: { tracks: [] } },
expectedActions: [ expectedActions: [
{ type: 'append', payload: {track: tracks[0], index: 0} }, { type: 'append', payload: { track: tracks[0], index: 0 } },
{ type: 'append', payload: {track: tracks[1], index: 1} }, { type: 'append', payload: { track: tracks[1], index: 1 } }
] ]
}) })
}) })
it('appendMany at index', () => { it('appendMany at index', () => {
const tracks = [{title: 1}, {title: 2}] const tracks = [{ title: 1 }, { title: 2 }]
testAction({ testAction({
action: store.actions.appendMany, action: store.actions.appendMany,
payload: {tracks: tracks, index: 1}, payload: { tracks: tracks, index: 1 },
params: {state: {tracks: [1, 2]}}, params: { state: { tracks: [1, 2] } },
expectedActions: [ expectedActions: [
{ type: 'append', payload: {track: tracks[0], index: 1} }, { type: 'append', payload: { track: tracks[0], index: 1 } },
{ type: 'append', payload: {track: tracks[1], index: 2} }, { type: 'append', payload: { track: tracks[1], index: 2 } }
] ]
}) })
}) })
@ -122,9 +119,9 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.cleanTrack, action: store.actions.cleanTrack,
payload: 3, payload: 3,
params: {state: {currentIndex: 2, tracks: [1, 2, 3, 4, 5]}}, params: { state: { currentIndex: 2, tracks: [1, 2, 3, 4, 5] } },
expectedMutations: [ expectedMutations: [
{ type: 'splice', payload: {start: 3, size: 1} } { type: 'splice', payload: { start: 3, size: 1 } }
] ]
}) })
}) })
@ -132,9 +129,9 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.cleanTrack, action: store.actions.cleanTrack,
payload: 1, payload: 1,
params: {state: {currentIndex: 2, tracks: []}}, params: { state: { currentIndex: 2, tracks: [] } },
expectedMutations: [ expectedMutations: [
{ type: 'splice', payload: {start: 1, size: 1} }, { type: 'splice', payload: { start: 1, size: 1 } },
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
] ]
}) })
@ -143,13 +140,13 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.cleanTrack, action: store.actions.cleanTrack,
payload: 2, payload: 2,
params: {state: {currentIndex: 2, tracks: []}}, params: { state: { currentIndex: 2, tracks: [] } },
expectedMutations: [ expectedMutations: [
{ type: 'splice', payload: {start: 2, size: 1} }, { type: 'splice', payload: { start: 2, size: 1 } },
{ type: 'currentIndex', payload: 2 } { type: 'currentIndex', payload: 2 }
], ],
expectedActions: [ expectedActions: [
{ type: 'player/stop', payload: null, options: {root: true} } { type: 'player/stop', payload: null, options: { root: true } }
] ]
}) })
}) })
@ -170,7 +167,7 @@ describe('store/queue', () => {
it('previous when at beginning', () => { it('previous when at beginning', () => {
testAction({ testAction({
action: store.actions.previous, action: store.actions.previous,
params: {state: {currentIndex: 0}}, params: { state: { currentIndex: 0 } },
expectedActions: [ expectedActions: [
{ type: 'currentIndex', payload: 0 } { type: 'currentIndex', payload: 0 }
] ]
@ -179,7 +176,7 @@ describe('store/queue', () => {
it('previous after less than 3 seconds of playback', () => { it('previous after less than 3 seconds of playback', () => {
testAction({ testAction({
action: store.actions.previous, action: store.actions.previous,
params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 1}}}, params: { state: { currentIndex: 1 }, rootState: { player: { currentTime: 1 } } },
expectedActions: [ expectedActions: [
{ type: 'currentIndex', payload: 0 } { type: 'currentIndex', payload: 0 }
] ]
@ -188,7 +185,7 @@ describe('store/queue', () => {
it('previous after more than 3 seconds of playback', () => { it('previous after more than 3 seconds of playback', () => {
testAction({ testAction({
action: store.actions.previous, action: store.actions.previous,
params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 3}}}, params: { state: { currentIndex: 1 }, rootState: { player: { currentTime: 3 } } },
expectedActions: [ expectedActions: [
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
] ]
@ -197,7 +194,7 @@ describe('store/queue', () => {
it('next on last track when looping on queue', () => { it('next on last track when looping on queue', () => {
testAction({ testAction({
action: store.actions.next, action: store.actions.next,
params: {state: {tracks: [1, 2], currentIndex: 1}, rootState: {player: {looping: 2}}}, params: { state: { tracks: [1, 2], currentIndex: 1 }, rootState: { player: { looping: 2 } } },
expectedActions: [ expectedActions: [
{ type: 'currentIndex', payload: 0 } { type: 'currentIndex', payload: 0 }
] ]
@ -206,7 +203,7 @@ describe('store/queue', () => {
it('next track when last track', () => { it('next track when last track', () => {
testAction({ testAction({
action: store.actions.next, action: store.actions.next,
params: {state: {tracks: [1, 2], currentIndex: 1}, rootState: {player: {looping: 0}}}, params: { state: { tracks: [1, 2], currentIndex: 1 }, rootState: { player: { looping: 0 } } },
expectedMutations: [ expectedMutations: [
{ type: 'ended', payload: true } { type: 'ended', payload: true }
] ]
@ -215,7 +212,7 @@ describe('store/queue', () => {
it('next track when not last track', () => { it('next track when not last track', () => {
testAction({ testAction({
action: store.actions.next, action: store.actions.next,
params: {state: {tracks: [1, 2], currentIndex: 0}, rootState: {player: {looping: 0}}}, params: { state: { tracks: [1, 2], currentIndex: 0 }, rootState: { player: { looping: 0 } } },
expectedActions: [ expectedActions: [
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
] ]
@ -225,10 +222,10 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.currentIndex, action: store.actions.currentIndex,
payload: 1, payload: 1,
params: {state: {tracks: [1, 2], currentIndex: 0}, rootState: {radios: {running: false}}}, params: { state: { tracks: [1, 2], currentIndex: 0 }, rootState: { radios: { running: false } } },
expectedMutations: [ expectedMutations: [
{ type: 'ended', payload: false }, { type: 'ended', payload: false },
{ type: 'player/currentTime', payload: 0, options: {root: true} }, { type: 'player/currentTime', payload: 0, options: { root: true } },
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
] ]
}) })
@ -237,10 +234,10 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.currentIndex, action: store.actions.currentIndex,
payload: 1, payload: 1,
params: {state: {tracks: [1, 2, 3, 4], currentIndex: 0}, rootState: {radios: {running: true}}}, params: { state: { tracks: [1, 2, 3, 4], currentIndex: 0 }, rootState: { radios: { running: true } } },
expectedMutations: [ expectedMutations: [
{ type: 'ended', payload: false }, { type: 'ended', payload: false },
{ type: 'player/currentTime', payload: 0, options: {root: true} }, { type: 'player/currentTime', payload: 0, options: { root: true } },
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
] ]
}) })
@ -249,14 +246,14 @@ describe('store/queue', () => {
testAction({ testAction({
action: store.actions.currentIndex, action: store.actions.currentIndex,
payload: 1, payload: 1,
params: {state: {tracks: [1, 2, 3], currentIndex: 0}, rootState: {radios: {running: true}}}, params: { state: { tracks: [1, 2, 3], currentIndex: 0 }, rootState: { radios: { running: true } } },
expectedMutations: [ expectedMutations: [
{ type: 'ended', payload: false }, { type: 'ended', payload: false },
{ type: 'player/currentTime', payload: 0, options: {root: true} }, { type: 'player/currentTime', payload: 0, options: { root: true } },
{ type: 'currentIndex', payload: 1 } { type: 'currentIndex', payload: 1 }
], ],
expectedActions: [ expectedActions: [
{ type: 'radios/populateQueue', payload: null, options: {root: true} } { type: 'radios/populateQueue', payload: null, options: { root: true } }
] ]
}) })
}) })
@ -268,28 +265,28 @@ describe('store/queue', () => {
{ type: 'ended', payload: true } { type: 'ended', payload: true }
], ],
expectedActions: [ expectedActions: [
{ type: 'radios/stop', payload: null, options: {root: true} }, { type: 'radios/stop', payload: null, options: { root: true } },
{ type: 'player/stop', payload: null, options: {root: true} }, { type: 'player/stop', payload: null, options: { root: true } },
{ type: 'currentIndex', payload: -1 } { type: 'currentIndex', payload: -1 }
] ]
}) })
}) })
//it('shuffle', () => { // it('shuffle', () => {
//let _shuffle = sandbox.stub(_, 'shuffle') // let _shuffle = sandbox.stub(_, 'shuffle')
//let tracks = ['a', 'b', 'c', 'd', 'e'] // let tracks = ['a', 'b', 'c', 'd', 'e']
//let shuffledTracks = ['a', 'b', 'e', 'd', 'c'] // let shuffledTracks = ['a', 'b', 'e', 'd', 'c']
//_shuffle.returns(shuffledTracks) // _shuffle.returns(shuffledTracks)
//testAction({ // testAction({
// action: store.actions.shuffle, // action: store.actions.shuffle,
// params: {state: {currentIndex: 1, tracks: tracks}}, // params: {state: {currentIndex: 1, tracks: tracks}},
// expectedMutations: [ // expectedMutations: [
// { type: 'tracks', payload: [] } // { type: 'tracks', payload: [] }
// ], // ],
// expectedActions: [ // expectedActions: [
// { type: 'appendMany', payload: {tracks: shuffledTracks} }, // { type: 'appendMany', payload: {tracks: shuffledTracks} },
// { type: 'currentIndex', payload: {tracks: shuffledTracks} } // { type: 'currentIndex', payload: {tracks: shuffledTracks} }
// ] // ]
//}) // })
//}) // })
}) })
}) })

View File

@ -1,10 +1,9 @@
import { describe, beforeEach, it, afterEach, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import store from '@/store/radios' import store from '@/store/radios'
import { testAction } from '../../utils' import { testAction } from '../../utils'
describe('store/radios', () => { describe('store/radios', () => {
describe('mutations', () => { describe('mutations', () => {
it('current', () => { it('current', () => {
const state = {} const state = {}
@ -21,7 +20,7 @@ describe('store/radios', () => {
it('start', () => { it('start', () => {
testAction({ testAction({
action: store.actions.start, action: store.actions.start,
payload: {type: 'favorites', objectId: 0, customRadioId: null}, payload: { type: 'favorites', objectId: 0, customRadioId: null },
expectedMutations: [ expectedMutations: [
{ {
type: 'current', type: 'current',
@ -42,7 +41,7 @@ describe('store/radios', () => {
it('stop', () => { it('stop', () => {
return testAction({ return testAction({
action: store.actions.stop, action: store.actions.stop,
params: {state: {}}, params: { state: {} },
expectedMutations: [ expectedMutations: [
{ type: 'current', payload: null }, { type: 'current', payload: null },
{ type: 'running', payload: false } { type: 'running', payload: false }
@ -53,29 +52,29 @@ describe('store/radios', () => {
return testAction({ return testAction({
action: store.actions.populateQueue, action: store.actions.populateQueue,
params: { params: {
state: {running: true, current: {session: 1}}, state: { running: true, current: { session: 1 } },
rootState: {player: {errorCount: 0, maxConsecutiveErrors: 5}} rootState: { player: { errorCount: 0, maxConsecutiveErrors: 5 } }
}, },
expectedActions: [ expectedActions: [
{ type: 'queue/append', payload: {track: {id: 1}}, options: {root: true} } { type: 'queue/append', payload: { track: { id: 1 } }, options: { root: true } }
] ]
}) })
}) })
it('populateQueue does nothing when not running', () => { it('populateQueue does nothing when not running', () => {
testAction({ testAction({
action: store.actions.populateQueue, action: store.actions.populateQueue,
params: {state: {running: false}}, params: { state: { running: false } },
expectedActions: [] expectedActions: []
}) })
}) })
it('populateQueue does nothing when too much errors', () => { it('populateQueue does nothing when too much errors', () => {
return testAction({ return testAction({
action: store.actions.populateQueue, action: store.actions.populateQueue,
payload: {test: 'track'}, payload: { test: 'track' },
params: { params: {
rootState: {player: {errorCount: 5, maxConsecutiveErrors: 5}}, rootState: { player: { errorCount: 5, maxConsecutiveErrors: 5 } },
state: {running: true} state: { running: true }
}, },
expectedActions: [] expectedActions: []
}) })

View File

@ -1,31 +1,31 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import {parseAPIErrors} from '@/utils' import { parseAPIErrors } from '@/utils'
describe('utils', () => { describe('utils', () => {
describe('parseAPIErrors', () => { describe('parseAPIErrors', () => {
it('handles flat structure', () => { it('handles flat structure', () => {
const input = {"old_password": ["Invalid password"]} const input = { old_password: ['Invalid password'] }
let expected = ["Invalid password"] const expected = ['Invalid password']
let output = parseAPIErrors(input) const output = parseAPIErrors(input)
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
it('handles flat structure with multiple errors per field', () => { it('handles flat structure with multiple errors per field', () => {
const input = {"old_password": ["Invalid password", "Too short"]} const input = { old_password: ['Invalid password', 'Too short'] }
let expected = ["Invalid password", "Too short"] const expected = ['Invalid password', 'Too short']
let output = parseAPIErrors(input) const output = parseAPIErrors(input)
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
it('translate field name', () => { it('translate field name', () => {
const input = {"old_password": ["This field is required"]} const input = { old_password: ['This field is required'] }
let expected = ["Old Password: This field is required"] const expected = ['Old Password: This field is required']
let output = parseAPIErrors(input) const output = parseAPIErrors(input)
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
it('handle nested fields', () => { it('handle nested fields', () => {
const input = {"summary": {"text": ["Ensure this field has no more than 5000 characters."]}} const input = { summary: { text: ['Ensure this field has no more than 5000 characters.'] } }
let expected = ["Summary - Text: Ensure this field has no more than 5000 characters."] const expected = ['Summary - Text: Ensure this field has no more than 5000 characters.']
let output = parseAPIErrors(input) const output = parseAPIErrors(input)
expect(output).to.deep.equal(expected) expect(output).to.deep.equal(expected)
}) })
}) })

View File

@ -1,47 +0,0 @@
import { describe, beforeEach, afterEach, it, expect } from 'vitest'
import { shallowMount, createLocalVue } from '@vue/test-utils'
import AlbumDetail from '@/views/admin/library/AlbumDetail.vue'
import GetTextPlugin from 'vue-gettext'
import HumanDate from '@/components/common/HumanDate.vue'
import DangerousButton from '@/components/common/DangerousButton.vue'
describe('views/admin/library', () => {
let wrapper
describe('Album details', () => {
it('displays default cover', async () => {
const album = { cover: null, artist: { id: null }, title: "dummy" }
const localVue = createLocalVue()
localVue.directive('title', (() => null))
localVue.directive('dropdown', (() => null))
localVue.use(GetTextPlugin, { translations: {} })
// overrides axios calls
//sandbox.stub(AlbumDetail.methods, "fetchData").callsFake(() => null)
//sandbox.stub(AlbumDetail.methods, "fetchStats").callsFake(() => null)
wrapper = shallowMount(AlbumDetail, {
localVue,
data() {
return {
isLoading: false,
isLoadingStats: false,
object: album,
stats: [],
}
},
mocks: {
$store: {
state: { auth: { profile: null }, ui: { lastDate: null } }
}
},
stubs: {
'human-date': HumanDate,
'dangerous-button': DangerousButton
},
computed: { labels: () => { return { statsWarning: null } } }
})
//expect(wrapper.find('img').attributes('src')).to.include("default-cover")
})
})
})

View File

@ -1,14 +1,13 @@
// helper for testing action with expected mutations // helper for testing action with expected mutations
import Vue from 'vue' import Vue from 'vue'
import {expect} from 'chai' import { expect } from 'chai'
export const render = (Component, propsData) => { export const render = (Component, propsData) => {
const Constructor = Vue.extend(Component) const Constructor = Vue.extend(Component)
return new Constructor({ propsData: propsData }).$mount() return new Constructor({ propsData: propsData }).$mount()
} }
export const testAction = ({action, payload, params, expectedMutations, expectedActions}, done) => { export const testAction = ({ action, payload, params, expectedMutations, expectedActions }, done) => {
let mutationsCount = 0 let mutationsCount = 0
let actionsCount = 0 let actionsCount = 0
@ -18,9 +17,6 @@ export const testAction = ({action, payload, params, expectedMutations, expected
if (!expectedActions) { if (!expectedActions) {
expectedActions = [] expectedActions = []
} }
const isOver = () => {
return mutationsCount >= expectedMutations.length && actionsCount >= expectedActions.length
}
// mock commit // mock commit
const commit = (type, payload) => { const commit = (type, payload) => {
const mutation = expectedMutations[mutationsCount] const mutation = expectedMutations[mutationsCount]
@ -31,9 +27,6 @@ export const testAction = ({action, payload, params, expectedMutations, expected
} }
mutationsCount++ mutationsCount++
if (isOver()) {
return
}
} }
// mock dispatch // mock dispatch
const dispatch = (type, payload, options) => { const dispatch = (type, payload, options) => {
@ -49,12 +42,9 @@ export const testAction = ({action, payload, params, expectedMutations, expected
expect(options).to.deep.equal(a.options) expect(options).to.deep.equal(a.options)
} }
actionsCount++ actionsCount++
if (isOver()) {
return
}
} }
let end = function () { const end = function () {
// check if no mutations should have been dispatched // check if no mutations should have been dispatched
if (expectedMutations.length === 0) { if (expectedMutations.length === 0) {
expect(mutationsCount).to.equal(0) expect(mutationsCount).to.equal(0)
@ -62,12 +52,9 @@ export const testAction = ({action, payload, params, expectedMutations, expected
if (expectedActions.length === 0) { if (expectedActions.length === 0) {
expect(actionsCount).to.equal(0) expect(actionsCount).to.equal(0)
} }
if (isOver()) {
return
}
} }
// call the action with mocked store and arguments // call the action with mocked store and arguments
let promise = action({ commit, dispatch, ...params }, payload) const promise = action({ commit, dispatch, ...params }, payload)
if (promise) { if (promise) {
promise.then(end) promise.then(end)
return promise return promise