feat(playlists): implement event refresh

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2025-05-29 20:47:00 -04:00
parent 588b6be075
commit 5a1e9f96f7
3 changed files with 58 additions and 3 deletions

View File

@ -30,6 +30,44 @@ var _ = Describe("MediaAnnotationController", func() {
router = New(ds, nil, nil, nil, nil, nil, nil, eventBroker, nil, playTracker, nil, nil)
})
Describe("Star", func() {
It("should send refresh resource event when starring a playlist", func() {
mockPlaylistRepo := &tests.MockPlaylistRepo{
Entity: &model.Playlist{ID: "pls-1", Name: "Test Playlist"},
}
ds.(*tests.MockDataStore).MockedPlaylist = mockPlaylistRepo
r := newGetRequest("id=pls-1")
_, err := router.Star(r)
Expect(err).ToNot(HaveOccurred())
Expect(eventBroker.Events).To(HaveLen(1))
event := eventBroker.Events[0].(*events.RefreshResource)
data := event.Data(event)
Expect(data).To(ContainSubstring("playlist"))
Expect(data).To(ContainSubstring("pls-1"))
})
It("should send refresh resource event when unstarring a playlist", func() {
mockPlaylistRepo := &tests.MockPlaylistRepo{
Entity: &model.Playlist{ID: "pls-1", Name: "Test Playlist"},
}
ds.(*tests.MockDataStore).MockedPlaylist = mockPlaylistRepo
r := newGetRequest("id=pls-1")
_, err := router.Unstar(r)
Expect(err).ToNot(HaveOccurred())
Expect(eventBroker.Events).To(HaveLen(1))
event := eventBroker.Events[0].(*events.RefreshResource)
data := event.Data(event)
Expect(data).To(ContainSubstring("playlist"))
Expect(data).To(ContainSubstring("pls-1"))
})
})
Describe("Scrobble", func() {
It("submit all scrobbles with only the id", func() {
submissionTime := time.Now()

View File

@ -10,6 +10,7 @@ type MockPlaylistRepo struct {
Entity *model.Playlist
Error error
SetStarWasCalled bool
}
func (m *MockPlaylistRepo) Get(_ string) (*model.Playlist, error) {
@ -31,3 +32,18 @@ func (m *MockPlaylistRepo) Count(_ ...rest.QueryOptions) (int64, error) {
}
return 1, nil
}
func (m *MockPlaylistRepo) Exists(_ string) (bool, error) {
if m.Error != nil {
return false, m.Error
}
return m.Entity != nil, nil
}
func (m *MockPlaylistRepo) SetStar(starred bool, itemIDs ...string) error {
if m.Error != nil {
return m.Error
}
m.SetStarWasCalled = true
return nil
}

View File

@ -12,7 +12,7 @@ import QueueMusicOutlinedIcon from '@material-ui/icons/QueueMusicOutlined'
import { BiCog } from 'react-icons/bi'
import { useDrop } from 'react-dnd'
import SubMenu from './SubMenu'
import { canChangeTracks } from '../common'
import { canChangeTracks, useResourceRefresh } from '../common'
import { DraggableTypes } from '../consts'
import config from '../config'
@ -51,6 +51,7 @@ const PlaylistMenuItemLink = ({ pls, sidebarIsOpen }) => {
const PlaylistsSubMenu = ({ state, setState, sidebarIsOpen, dense }) => {
const history = useHistory()
useResourceRefresh('playlist')
const { data, loaded } = useQueryWithStore({
type: 'getList',
resource: 'playlist',