Reintroduce unit testing for the frontend
This commit is contained in:
parent
7dff941979
commit
8127bc10ba
|
@ -10,7 +10,7 @@
|
|||
"build:deployment": "vite build --base /front/",
|
||||
"serve": "vite preview",
|
||||
"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",
|
||||
"i18n-compile": "scripts/i18n-compile.sh",
|
||||
"i18n-extract": "scripts/i18n-extract.sh",
|
||||
|
|
|
@ -3,8 +3,6 @@ import { mount } from '@vue/test-utils'
|
|||
|
||||
import Username from '@/components/common/Username.vue'
|
||||
|
||||
import { render } from '../../utils'
|
||||
|
||||
describe('Username', () => {
|
||||
it('displays username', () => {
|
||||
const wrapper = mount(Username, {
|
||||
|
@ -12,7 +10,6 @@ describe('Username', () => {
|
|||
username: 'Hello'
|
||||
}
|
||||
})
|
||||
const vm = render(Username, {username: 'Hello'})
|
||||
expect(wrapper.text()).to.equal('Hello')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,7 +18,7 @@ describe('PasswordInput', () => {
|
|||
const inputElement = wrapper.find('input')
|
||||
expect(inputElement.element.value).to.equal(password)
|
||||
})
|
||||
//it('copy password function called', () => {
|
||||
// it('copy password function called', () => {
|
||||
// const spy = sandbox.spy()
|
||||
// wrapper.setMethods({
|
||||
// copyPassword: spy
|
||||
|
@ -27,5 +27,5 @@ describe('PasswordInput', () => {
|
|||
// const copyButton = wrapper.findAll('button').at(1)
|
||||
// copyButton.trigger('click')
|
||||
// sandbox.assert.calledOnce(spy)
|
||||
//})
|
||||
// })
|
||||
})
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import moment from 'moment'
|
||||
import {truncate, ago, capitalize, year} from '@/filters'
|
||||
import { truncate, ago, capitalize, year } from '@/filters'
|
||||
|
||||
describe('filters', () => {
|
||||
describe('truncate', () => {
|
||||
it('leave strings as it if correct size', () => {
|
||||
const input = 'Hello world'
|
||||
let output = truncate(input, 100)
|
||||
const output = truncate(input, 100)
|
||||
expect(output).to.equal(input)
|
||||
})
|
||||
it('returns shorter string with character', () => {
|
||||
const input = 'Hello world'
|
||||
let output = truncate(input, 5)
|
||||
const output = truncate(input, 5)
|
||||
expect(output).to.equal('Hello…')
|
||||
})
|
||||
it('custom ellipsis', () => {
|
||||
const input = 'Hello world'
|
||||
let output = truncate(input, 5, ' pouet')
|
||||
const output = truncate(input, 5, ' pouet')
|
||||
expect(output).to.equal('Hello pouet')
|
||||
})
|
||||
})
|
||||
describe('ago', () => {
|
||||
it('works', () => {
|
||||
const input = new Date()
|
||||
let output = ago(input)
|
||||
let expected = moment(input).calendar(input, {
|
||||
const output = ago(input)
|
||||
const expected = moment(input).calendar(input, {
|
||||
sameDay: 'LT',
|
||||
nextDay: 'L',
|
||||
nextWeek: 'L',
|
||||
|
@ -38,14 +38,14 @@ describe('filters', () => {
|
|||
describe('year', () => {
|
||||
it('works', () => {
|
||||
const input = '2017-07-13'
|
||||
let output = year(input)
|
||||
const output = year(input)
|
||||
expect(output).to.equal(2017)
|
||||
})
|
||||
})
|
||||
describe('capitalize', () => {
|
||||
it('works', () => {
|
||||
const input = 'hello world'
|
||||
let output = capitalize(input)
|
||||
const output = capitalize(input)
|
||||
expect(output).to.equal('Hello world')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,65 +1,65 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
|
||||
import {normalizeQuery, parseTokens, compileTokens} from '@/search'
|
||||
import { normalizeQuery, parseTokens, compileTokens } from '@/search'
|
||||
|
||||
describe('search', () => {
|
||||
it('normalizeQuery returns correct tokens', () => {
|
||||
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'])
|
||||
})
|
||||
it('parseTokens can extract fields and values from tokens', () => {
|
||||
const input = ['unhandled', 'key:value', 'status:pending', 'title:"some title"', 'anotherunhandled']
|
||||
let output = parseTokens(input)
|
||||
let expected = [
|
||||
const output = parseTokens(input)
|
||||
const expected = [
|
||||
{
|
||||
'field': null,
|
||||
'value': 'unhandled'
|
||||
field: null,
|
||||
value: 'unhandled'
|
||||
},
|
||||
{
|
||||
'field': 'key',
|
||||
'value': 'value'
|
||||
field: 'key',
|
||||
value: 'value'
|
||||
},
|
||||
{
|
||||
'field': 'status',
|
||||
'value': 'pending',
|
||||
field: 'status',
|
||||
value: 'pending'
|
||||
},
|
||||
{
|
||||
'field': 'title',
|
||||
'value': 'some title'
|
||||
field: 'title',
|
||||
value: 'some title'
|
||||
},
|
||||
{
|
||||
'field': null,
|
||||
'value': 'anotherunhandled'
|
||||
field: null,
|
||||
value: 'anotherunhandled'
|
||||
}
|
||||
]
|
||||
expect(output).to.deep.equal(expected)
|
||||
})
|
||||
it('compileTokens returns proper query string', () => {
|
||||
let input = [
|
||||
const input = [
|
||||
{
|
||||
'field': null,
|
||||
'value': 'unhandled'
|
||||
field: null,
|
||||
value: 'unhandled'
|
||||
},
|
||||
{
|
||||
'field': 'key',
|
||||
'value': 'value'
|
||||
field: 'key',
|
||||
value: 'value'
|
||||
},
|
||||
{
|
||||
'field': 'status',
|
||||
'value': 'pending',
|
||||
field: 'status',
|
||||
value: 'pending'
|
||||
},
|
||||
{
|
||||
'field': 'title',
|
||||
'value': 'some title'
|
||||
field: 'title',
|
||||
value: 'some title'
|
||||
},
|
||||
{
|
||||
'field': null,
|
||||
'value': 'anotherunhandled'
|
||||
field: null,
|
||||
value: '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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -4,7 +4,6 @@ import store from '@/store/auth'
|
|||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/auth', () => {
|
||||
|
||||
describe('mutations', () => {
|
||||
it('profile', () => {
|
||||
const state = {}
|
||||
|
@ -42,47 +41,47 @@ describe('store/auth', () => {
|
|||
})
|
||||
it('token real', () => {
|
||||
const state = {}
|
||||
let token = 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTUxNTUzMzQyOSwiZXhwIjoxNTE1NTM3MDI5LCJpYXQiOjE1MTU1MzM0MjksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.'
|
||||
const token = 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2p3dC1pZHAuZXhhbXBsZS5jb20iLCJzdWIiOiJtYWlsdG86bWlrZUBleGFtcGxlLmNvbSIsIm5iZiI6MTUxNTUzMzQyOSwiZXhwIjoxNTE1NTM3MDI5LCJpYXQiOjE1MTU1MzM0MjksImp0aSI6ImlkMTIzNDU2IiwidHlwIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9yZWdpc3RlciJ9.'
|
||||
store.mutations.token(state, token)
|
||||
expect(state.token).to.equal(token)
|
||||
})
|
||||
it('permissions', () => {
|
||||
const state = { availablePermissions: {} }
|
||||
store.mutations.permission(state, {key: 'admin', status: true})
|
||||
expect(state.availablePermissions).to.deep.equal({admin: true})
|
||||
store.mutations.permission(state, { key: 'admin', status: true })
|
||||
expect(state.availablePermissions).to.deep.equal({ admin: true })
|
||||
})
|
||||
})
|
||||
describe('getters', () => {
|
||||
it('header', () => {
|
||||
const state = { oauth: {accessToken: 'helloworld' }}
|
||||
expect(store.getters['header'](state)).to.equal('Bearer helloworld')
|
||||
const state = { oauth: { accessToken: 'helloworld' } }
|
||||
expect(store.getters.header(state)).to.equal('Bearer helloworld')
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
it('logout', () => {
|
||||
testAction({
|
||||
action: store.actions.logout,
|
||||
params: {state: {}},
|
||||
params: { state: {} },
|
||||
expectedMutations: [
|
||||
{ type: 'auth/reset', payload: null, options: {root: true} },
|
||||
{ type: 'favorites/reset', payload: null, options: {root: true} },
|
||||
{ type: 'player/reset', payload: null, options: {root: true} },
|
||||
{ type: 'playlists/reset', payload: null, options: {root: true} },
|
||||
{ type: 'queue/reset', payload: null, options: {root: true} },
|
||||
{ type: 'radios/reset', payload: null, options: {root: true} }
|
||||
{ type: 'auth/reset', payload: null, options: { root: true } },
|
||||
{ type: 'favorites/reset', payload: null, options: { root: true } },
|
||||
{ type: 'player/reset', payload: null, options: { root: true } },
|
||||
{ type: 'playlists/reset', payload: null, options: { root: true } },
|
||||
{ type: 'queue/reset', payload: null, options: { root: true } },
|
||||
{ type: 'radios/reset', payload: null, options: { root: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('check jwt null', () => {
|
||||
testAction({
|
||||
action: store.actions.check,
|
||||
params: {state: {}},
|
||||
params: { state: {} },
|
||||
expectedMutations: [
|
||||
{ type: 'authenticated', payload: false },
|
||||
{ type: 'authenticated', payload: true },
|
||||
{ type: 'authenticated', payload: true }
|
||||
],
|
||||
expectedActions: [
|
||||
{ type: 'fetchProfile' },
|
||||
{ type: 'fetchProfile' }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
@ -99,17 +98,17 @@ describe('store/auth', () => {
|
|||
{ type: 'authenticated', payload: true },
|
||||
{ type: 'profile', payload: profile },
|
||||
{ type: 'username', payload: profile.username },
|
||||
{ type: 'permission', payload: {key: 'admin', status: true} }
|
||||
{ type: 'permission', payload: { key: 'admin', status: true } }
|
||||
],
|
||||
expectedActions: [
|
||||
{ type: 'ui/initSettings', payload: { root: true } },
|
||||
{ type: 'updateProfile', payload: profile },
|
||||
{ type: 'ui/fetchUnreadNotifications', payload: null },
|
||||
{ type: 'favorites/fetch', payload: null, options: {root: true} },
|
||||
{ type: 'channels/fetchSubscriptions', payload: null, options: {root: true} },
|
||||
{ type: 'libraries/fetchFollows', payload: null, options: {root: true} },
|
||||
{ type: 'moderation/fetchContentFilters', payload: null, options: {root: true} },
|
||||
{ type: 'playlists/fetchOwn', payload: null, options: {root: true} }
|
||||
{ type: 'favorites/fetch', payload: null, options: { root: true } },
|
||||
{ type: 'channels/fetchSubscriptions', payload: null, options: { root: true } },
|
||||
{ type: 'libraries/fetchFollows', payload: null, options: { root: true } },
|
||||
{ type: 'moderation/fetchContentFilters', payload: null, options: { root: true } },
|
||||
{ type: 'playlists/fetchOwn', payload: null, options: { root: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
|
|
@ -8,13 +8,13 @@ describe('store/favorites', () => {
|
|||
describe('mutations', () => {
|
||||
it('track true', () => {
|
||||
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.count).to.deep.equal(1)
|
||||
})
|
||||
it('track false', () => {
|
||||
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.count).to.deep.equal(0)
|
||||
})
|
||||
|
@ -22,11 +22,11 @@ describe('store/favorites', () => {
|
|||
describe('getters', () => {
|
||||
it('isFavorite true', () => {
|
||||
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', () => {
|
||||
const state = { tracks: [] }
|
||||
expect(store.getters['isFavorite'](state)(1)).to.equal(false)
|
||||
expect(store.getters.isFavorite(state)(1)).to.equal(false)
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
|
@ -34,9 +34,9 @@ describe('store/favorites', () => {
|
|||
testAction({
|
||||
action: store.actions.toggle,
|
||||
payload: 1,
|
||||
params: {getters: {isFavorite: () => false}},
|
||||
params: { getters: { isFavorite: () => false } },
|
||||
expectedActions: [
|
||||
{ type: 'set', payload: {id: 1, value: true} }
|
||||
{ type: 'set', payload: { id: 1, value: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
@ -44,9 +44,9 @@ describe('store/favorites', () => {
|
|||
testAction({
|
||||
action: store.actions.toggle,
|
||||
payload: 1,
|
||||
params: {getters: {isFavorite: () => true}},
|
||||
params: { getters: { isFavorite: () => true } },
|
||||
expectedActions: [
|
||||
{ type: 'set', payload: {id: 1, value: false} }
|
||||
{ type: 'set', payload: { id: 1, value: false } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
import { describe, beforeEach, afterEach, it, expect } from 'vitest'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import store from '@/store/instance'
|
||||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/instance', () => {
|
||||
|
||||
describe('mutations', () => {
|
||||
it('settings', () => {
|
||||
const state = {settings: {users: {upload_quota: {value: 1}}}}
|
||||
let settings = {users: {registration_enabled: {value: true}}}
|
||||
const state = { settings: { users: { upload_quota: { value: 1 } } } }
|
||||
const settings = { users: { registration_enabled: { value: true } } }
|
||||
store.mutations.settings(state, settings)
|
||||
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', () => {
|
||||
const state = {instanceUrl: null, knownInstances: ['http://test2/', 'http://test/']}
|
||||
const state = { instanceUrl: null, knownInstances: ['http://test2/', 'http://test/'] }
|
||||
store.mutations.instanceUrl(state, 'http://test')
|
||||
expect(state).to.deep.equal({
|
||||
instanceUrl: 'http://test/', // trailing slash added
|
||||
|
|
|
@ -90,15 +90,15 @@ describe('store/player', () => {
|
|||
describe('getters', () => {
|
||||
it('durationFormatted', () => {
|
||||
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', () => {
|
||||
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', () => {
|
||||
const state = { currentTime: 4, duration: 10 }
|
||||
expect(store.getters['progress'](state)).to.equal(40)
|
||||
expect(store.getters.progress(state)).to.equal(40)
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
|
@ -106,7 +106,7 @@ describe('store/player', () => {
|
|||
testAction({
|
||||
action: store.actions.incrementVolume,
|
||||
payload: 0.2,
|
||||
params: {state: {volume: 0.7}},
|
||||
params: { state: { volume: 0.7 } },
|
||||
expectedMutations: [
|
||||
{ type: 'volume', payload: 0.7 + 0.2 }
|
||||
]
|
||||
|
@ -115,7 +115,7 @@ describe('store/player', () => {
|
|||
it('toggle playback false', () => {
|
||||
testAction({
|
||||
action: store.actions.togglePlayback,
|
||||
params: {state: {playing: false}},
|
||||
params: { state: { playing: false } },
|
||||
expectedMutations: [
|
||||
{ type: 'playing', payload: true }
|
||||
]
|
||||
|
@ -124,7 +124,7 @@ describe('store/player', () => {
|
|||
it('toggle playback true', () => {
|
||||
testAction({
|
||||
action: store.actions.togglePlayback,
|
||||
params: {state: {playing: true}},
|
||||
params: { state: { playing: true } },
|
||||
expectedMutations: [
|
||||
{ type: 'playing', payload: false }
|
||||
]
|
||||
|
@ -133,7 +133,7 @@ describe('store/player', () => {
|
|||
it('resume playback', () => {
|
||||
testAction({
|
||||
action: store.actions.resumePlayback,
|
||||
params: {state: {}},
|
||||
params: { state: {} },
|
||||
expectedMutations: [
|
||||
{ type: 'playing', payload: true }
|
||||
]
|
||||
|
@ -150,35 +150,35 @@ describe('store/player', () => {
|
|||
it('trackEnded', () => {
|
||||
testAction({
|
||||
action: store.actions.trackEnded,
|
||||
payload: {test: 'track'},
|
||||
params: {rootState: {queue: {currentIndex: 0, tracks: [1, 2]}}},
|
||||
payload: { test: 'track' },
|
||||
params: { rootState: { queue: { currentIndex: 0, tracks: [1, 2] } } },
|
||||
expectedActions: [
|
||||
{ type: 'queue/next', payload: null, options: {root: true} }
|
||||
{ type: 'queue/next', payload: null, options: { root: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('trackEnded calls populateQueue if last', () => {
|
||||
testAction({
|
||||
action: store.actions.trackEnded,
|
||||
payload: {test: 'track'},
|
||||
params: {rootState: {queue: {currentIndex: 1, tracks: [1, 2]}}},
|
||||
payload: { test: 'track' },
|
||||
params: { rootState: { queue: { currentIndex: 1, tracks: [1, 2] } } },
|
||||
expectedActions: [
|
||||
{ type: 'radios/populateQueue', payload: null, options: {root: true} },
|
||||
{ type: 'queue/next', payload: null, options: {root: true} }
|
||||
{ type: 'radios/populateQueue', payload: null, options: { root: true } },
|
||||
{ type: 'queue/next', payload: null, options: { root: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('trackErrored', () => {
|
||||
testAction({
|
||||
action: store.actions.trackErrored,
|
||||
payload: {test: 'track'},
|
||||
params: {state: {errorCount: 0, maxConsecutiveErrors: 5}},
|
||||
payload: { test: 'track' },
|
||||
params: { state: { errorCount: 0, maxConsecutiveErrors: 5 } },
|
||||
expectedMutations: [
|
||||
{ type: 'errored', payload: true },
|
||||
{ type: 'incrementErrorCount' }
|
||||
],
|
||||
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', () => {
|
||||
testAction({
|
||||
action: store.actions.mute,
|
||||
params: {state: { volume: 0.7, tempVolume: 0}},
|
||||
params: { state: { volume: 0.7, tempVolume: 0 } },
|
||||
expectedMutations: [
|
||||
{ type: 'tempVolume', payload: 0.7 },
|
||||
{ type: 'volume', payload: 0 },
|
||||
{ type: 'volume', payload: 0 }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('unmute', () => {
|
||||
testAction({
|
||||
action: store.actions.unmute,
|
||||
params: {state: { volume: 0, tempVolume: 0.8}},
|
||||
params: { state: { volume: 0, tempVolume: 0.8 } },
|
||||
expectedMutations: [
|
||||
{ type: 'volume', payload: 0.8 },
|
||||
{ type: 'volume', payload: 0.8 }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import { describe, beforeEach, afterEach, it, expect } from 'vitest'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import store from '@/store/playlists'
|
||||
|
||||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/playlists', () => {
|
||||
|
||||
describe('mutations', () => {
|
||||
it('set playlists', () => {
|
||||
const state = { playlists: [] }
|
||||
store.mutations.playlists(state, [{id: 1, name: 'test'}])
|
||||
expect(state.playlists).to.deep.equal([{id: 1, name: 'test'}])
|
||||
store.mutations.playlists(state, [{ id: 1, name: 'test' }])
|
||||
expect(state.playlists).to.deep.equal([{ id: 1, name: 'test' }])
|
||||
})
|
||||
})
|
||||
describe('actions', () => {
|
||||
|
@ -17,7 +16,7 @@ describe('store/playlists', () => {
|
|||
testAction({
|
||||
action: store.actions.fetchOwn,
|
||||
payload: null,
|
||||
params: {state: { playlists: [] }, rootState: {auth: {profile: {}}}},
|
||||
params: { state: { playlists: [] }, rootState: { auth: { profile: {} } } },
|
||||
expectedMutations: []
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import { it, describe, expect } from 'vitest'
|
||||
|
||||
import _ from 'lodash'
|
||||
|
||||
import store from '@/store/queue'
|
||||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/queue', () => {
|
||||
|
||||
describe('mutations', () => {
|
||||
it('currentIndex', () => {
|
||||
const state = {}
|
||||
|
@ -24,97 +21,97 @@ describe('store/queue', () => {
|
|||
expect(state.tracks).to.deep.equal([1, 2])
|
||||
})
|
||||
it('splice', () => {
|
||||
const state = {tracks: [1, 2, 3]}
|
||||
store.mutations.splice(state, {start: 1, size: 2})
|
||||
const state = { tracks: [1, 2, 3] }
|
||||
store.mutations.splice(state, { start: 1, size: 2 })
|
||||
expect(state.tracks).to.deep.equal([1])
|
||||
})
|
||||
it('insert', () => {
|
||||
const state = {tracks: [1, 3]}
|
||||
store.mutations.insert(state, {track: 2, index: 1})
|
||||
const state = { tracks: [1, 3] }
|
||||
store.mutations.insert(state, { track: 2, index: 1 })
|
||||
expect(state.tracks).to.deep.equal([1, 2, 3])
|
||||
})
|
||||
it('reorder before', () => {
|
||||
const state = {currentIndex: 3}
|
||||
store.mutations.reorder(state, {oldIndex: 2, newIndex: 1})
|
||||
const state = { currentIndex: 3 }
|
||||
store.mutations.reorder(state, { oldIndex: 2, newIndex: 1 })
|
||||
expect(state.currentIndex).to.equal(3)
|
||||
})
|
||||
it('reorder from after to before', () => {
|
||||
const state = {currentIndex: 3}
|
||||
store.mutations.reorder(state, {oldIndex: 4, newIndex: 1})
|
||||
const state = { currentIndex: 3 }
|
||||
store.mutations.reorder(state, { oldIndex: 4, newIndex: 1 })
|
||||
expect(state.currentIndex).to.equal(4)
|
||||
})
|
||||
it('reorder after', () => {
|
||||
const state = {currentIndex: 3}
|
||||
store.mutations.reorder(state, {oldIndex: 4, newIndex: 5})
|
||||
const state = { currentIndex: 3 }
|
||||
store.mutations.reorder(state, { oldIndex: 4, newIndex: 5 })
|
||||
expect(state.currentIndex).to.equal(3)
|
||||
})
|
||||
it('reorder before to after', () => {
|
||||
const state = {currentIndex: 3}
|
||||
store.mutations.reorder(state, {oldIndex: 1, newIndex: 5})
|
||||
const state = { currentIndex: 3 }
|
||||
store.mutations.reorder(state, { oldIndex: 1, newIndex: 5 })
|
||||
expect(state.currentIndex).to.equal(2)
|
||||
})
|
||||
it('reorder current', () => {
|
||||
const state = {currentIndex: 3}
|
||||
store.mutations.reorder(state, {oldIndex: 3, newIndex: 1})
|
||||
const state = { currentIndex: 3 }
|
||||
store.mutations.reorder(state, { oldIndex: 3, newIndex: 1 })
|
||||
expect(state.currentIndex).to.equal(1)
|
||||
})
|
||||
})
|
||||
describe('getters', () => {
|
||||
it('currentTrack', () => {
|
||||
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', () => {
|
||||
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', () => {
|
||||
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', () => {
|
||||
it('append at end', () => {
|
||||
testAction({
|
||||
action: store.actions.append,
|
||||
payload: {track: 4},
|
||||
params: {state: {tracks: [1, 2, 3]}},
|
||||
payload: { track: 4 },
|
||||
params: { state: { tracks: [1, 2, 3] } },
|
||||
expectedMutations: [
|
||||
{ type: 'insert', payload: {track: 4, index: 3} }
|
||||
{ type: 'insert', payload: { track: 4, index: 3 } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('append at index', () => {
|
||||
testAction({
|
||||
action: store.actions.append,
|
||||
payload: {track: 2, index: 1},
|
||||
params: {state: {tracks: [1, 3]}},
|
||||
payload: { track: 2, index: 1 },
|
||||
params: { state: { tracks: [1, 3] } },
|
||||
expectedMutations: [
|
||||
{ type: 'insert', payload: {track: 2, index: 1} }
|
||||
{ type: 'insert', payload: { track: 2, index: 1 } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('appendMany', () => {
|
||||
const tracks = [{title: 1}, {title: 2}]
|
||||
const tracks = [{ title: 1 }, { title: 2 }]
|
||||
testAction({
|
||||
action: store.actions.appendMany,
|
||||
payload: {tracks: tracks},
|
||||
params: {state: {tracks: []}},
|
||||
payload: { tracks: tracks },
|
||||
params: { state: { tracks: [] } },
|
||||
expectedActions: [
|
||||
{ type: 'append', payload: {track: tracks[0], index: 0} },
|
||||
{ type: 'append', payload: {track: tracks[1], index: 1} },
|
||||
{ type: 'append', payload: { track: tracks[0], index: 0 } },
|
||||
{ type: 'append', payload: { track: tracks[1], index: 1 } }
|
||||
]
|
||||
})
|
||||
})
|
||||
it('appendMany at index', () => {
|
||||
const tracks = [{title: 1}, {title: 2}]
|
||||
const tracks = [{ title: 1 }, { title: 2 }]
|
||||
testAction({
|
||||
action: store.actions.appendMany,
|
||||
payload: {tracks: tracks, index: 1},
|
||||
params: {state: {tracks: [1, 2]}},
|
||||
payload: { tracks: tracks, index: 1 },
|
||||
params: { state: { tracks: [1, 2] } },
|
||||
expectedActions: [
|
||||
{ type: 'append', payload: {track: tracks[0], index: 1} },
|
||||
{ type: 'append', payload: {track: tracks[1], index: 2} },
|
||||
{ type: 'append', payload: { track: tracks[0], index: 1 } },
|
||||
{ type: 'append', payload: { track: tracks[1], index: 2 } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
@ -122,9 +119,9 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.cleanTrack,
|
||||
payload: 3,
|
||||
params: {state: {currentIndex: 2, tracks: [1, 2, 3, 4, 5]}},
|
||||
params: { state: { currentIndex: 2, tracks: [1, 2, 3, 4, 5] } },
|
||||
expectedMutations: [
|
||||
{ type: 'splice', payload: {start: 3, size: 1} }
|
||||
{ type: 'splice', payload: { start: 3, size: 1 } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
@ -132,9 +129,9 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.cleanTrack,
|
||||
payload: 1,
|
||||
params: {state: {currentIndex: 2, tracks: []}},
|
||||
params: { state: { currentIndex: 2, tracks: [] } },
|
||||
expectedMutations: [
|
||||
{ type: 'splice', payload: {start: 1, size: 1} },
|
||||
{ type: 'splice', payload: { start: 1, size: 1 } },
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
]
|
||||
})
|
||||
|
@ -143,13 +140,13 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.cleanTrack,
|
||||
payload: 2,
|
||||
params: {state: {currentIndex: 2, tracks: []}},
|
||||
params: { state: { currentIndex: 2, tracks: [] } },
|
||||
expectedMutations: [
|
||||
{ type: 'splice', payload: {start: 2, size: 1} },
|
||||
{ type: 'splice', payload: { start: 2, size: 1 } },
|
||||
{ type: 'currentIndex', payload: 2 }
|
||||
],
|
||||
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', () => {
|
||||
testAction({
|
||||
action: store.actions.previous,
|
||||
params: {state: {currentIndex: 0}},
|
||||
params: { state: { currentIndex: 0 } },
|
||||
expectedActions: [
|
||||
{ type: 'currentIndex', payload: 0 }
|
||||
]
|
||||
|
@ -179,7 +176,7 @@ describe('store/queue', () => {
|
|||
it('previous after less than 3 seconds of playback', () => {
|
||||
testAction({
|
||||
action: store.actions.previous,
|
||||
params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 1}}},
|
||||
params: { state: { currentIndex: 1 }, rootState: { player: { currentTime: 1 } } },
|
||||
expectedActions: [
|
||||
{ type: 'currentIndex', payload: 0 }
|
||||
]
|
||||
|
@ -188,7 +185,7 @@ describe('store/queue', () => {
|
|||
it('previous after more than 3 seconds of playback', () => {
|
||||
testAction({
|
||||
action: store.actions.previous,
|
||||
params: {state: {currentIndex: 1}, rootState: {player: {currentTime: 3}}},
|
||||
params: { state: { currentIndex: 1 }, rootState: { player: { currentTime: 3 } } },
|
||||
expectedActions: [
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
]
|
||||
|
@ -197,7 +194,7 @@ describe('store/queue', () => {
|
|||
it('next on last track when looping on queue', () => {
|
||||
testAction({
|
||||
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: [
|
||||
{ type: 'currentIndex', payload: 0 }
|
||||
]
|
||||
|
@ -206,7 +203,7 @@ describe('store/queue', () => {
|
|||
it('next track when last track', () => {
|
||||
testAction({
|
||||
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: [
|
||||
{ type: 'ended', payload: true }
|
||||
]
|
||||
|
@ -215,7 +212,7 @@ describe('store/queue', () => {
|
|||
it('next track when not last track', () => {
|
||||
testAction({
|
||||
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: [
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
]
|
||||
|
@ -225,10 +222,10 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.currentIndex,
|
||||
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: [
|
||||
{ type: 'ended', payload: false },
|
||||
{ type: 'player/currentTime', payload: 0, options: {root: true} },
|
||||
{ type: 'player/currentTime', payload: 0, options: { root: true } },
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
]
|
||||
})
|
||||
|
@ -237,10 +234,10 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.currentIndex,
|
||||
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: [
|
||||
{ type: 'ended', payload: false },
|
||||
{ type: 'player/currentTime', payload: 0, options: {root: true} },
|
||||
{ type: 'player/currentTime', payload: 0, options: { root: true } },
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
]
|
||||
})
|
||||
|
@ -249,14 +246,14 @@ describe('store/queue', () => {
|
|||
testAction({
|
||||
action: store.actions.currentIndex,
|
||||
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: [
|
||||
{ type: 'ended', payload: false },
|
||||
{ type: 'player/currentTime', payload: 0, options: {root: true} },
|
||||
{ type: 'player/currentTime', payload: 0, options: { root: true } },
|
||||
{ type: 'currentIndex', payload: 1 }
|
||||
],
|
||||
expectedActions: [
|
||||
{ type: 'radios/populateQueue', payload: null, options: {root: true} }
|
||||
{ type: 'radios/populateQueue', payload: null, options: { root: true } }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
@ -268,18 +265,18 @@ describe('store/queue', () => {
|
|||
{ type: 'ended', payload: true }
|
||||
],
|
||||
expectedActions: [
|
||||
{ type: 'radios/stop', payload: null, options: {root: true} },
|
||||
{ type: 'player/stop', payload: null, options: {root: true} },
|
||||
{ type: 'radios/stop', payload: null, options: { root: true } },
|
||||
{ type: 'player/stop', payload: null, options: { root: true } },
|
||||
{ type: 'currentIndex', payload: -1 }
|
||||
]
|
||||
})
|
||||
})
|
||||
//it('shuffle', () => {
|
||||
//let _shuffle = sandbox.stub(_, 'shuffle')
|
||||
//let tracks = ['a', 'b', 'c', 'd', 'e']
|
||||
//let shuffledTracks = ['a', 'b', 'e', 'd', 'c']
|
||||
//_shuffle.returns(shuffledTracks)
|
||||
//testAction({
|
||||
// it('shuffle', () => {
|
||||
// let _shuffle = sandbox.stub(_, 'shuffle')
|
||||
// let tracks = ['a', 'b', 'c', 'd', 'e']
|
||||
// let shuffledTracks = ['a', 'b', 'e', 'd', 'c']
|
||||
// _shuffle.returns(shuffledTracks)
|
||||
// testAction({
|
||||
// action: store.actions.shuffle,
|
||||
// params: {state: {currentIndex: 1, tracks: tracks}},
|
||||
// expectedMutations: [
|
||||
|
@ -289,7 +286,7 @@ describe('store/queue', () => {
|
|||
// { type: 'appendMany', payload: {tracks: shuffledTracks} },
|
||||
// { type: 'currentIndex', payload: {tracks: shuffledTracks} }
|
||||
// ]
|
||||
//})
|
||||
//})
|
||||
// })
|
||||
// })
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { describe, beforeEach, it, afterEach, expect } from 'vitest'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
|
||||
import store from '@/store/radios'
|
||||
import { testAction } from '../../utils'
|
||||
|
||||
describe('store/radios', () => {
|
||||
|
||||
describe('mutations', () => {
|
||||
it('current', () => {
|
||||
const state = {}
|
||||
|
@ -21,7 +20,7 @@ describe('store/radios', () => {
|
|||
it('start', () => {
|
||||
testAction({
|
||||
action: store.actions.start,
|
||||
payload: {type: 'favorites', objectId: 0, customRadioId: null},
|
||||
payload: { type: 'favorites', objectId: 0, customRadioId: null },
|
||||
expectedMutations: [
|
||||
{
|
||||
type: 'current',
|
||||
|
@ -42,7 +41,7 @@ describe('store/radios', () => {
|
|||
it('stop', () => {
|
||||
return testAction({
|
||||
action: store.actions.stop,
|
||||
params: {state: {}},
|
||||
params: { state: {} },
|
||||
expectedMutations: [
|
||||
{ type: 'current', payload: null },
|
||||
{ type: 'running', payload: false }
|
||||
|
@ -53,29 +52,29 @@ describe('store/radios', () => {
|
|||
return testAction({
|
||||
action: store.actions.populateQueue,
|
||||
params: {
|
||||
state: {running: true, current: {session: 1}},
|
||||
rootState: {player: {errorCount: 0, maxConsecutiveErrors: 5}}
|
||||
state: { running: true, current: { session: 1 } },
|
||||
rootState: { player: { errorCount: 0, maxConsecutiveErrors: 5 } }
|
||||
|
||||
},
|
||||
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', () => {
|
||||
testAction({
|
||||
action: store.actions.populateQueue,
|
||||
params: {state: {running: false}},
|
||||
params: { state: { running: false } },
|
||||
expectedActions: []
|
||||
})
|
||||
})
|
||||
it('populateQueue does nothing when too much errors', () => {
|
||||
return testAction({
|
||||
action: store.actions.populateQueue,
|
||||
payload: {test: 'track'},
|
||||
payload: { test: 'track' },
|
||||
params: {
|
||||
rootState: {player: {errorCount: 5, maxConsecutiveErrors: 5}},
|
||||
state: {running: true}
|
||||
rootState: { player: { errorCount: 5, maxConsecutiveErrors: 5 } },
|
||||
state: { running: true }
|
||||
},
|
||||
expectedActions: []
|
||||
})
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
|
||||
import {parseAPIErrors} from '@/utils'
|
||||
import { parseAPIErrors } from '@/utils'
|
||||
|
||||
describe('utils', () => {
|
||||
describe('parseAPIErrors', () => {
|
||||
it('handles flat structure', () => {
|
||||
const input = {"old_password": ["Invalid password"]}
|
||||
let expected = ["Invalid password"]
|
||||
let output = parseAPIErrors(input)
|
||||
const input = { old_password: ['Invalid password'] }
|
||||
const expected = ['Invalid password']
|
||||
const output = parseAPIErrors(input)
|
||||
expect(output).to.deep.equal(expected)
|
||||
})
|
||||
it('handles flat structure with multiple errors per field', () => {
|
||||
const input = {"old_password": ["Invalid password", "Too short"]}
|
||||
let expected = ["Invalid password", "Too short"]
|
||||
let output = parseAPIErrors(input)
|
||||
const input = { old_password: ['Invalid password', 'Too short'] }
|
||||
const expected = ['Invalid password', 'Too short']
|
||||
const output = parseAPIErrors(input)
|
||||
expect(output).to.deep.equal(expected)
|
||||
})
|
||||
it('translate field name', () => {
|
||||
const input = {"old_password": ["This field is required"]}
|
||||
let expected = ["Old Password: This field is required"]
|
||||
let output = parseAPIErrors(input)
|
||||
const input = { old_password: ['This field is required'] }
|
||||
const expected = ['Old Password: This field is required']
|
||||
const output = parseAPIErrors(input)
|
||||
expect(output).to.deep.equal(expected)
|
||||
})
|
||||
it('handle nested fields', () => {
|
||||
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."]
|
||||
let output = parseAPIErrors(input)
|
||||
const input = { summary: { text: ['Ensure this field has no more than 5000 characters.'] } }
|
||||
const expected = ['Summary - Text: Ensure this field has no more than 5000 characters.']
|
||||
const output = parseAPIErrors(input)
|
||||
expect(output).to.deep.equal(expected)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,14 +1,13 @@
|
|||
// helper for testing action with expected mutations
|
||||
import Vue from 'vue'
|
||||
import {expect} from 'chai'
|
||||
|
||||
import { expect } from 'chai'
|
||||
|
||||
export const render = (Component, propsData) => {
|
||||
const Constructor = Vue.extend(Component)
|
||||
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 actionsCount = 0
|
||||
|
||||
|
@ -18,9 +17,6 @@ export const testAction = ({action, payload, params, expectedMutations, expected
|
|||
if (!expectedActions) {
|
||||
expectedActions = []
|
||||
}
|
||||
const isOver = () => {
|
||||
return mutationsCount >= expectedMutations.length && actionsCount >= expectedActions.length
|
||||
}
|
||||
// mock commit
|
||||
const commit = (type, payload) => {
|
||||
const mutation = expectedMutations[mutationsCount]
|
||||
|
@ -31,9 +27,6 @@ export const testAction = ({action, payload, params, expectedMutations, expected
|
|||
}
|
||||
|
||||
mutationsCount++
|
||||
if (isOver()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// mock dispatch
|
||||
const dispatch = (type, payload, options) => {
|
||||
|
@ -49,12 +42,9 @@ export const testAction = ({action, payload, params, expectedMutations, expected
|
|||
expect(options).to.deep.equal(a.options)
|
||||
}
|
||||
actionsCount++
|
||||
if (isOver()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let end = function () {
|
||||
const end = function () {
|
||||
// check if no mutations should have been dispatched
|
||||
if (expectedMutations.length === 0) {
|
||||
expect(mutationsCount).to.equal(0)
|
||||
|
@ -62,12 +52,9 @@ export const testAction = ({action, payload, params, expectedMutations, expected
|
|||
if (expectedActions.length === 0) {
|
||||
expect(actionsCount).to.equal(0)
|
||||
}
|
||||
if (isOver()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// call the action with mocked store and arguments
|
||||
let promise = action({ commit, dispatch, ...params }, payload)
|
||||
const promise = action({ commit, dispatch, ...params }, payload)
|
||||
if (promise) {
|
||||
promise.then(end)
|
||||
return promise
|
||||
|
|
Loading…
Reference in New Issue