mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Remove redundant tests from contexts
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user