From 34a24b2e445c5fd07c94d8ede199675e03fe0bac Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Wed, 18 Feb 2026 14:45:34 -0600 Subject: [PATCH] Added isLoading: false to fetchChannelIds and fix auth and channels tests. --- frontend/src/store/__tests__/auth.test.jsx | 9 ++++++-- .../src/store/__tests__/channels.test.jsx | 22 +++++++------------ frontend/src/store/channels.jsx | 1 + 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/frontend/src/store/__tests__/auth.test.jsx b/frontend/src/store/__tests__/auth.test.jsx index 6ec23873..76a4d468 100644 --- a/frontend/src/store/__tests__/auth.test.jsx +++ b/frontend/src/store/__tests__/auth.test.jsx @@ -371,10 +371,12 @@ describe('useAuthStore', () => { // Mock getState for each store useSettingsStore.getState = () => ({ fetchSettings }); + const fetchChannelIds = vi.fn().mockResolvedValue(); useChannelsStore.getState = () => ({ fetchChannels, fetchChannelGroups, fetchChannelProfiles, + fetchChannelIds, }); usePlaylistsStore.getState = () => ({ fetchPlaylists }); useEPGsStore.getState = () => ({ fetchEPGs, fetchEPGData }); @@ -401,7 +403,7 @@ describe('useAuthStore', () => { expect(result.current.user).toEqual(mockUser); expect(result.current.isAuthenticated).toBe(true); expect(fetchSettings).toHaveBeenCalled(); - expect(fetchChannels).toHaveBeenCalled(); + expect(fetchChannelIds).toHaveBeenCalled(); expect(fetchUsers).toHaveBeenCalled(); }); @@ -458,6 +460,7 @@ describe('useAuthStore', () => { fetchChannels, fetchChannelGroups: vi.fn().mockResolvedValue(), fetchChannelProfiles: vi.fn().mockResolvedValue(), + fetchChannelIds: vi.fn().mockResolvedValue(), })); const { result } = renderHook(() => useAuthStore()); @@ -645,10 +648,12 @@ describe('useAuthStore', () => { }; const fetchChannels = vi.fn().mockResolvedValue(); + const fetchChannelIdsSpy = vi.fn().mockResolvedValue(); useChannelsStore.getState = () => ({ fetchChannels, fetchChannelGroups: vi.fn().mockResolvedValue(), fetchChannelProfiles: vi.fn().mockResolvedValue(), + fetchChannelIds: fetchChannelIdsSpy, }); API.me.mockResolvedValue(mockUser); @@ -666,7 +671,7 @@ describe('useAuthStore', () => { // The background fetchChannels is called synchronously without await // so we just need to verify it was called - expect(fetchChannels).toHaveBeenCalled(); + expect(fetchChannelIdsSpy).toHaveBeenCalled(); }); }); }); diff --git a/frontend/src/store/__tests__/channels.test.jsx b/frontend/src/store/__tests__/channels.test.jsx index f992794b..d86eca29 100644 --- a/frontend/src/store/__tests__/channels.test.jsx +++ b/frontend/src/store/__tests__/channels.test.jsx @@ -32,11 +32,8 @@ describe('useChannelsStore', () => { describe('fetchChannelIds', () => { it('should fetch and store channels successfully', async () => { - const mockChannels = [ - { id: 1, uuid: 'uuid-1', name: 'Channel 1' }, - { id: 2, uuid: 'uuid-2', name: 'Channel 2' }, - ]; - api.getChannels.mockResolvedValue(mockChannels); + const mockChannelIds = [1, 2]; + api.getAllChannelIds.mockResolvedValue(mockChannelIds); const { result } = renderHook(() => useChannelsStore()); @@ -45,24 +42,21 @@ describe('useChannelsStore', () => { }); expect(api.getAllChannelIds).toHaveBeenCalledOnce(); - expect(result.current.channels).toEqual({ - 1: mockChannels[0].id, - 2: mockChannels[1].id, - }); - expect(result.current.channelsByUUID).toEqual({ - 'uuid-1': 1, - 'uuid-2': 2, - }); + expect(result.current.channelIds).toEqual(mockChannelIds); expect(result.current.isLoading).toBe(false); expect(result.current.error).toBeNull(); }); it('should handle fetch error', async () => { const errorMessage = 'Network error'; - api.getChannels.mockRejectedValue(new Error(errorMessage)); + api.getAllChannelIds.mockRejectedValue(new Error(errorMessage)); const { result } = renderHook(() => useChannelsStore()); + await act(async () => { + await result.current.fetchChannelIds(); + }); + expect(result.current.error).toBe(errorMessage); expect(result.current.isLoading).toBe(false); }); diff --git a/frontend/src/store/channels.jsx b/frontend/src/store/channels.jsx index b6475ddf..15aa5776 100644 --- a/frontend/src/store/channels.jsx +++ b/frontend/src/store/channels.jsx @@ -129,6 +129,7 @@ const useChannelsStore = create((set, get) => ({ const channelIds = await api.getAllChannelIds(); set({ channelIds, + isLoading: false, }); } catch (error) { set({ error: error.message, isLoading: false });