funkwhale/front/tests/unit/specs/store/radios.spec.js

84 lines
2.3 KiB
JavaScript

import { describe, it, expect } from 'vitest'
import store from '@/store/radios'
import { testAction } from '../../utils'
describe('store/radios', () => {
describe('mutations', () => {
it('current', () => {
const state = {}
store.mutations.current(state, 1)
expect(state.current).to.equal(1)
})
it('running', () => {
const state = {}
store.mutations.running(state, false)
expect(state.running).to.equal(false)
})
})
describe('actions', () => {
it('start', () => {
testAction({
action: store.actions.start,
payload: { type: 'favorites', objectId: 0, customRadioId: null },
expectedMutations: [
{
type: 'current',
payload: {
type: 'favorites',
objectId: 0,
customRadioId: null,
session: 2
}
},
{ type: 'running', payload: true }
],
expectedActions: [
{ type: 'populateQueue', payload: true }
]
})
})
it('stop', () => {
return testAction({
action: store.actions.stop,
params: { state: {} },
expectedMutations: [
{ type: 'current', payload: null },
{ type: 'running', payload: false }
]
})
})
it('populateQueue', () => {
return testAction({
action: store.actions.populateQueue,
params: {
state: { running: true, current: { session: 1 } },
rootState: { player: { errorCount: 0, maxConsecutiveErrors: 5 } }
},
expectedActions: [
{ 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 } },
expectedActions: []
})
})
it('populateQueue does nothing when too much errors', () => {
return testAction({
action: store.actions.populateQueue,
payload: { test: 'track' },
params: {
rootState: { player: { errorCount: 5, maxConsecutiveErrors: 5 } },
state: { running: true }
},
expectedActions: []
})
})
})
})