mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Refactor tests in useGitOperations and useWorkspaceOperations to handle undefined values gracefully
This commit is contained in:
@@ -380,7 +380,7 @@ describe('useGitOperations', () => {
|
|||||||
it('handles undefined workspace name gracefully', async () => {
|
it('handles undefined workspace name gracefully', async () => {
|
||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: undefined as unknown as string,
|
name: undefined!,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
@@ -396,7 +396,7 @@ describe('useGitOperations', () => {
|
|||||||
|
|
||||||
it('handles missing settings gracefully', async () => {
|
it('handles missing settings gracefully', async () => {
|
||||||
mockWorkspaceData.settings = {
|
mockWorkspaceData.settings = {
|
||||||
gitEnabled: undefined as unknown as boolean,
|
gitEnabled: undefined!,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
@@ -413,7 +413,7 @@ describe('useGitOperations', () => {
|
|||||||
it('handles API returning non-string commit hash', async () => {
|
it('handles API returning non-string commit hash', async () => {
|
||||||
const mockCommitAndPush = vi.mocked(gitApi.commitAndPush);
|
const mockCommitAndPush = vi.mocked(gitApi.commitAndPush);
|
||||||
// API might return something unexpected
|
// API might return something unexpected
|
||||||
mockCommitAndPush.mockResolvedValue(null as unknown as string);
|
mockCommitAndPush.mockResolvedValue(null!);
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
|
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ describe('useWorkspaceOperations', () => {
|
|||||||
it('updates workspace settings successfully', async () => {
|
it('updates workspace settings successfully', async () => {
|
||||||
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
||||||
const updatedWorkspace: Workspace = {
|
const updatedWorkspace: Workspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace as Workspace),
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
autoSave: true,
|
autoSave: true,
|
||||||
showHiddenFiles: true,
|
showHiddenFiles: true,
|
||||||
};
|
};
|
||||||
@@ -421,25 +421,8 @@ describe('useWorkspaceOperations', () => {
|
|||||||
it('updates theme and calls updateColorScheme', async () => {
|
it('updates theme and calls updateColorScheme', async () => {
|
||||||
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
||||||
const updatedWorkspace: Workspace = {
|
const updatedWorkspace: Workspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace ?? {
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'test-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
}),
|
|
||||||
theme: Theme.Dark,
|
theme: Theme.Dark,
|
||||||
name: mockWorkspaceData.currentWorkspace?.name ?? 'test-workspace',
|
|
||||||
};
|
};
|
||||||
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
||||||
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
||||||
@@ -467,23 +450,7 @@ describe('useWorkspaceOperations', () => {
|
|||||||
it('updates multiple settings including theme', async () => {
|
it('updates multiple settings including theme', async () => {
|
||||||
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
||||||
const updatedWorkspace: Workspace = {
|
const updatedWorkspace: Workspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace ?? {
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'test-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
}),
|
|
||||||
theme: Theme.Dark,
|
theme: Theme.Dark,
|
||||||
autoSave: true,
|
autoSave: true,
|
||||||
gitEnabled: true,
|
gitEnabled: true,
|
||||||
@@ -564,23 +531,7 @@ describe('useWorkspaceOperations', () => {
|
|||||||
.mockImplementation(() => {});
|
.mockImplementation(() => {});
|
||||||
|
|
||||||
const updatedWorkspace: Workspace = {
|
const updatedWorkspace: Workspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace ?? {
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'test-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
}),
|
|
||||||
autoSave: true,
|
autoSave: true,
|
||||||
};
|
};
|
||||||
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
||||||
@@ -609,23 +560,7 @@ describe('useWorkspaceOperations', () => {
|
|||||||
|
|
||||||
it('handles empty settings update', async () => {
|
it('handles empty settings update', async () => {
|
||||||
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
const mockUpdateWorkspace = vi.mocked(workspaceApi.updateWorkspace);
|
||||||
const updatedWorkspace = mockWorkspaceData.currentWorkspace ?? {
|
const updatedWorkspace = mockWorkspaceData.currentWorkspace!;
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'test-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
};
|
|
||||||
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
mockUpdateWorkspace.mockResolvedValue(updatedWorkspace);
|
||||||
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
||||||
|
|
||||||
@@ -684,23 +619,7 @@ describe('useWorkspaceOperations', () => {
|
|||||||
|
|
||||||
// Update workspace name
|
// Update workspace name
|
||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace ?? {
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'different-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
}),
|
|
||||||
name: 'different-workspace',
|
name: 'different-workspace',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -734,45 +653,8 @@ describe('useWorkspaceOperations', () => {
|
|||||||
|
|
||||||
// Change workspace
|
// Change workspace
|
||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
...(mockWorkspaceData.currentWorkspace ?? {
|
...mockWorkspaceData.currentWorkspace!,
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'new-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
}),
|
|
||||||
name: 'new-workspace',
|
name: 'new-workspace',
|
||||||
createdAt:
|
|
||||||
mockWorkspaceData.currentWorkspace?.createdAt ??
|
|
||||||
'2024-01-01T00:00:00Z',
|
|
||||||
id: mockWorkspaceData.currentWorkspace?.id ?? 1,
|
|
||||||
userId: mockWorkspaceData.currentWorkspace?.userId ?? 1,
|
|
||||||
theme: mockWorkspaceData.currentWorkspace?.theme ?? Theme.Light,
|
|
||||||
autoSave: mockWorkspaceData.currentWorkspace?.autoSave ?? false,
|
|
||||||
showHiddenFiles:
|
|
||||||
mockWorkspaceData.currentWorkspace?.showHiddenFiles ?? false,
|
|
||||||
gitEnabled: mockWorkspaceData.currentWorkspace?.gitEnabled ?? false,
|
|
||||||
gitUrl: mockWorkspaceData.currentWorkspace?.gitUrl ?? '',
|
|
||||||
gitUser: mockWorkspaceData.currentWorkspace?.gitUser ?? '',
|
|
||||||
gitToken: mockWorkspaceData.currentWorkspace?.gitToken ?? '',
|
|
||||||
gitAutoCommit:
|
|
||||||
mockWorkspaceData.currentWorkspace?.gitAutoCommit ?? false,
|
|
||||||
gitCommitMsgTemplate:
|
|
||||||
mockWorkspaceData.currentWorkspace?.gitCommitMsgTemplate ??
|
|
||||||
'${action} ${filename}',
|
|
||||||
gitCommitName: mockWorkspaceData.currentWorkspace?.gitCommitName ?? '',
|
|
||||||
gitCommitEmail:
|
|
||||||
mockWorkspaceData.currentWorkspace?.gitCommitEmail ?? '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
rerender();
|
rerender();
|
||||||
@@ -816,27 +698,9 @@ describe('useWorkspaceOperations', () => {
|
|||||||
mockUpdateLastWorkspaceName.mockResolvedValue(undefined);
|
mockUpdateLastWorkspaceName.mockResolvedValue(undefined);
|
||||||
mockWorkspaceData.loadWorkspaceData.mockResolvedValue(undefined);
|
mockWorkspaceData.loadWorkspaceData.mockResolvedValue(undefined);
|
||||||
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
mockWorkspaceData.loadWorkspaces.mockResolvedValue(mockWorkspaces);
|
||||||
|
mockUpdateWorkspace.mockResolvedValue(
|
||||||
// Ensure we have a defined workspace to use
|
mockWorkspaceData.currentWorkspace!
|
||||||
const workspaceToUse: Workspace = {
|
);
|
||||||
id: 1,
|
|
||||||
userId: 1,
|
|
||||||
name: 'test-workspace',
|
|
||||||
createdAt: '2024-01-01T00:00:00Z',
|
|
||||||
theme: Theme.Light,
|
|
||||||
autoSave: false,
|
|
||||||
showHiddenFiles: false,
|
|
||||||
gitEnabled: false,
|
|
||||||
gitUrl: '',
|
|
||||||
gitUser: '',
|
|
||||||
gitToken: '',
|
|
||||||
gitAutoCommit: false,
|
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
|
||||||
gitCommitName: '',
|
|
||||||
gitCommitEmail: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUpdateWorkspace.mockResolvedValue(workspaceToUse);
|
|
||||||
|
|
||||||
const { result } = renderHook(() => useWorkspaceOperations());
|
const { result } = renderHook(() => useWorkspaceOperations());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user