Remove redundant tests from contexts

This commit is contained in:
2025-06-04 20:44:31 +02:00
parent 0fd87c072d
commit 73653c4271
3 changed files with 14 additions and 362 deletions

View File

@@ -687,142 +687,6 @@ describe('WorkspaceDataContext', () => {
});
});
describe('error handling', () => {
it('handles network errors during workspace loading', async () => {
const consoleSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(
null
);
(mockListWorkspaces as ReturnType<typeof vi.fn>).mockResolvedValue([]);
(mockGetWorkspace as ReturnType<typeof vi.fn>).mockRejectedValue(
new Error('Network unavailable')
);
const wrapper = createWrapper();
const { result } = renderHook(() => useWorkspaceData(), { wrapper });
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
await act(async () => {
await result.current.loadWorkspaceData('test-workspace');
});
expect(mockNotificationsShow).toHaveBeenCalledWith({
title: 'Error',
message: 'Failed to load workspace data',
color: 'red',
});
consoleSpy.mockRestore();
});
it('handles API errors during workspace list loading', async () => {
const consoleSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(
null
);
(mockListWorkspaces as ReturnType<typeof vi.fn>)
.mockResolvedValueOnce([]) // Initial load
.mockRejectedValueOnce(new Error('API Error'));
const wrapper = createWrapper();
const { result } = renderHook(() => useWorkspaceData(), { wrapper });
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
await act(async () => {
await result.current.loadWorkspaces();
});
expect(mockNotificationsShow).toHaveBeenCalledWith({
title: 'Error',
message: 'Failed to load workspaces list',
color: 'red',
});
consoleSpy.mockRestore();
});
});
describe('integration with ThemeContext', () => {
it('updates theme when workspace is loaded', async () => {
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(
'test-workspace'
);
(mockGetWorkspace as ReturnType<typeof vi.fn>).mockResolvedValue(
mockWorkspace
);
(mockListWorkspaces as ReturnType<typeof vi.fn>).mockResolvedValue(
mockWorkspaceList
);
const wrapper = createWrapper();
renderHook(() => useWorkspaceData(), { wrapper });
await waitFor(() => {
expect(mockUpdateColorScheme).toHaveBeenCalledWith('dark');
});
});
it('calls updateColorScheme when manually loading workspace', async () => {
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(
null
);
(mockListWorkspaces as ReturnType<typeof vi.fn>).mockResolvedValue([]);
(mockGetWorkspace as ReturnType<typeof vi.fn>).mockResolvedValue(
mockWorkspace2
);
const wrapper = createWrapper();
const { result } = renderHook(() => useWorkspaceData(), { wrapper });
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
await act(async () => {
await result.current.loadWorkspaceData('workspace-2');
});
expect(mockUpdateColorScheme).toHaveBeenCalledWith('light');
});
it('handles missing updateColorScheme gracefully', async () => {
mockUseTheme.mockReturnValue({
colorScheme: 'light',
updateColorScheme: undefined,
});
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(
'test-workspace'
);
(mockGetWorkspace as ReturnType<typeof vi.fn>).mockResolvedValue(
mockWorkspace
);
(mockListWorkspaces as ReturnType<typeof vi.fn>).mockResolvedValue(
mockWorkspaceList
);
const wrapper = createWrapper();
const { result } = renderHook(() => useWorkspaceData(), { wrapper });
await waitFor(() => {
expect(result.current.loading).toBe(false);
});
// Should not throw even though updateColorScheme is undefined
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
});
});
describe('concurrent operations', () => {
it('handles concurrent loadWorkspaceData calls', async () => {
(mockGetLastWorkspaceName as ReturnType<typeof vi.fn>).mockResolvedValue(