up
This commit is contained in:
@@ -1445,6 +1445,10 @@ test('редактор музыки: CRUD, native MP3, порядок, вали
|
||||
f.online.state.playlists[0]!.tracks.map((t) => t.id),
|
||||
[2, 1],
|
||||
)
|
||||
const conflict = f.online.state.error
|
||||
f.model.playlistError = 0
|
||||
await f.online.act({ action: 'playlists' })
|
||||
assert.equal(f.online.state.error, conflict, 'background refresh preserves the action error')
|
||||
f.model.playlistError = 403
|
||||
await assert.rejects(f.online.act({ action: 'playlist-create', name: 'Нет прав' }), /Нет доступа/)
|
||||
})
|
||||
|
||||
+8
-4
@@ -1096,14 +1096,18 @@ export class Online {
|
||||
return this.snapshot()
|
||||
}
|
||||
if (this.busy) throw new Error('Подождите завершения текущего действия')
|
||||
const isBackgroundRefresh = data.action === 'playlists'
|
||||
this.state.busy = true
|
||||
this.state.error = ''
|
||||
this.state.notice = ''
|
||||
if (!isBackgroundRefresh) {
|
||||
this.state.error = ''
|
||||
this.state.notice = ''
|
||||
}
|
||||
try {
|
||||
await this.perform(data)
|
||||
} catch (error) {
|
||||
this.state.error = error instanceof Error ? error.message : 'Действие не выполнено'
|
||||
throw new Error(this.state.error)
|
||||
const message = error instanceof Error ? error.message : 'Действие не выполнено'
|
||||
if (!isBackgroundRefresh || !this.state.error) this.state.error = message
|
||||
throw new Error(message)
|
||||
} finally {
|
||||
this.state.busy = false
|
||||
this.state.progress = null
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { playbackControl } from '../src/utils/playbackControl.js'
|
||||
import type { ChannelState } from '../src/types/screen.js'
|
||||
|
||||
for (const [desired, status, action, label] of [
|
||||
['stopped', 'stopped', 'play', 'Запуск'],
|
||||
['playing', 'playing', 'pause', 'Пауза'],
|
||||
['playing', 'pending', 'pause', 'Пауза'],
|
||||
['paused', 'paused', 'resume', 'Продолжить'],
|
||||
['playing', 'error', 'play', 'Запуск'],
|
||||
['playing', 'ended', 'play', 'Запуск'],
|
||||
] satisfies [ChannelState['desired'], ChannelState['status'], string, string][]) {
|
||||
test(`кнопка проигрывателя ${desired}/${status}: ${action}`, () => {
|
||||
assert.deepEqual(playbackControl({ desired, status }), { action, label })
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user