1
0

fix: sync-now feedback and polling, preserve stored subsonic password, fix placeholder

This commit is contained in:
2026-08-30 00:16:41 +02:00
parent 6b85f11871
commit 3efde1a828
2 changed files with 61 additions and 10 deletions

View File

@@ -147,4 +147,36 @@ describe('SettingsPage', () => {
await userEvent.click(await screen.findByRole('button', { name: /log out/i }))
expect(api.logout).toHaveBeenCalled()
})
it('sync now surfaces the no-config error', async () => {
const err = new (await import('../src/api.js')).ApiError(409, 'no_subsonic_config')
vi.mocked(api.startSync).mockRejectedValue(err)
renderSettings()
await userEvent.click(await screen.findByRole('button', { name: /sync now/i }))
await waitFor(() => expect(screen.getByText(/no_subsonic_config/)).toBeTruthy())
})
it('keeps the stored subsonic password when saving with a blank password field', async () => {
vi.mocked(api.putSettings).mockResolvedValue(emptyView as never)
renderSettings()
await userEvent.type(await screen.findByLabelText(/subsonic url/i), 'http://navidrome.local')
await userEvent.type(screen.getByLabelText(/subsonic username/i), 'sam')
// password left blank
await userEvent.click(screen.getByRole('button', { name: /save subsonic/i }))
await waitFor(() =>
expect(api.putSettings).toHaveBeenCalledWith({ subsonicUrl: 'http://navidrome.local', subsonicUsername: 'sam' })
)
})
it('polls sync status until it finishes after sync now', async () => {
vi.mocked(api.startSync).mockResolvedValue({ ...idleSync, status: 'running' } as never)
vi.mocked(api.syncStatus)
.mockResolvedValueOnce({ ...idleSync } as never) // mount poll: idle, chain ends
.mockResolvedValueOnce({ ...idleSync, status: 'running' } as never) // first poll after sync now
.mockResolvedValue({ ...idleSync, status: 'done', albums: 42, lastSyncedAt: '2026-08-29T12:00:00.000Z' } as never)
renderSettings()
await userEvent.click(await screen.findByRole('button', { name: /sync now/i }))
await waitFor(() => expect(screen.getByText(/42 albums synced/i)).toBeTruthy(), { timeout: 3000 })
expect(vi.mocked(api.syncStatus).mock.calls.length).toBeGreaterThanOrEqual(3)
})
})