mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 00:55:50 +00:00
Added isLoading: false to fetchChannelIds and fix auth and channels tests.
This commit is contained in:
parent
c68d73fbdb
commit
34a24b2e44
3 changed files with 16 additions and 16 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue