Refactor workspace settings handling in tests and components to use currentWorkspace directly

This commit is contained in:
2025-07-06 00:41:30 +02:00
parent 7368797a11
commit cf554fbb6e
9 changed files with 25 additions and 73 deletions

View File

@@ -70,7 +70,6 @@ describe('ContentView', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: mockCurrentWorkspace,
workspaces: [],
settings: mockCurrentWorkspace,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -88,7 +87,6 @@ describe('ContentView', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
workspaces: [],
settings: mockCurrentWorkspace,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',

View File

@@ -9,7 +9,7 @@ import React from 'react';
import { MantineProvider } from '@mantine/core';
import MarkdownPreview from './MarkdownPreview';
import { notifications } from '@mantine/notifications';
import { Theme, DEFAULT_WORKSPACE_SETTINGS } from '../../types/models';
import { Theme } from '../../types/models';
// Mock notifications
vi.mock('@mantine/notifications', () => ({
@@ -70,7 +70,6 @@ describe('MarkdownPreview', () => {
lastOpenedFilePath: '',
},
workspaces: [],
settings: DEFAULT_WORKSPACE_SETTINGS,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -213,7 +212,6 @@ describe('MarkdownPreview', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
workspaces: [],
settings: DEFAULT_WORKSPACE_SETTINGS,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',

View File

@@ -23,7 +23,10 @@ describe('FileActions', () => {
const mockSetDeleteFileModalVisible = vi.fn();
const mockSetCommitMessageModalVisible = vi.fn();
const mockSettings = {
const mockCurrentWorkspace = {
id: 1,
name: 'Test Workspace',
createdAt: '2024-01-01T00:00:00Z',
gitEnabled: true,
gitAutoCommit: false,
theme: Theme.Light,
@@ -61,9 +64,8 @@ describe('FileActions', () => {
const { useWorkspace } = await import('../../hooks/useWorkspace');
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
currentWorkspace: mockCurrentWorkspace,
workspaces: [],
settings: mockSettings,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -140,9 +142,8 @@ describe('FileActions', () => {
it('disables git buttons when git is not enabled', async () => {
const { useWorkspace } = await import('../../hooks/useWorkspace');
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
currentWorkspace: { ...mockCurrentWorkspace, gitEnabled: false },
workspaces: [],
settings: { ...mockSettings, gitEnabled: false },
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -186,9 +187,8 @@ describe('FileActions', () => {
it('disables commit button when auto-commit is enabled', async () => {
const { useWorkspace } = await import('../../hooks/useWorkspace');
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
currentWorkspace: { ...mockCurrentWorkspace, gitAutoCommit: true },
workspaces: [],
settings: { ...mockSettings, gitAutoCommit: true },
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',

View File

@@ -18,7 +18,7 @@ const FileActions: React.FC<FileActionsProps> = ({
handlePullChanges,
selectedFile,
}) => {
const { settings } = useWorkspace();
const { currentWorkspace } = useWorkspace();
const {
setNewFileModalVisible,
setDeleteFileModalVisible,
@@ -61,7 +61,7 @@ const FileActions: React.FC<FileActionsProps> = ({
<Tooltip
label={
settings.gitEnabled
currentWorkspace?.gitEnabled
? 'Pull changes from remote'
: 'Git is not enabled'
}
@@ -74,7 +74,7 @@ const FileActions: React.FC<FileActionsProps> = ({
console.error('Error pulling changes:', error);
});
}}
disabled={!settings.gitEnabled}
disabled={!currentWorkspace?.gitEnabled}
aria-label="Pull changes from remote"
data-testid="pull-changes-button"
>
@@ -84,9 +84,9 @@ const FileActions: React.FC<FileActionsProps> = ({
<Tooltip
label={
!settings.gitEnabled
!currentWorkspace?.gitEnabled
? 'Git is not enabled'
: settings.gitAutoCommit
: currentWorkspace.gitAutoCommit
? 'Auto-commit is enabled'
: 'Commit and push changes'
}
@@ -95,7 +95,9 @@ const FileActions: React.FC<FileActionsProps> = ({
variant="default"
size="md"
onClick={handleCommitAndPush}
disabled={!settings.gitEnabled || settings.gitAutoCommit}
disabled={
!currentWorkspace?.gitEnabled || currentWorkspace.gitAutoCommit
}
aria-label="Commit and push changes"
data-testid="commit-push-button"
>

View File

@@ -72,7 +72,6 @@ describe('Layout', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: mockCurrentWorkspace,
workspaces: [],
settings: mockCurrentWorkspace,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -112,7 +111,6 @@ describe('Layout', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: mockCurrentWorkspace,
workspaces: [],
settings: mockCurrentWorkspace,
updateSettings: vi.fn(),
loading: true,
colorScheme: 'light',
@@ -137,7 +135,6 @@ describe('Layout', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
workspaces: [],
settings: mockCurrentWorkspace,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',

View File

@@ -58,7 +58,10 @@ describe('Sidebar', () => {
},
];
const mockSettings = {
const mockCurrentWorkspace = {
id: 1,
name: 'test-workspace',
createdAt: '2024-01-01T00:00:00Z',
gitEnabled: true,
gitAutoCommit: false,
theme: Theme.Light,
@@ -88,7 +91,6 @@ describe('Sidebar', () => {
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
workspaces: [],
settings: mockSettings,
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',
@@ -122,9 +124,8 @@ describe('Sidebar', () => {
it('passes showHiddenFiles setting to file tree', async () => {
const { useWorkspace } = await import('../../hooks/useWorkspace');
vi.mocked(useWorkspace).mockReturnValue({
currentWorkspace: null,
currentWorkspace: { ...mockCurrentWorkspace, showHiddenFiles: true },
workspaces: [],
settings: { ...mockSettings, showHiddenFiles: true },
updateSettings: vi.fn(),
loading: false,
colorScheme: 'light',

View File

@@ -19,7 +19,7 @@ const Sidebar: React.FC<SidebarProps> = ({
files,
loadFileList,
}) => {
const { settings } = useWorkspace();
const { currentWorkspace } = useWorkspace();
const { handlePull } = useGitOperations();
useEffect(() => {
@@ -41,7 +41,7 @@ const Sidebar: React.FC<SidebarProps> = ({
<FileTree
files={files}
handleFileSelect={handleFileSelect}
showHiddenFiles={settings.showHiddenFiles || false}
showHiddenFiles={currentWorkspace?.showHiddenFiles || false}
/>
</Box>
);