mirror of
https://github.com/OFFIS-ESC/constellation-analyzer
synced 2026-01-27 07:43:41 +00:00
Fix lint in unit test
This commit is contained in:
parent
8dcca18008
commit
00c7adc41d
1 changed files with 240 additions and 205 deletions
|
|
@ -1,18 +1,18 @@
|
||||||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
|
||||||
import { useWorkspaceStore } from './workspaceStore';
|
import { useWorkspaceStore } from "./workspaceStore";
|
||||||
import {
|
import {
|
||||||
loadWorkspaceState,
|
loadWorkspaceState,
|
||||||
loadDocumentFromStorage,
|
loadDocumentFromStorage,
|
||||||
clearWorkspaceStorage,
|
clearWorkspaceStorage,
|
||||||
} from './workspace/persistence';
|
} from "./workspace/persistence";
|
||||||
import { mockNodeTypes, mockEdgeTypes } from '../test-utils/mocks';
|
import { mockNodeTypes, mockEdgeTypes } from "../test-utils/mocks";
|
||||||
import type { TangibleConfig } from '../types';
|
import type { TangibleConfig } from "../types";
|
||||||
|
|
||||||
// Create a mock showToast that we can track
|
// Create a mock showToast that we can track
|
||||||
const mockShowToast = vi.fn();
|
const mockShowToast = vi.fn();
|
||||||
|
|
||||||
// Mock the dependent stores
|
// Mock the dependent stores
|
||||||
vi.mock('./toastStore', () => ({
|
vi.mock("./toastStore", () => ({
|
||||||
useToastStore: {
|
useToastStore: {
|
||||||
getState: () => ({
|
getState: () => ({
|
||||||
showToast: mockShowToast,
|
showToast: mockShowToast,
|
||||||
|
|
@ -20,7 +20,7 @@ vi.mock('./toastStore', () => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./timelineStore', () => ({
|
vi.mock("./timelineStore", () => ({
|
||||||
useTimelineStore: {
|
useTimelineStore: {
|
||||||
getState: () => ({
|
getState: () => ({
|
||||||
timelines: new Map(),
|
timelines: new Map(),
|
||||||
|
|
@ -30,7 +30,7 @@ vi.mock('./timelineStore', () => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./graphStore', () => ({
|
vi.mock("./graphStore", () => ({
|
||||||
useGraphStore: {
|
useGraphStore: {
|
||||||
getState: () => ({
|
getState: () => ({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
|
|
@ -50,7 +50,7 @@ vi.mock('./graphStore', () => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('./bibliographyStore', () => ({
|
vi.mock("./bibliographyStore", () => ({
|
||||||
useBibliographyStore: {
|
useBibliographyStore: {
|
||||||
getState: () => ({
|
getState: () => ({
|
||||||
citeInstance: {
|
citeInstance: {
|
||||||
|
|
@ -60,13 +60,13 @@ vi.mock('./bibliographyStore', () => ({
|
||||||
reset: vi.fn(),
|
reset: vi.fn(),
|
||||||
},
|
},
|
||||||
appMetadata: {},
|
appMetadata: {},
|
||||||
settings: { defaultStyle: 'apa', sortOrder: 'author' },
|
settings: { defaultStyle: "apa", sortOrder: "author" },
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
clearBibliographyForDocumentSwitch: vi.fn(),
|
clearBibliographyForDocumentSwitch: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('workspaceStore', () => {
|
describe("workspaceStore", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Clear localStorage
|
// Clear localStorage
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|
@ -79,8 +79,8 @@ describe('workspaceStore', () => {
|
||||||
// Reset workspace store to a clean state
|
// Reset workspace store to a clean state
|
||||||
// This simulates a fresh application start
|
// This simulates a fresh application start
|
||||||
useWorkspaceStore.setState({
|
useWorkspaceStore.setState({
|
||||||
workspaceId: 'test-workspace',
|
workspaceId: "test-workspace",
|
||||||
workspaceName: 'Test Workspace',
|
workspaceName: "Test Workspace",
|
||||||
documentOrder: [],
|
documentOrder: [],
|
||||||
activeDocumentId: null,
|
activeDocumentId: null,
|
||||||
documents: new Map(),
|
documents: new Map(),
|
||||||
|
|
@ -99,19 +99,19 @@ describe('workspaceStore', () => {
|
||||||
clearWorkspaceStorage();
|
clearWorkspaceStorage();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Initial State', () => {
|
describe("Initial State", () => {
|
||||||
it('should initialize with empty workspace', () => {
|
it("should initialize with empty workspace", () => {
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
||||||
expect(state.workspaceId).toBeDefined();
|
expect(state.workspaceId).toBeDefined();
|
||||||
expect(state.workspaceName).toBe('Test Workspace');
|
expect(state.workspaceName).toBe("Test Workspace");
|
||||||
expect(state.documentOrder).toEqual([]);
|
expect(state.documentOrder).toEqual([]);
|
||||||
expect(state.activeDocumentId).toBeNull();
|
expect(state.activeDocumentId).toBeNull();
|
||||||
expect(state.documents.size).toBe(0);
|
expect(state.documents.size).toBe(0);
|
||||||
expect(state.documentMetadata.size).toBe(0);
|
expect(state.documentMetadata.size).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have default settings', () => {
|
it("should have default settings", () => {
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
||||||
expect(state.settings.maxOpenDocuments).toBe(10);
|
expect(state.settings.maxOpenDocuments).toBe(10);
|
||||||
|
|
@ -122,9 +122,9 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Document Creation', () => {
|
describe("Document Creation", () => {
|
||||||
describe('createDocument', () => {
|
describe("createDocument", () => {
|
||||||
it('should create a new document with default title', () => {
|
it("should create a new document with default title", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const documentId = createDocument();
|
const documentId = createDocument();
|
||||||
|
|
@ -138,17 +138,17 @@ describe('workspaceStore', () => {
|
||||||
expect(state.activeDocumentId).toBe(documentId);
|
expect(state.activeDocumentId).toBe(documentId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create document with custom title', () => {
|
it("should create document with custom title", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const documentId = createDocument('My Analysis');
|
const documentId = createDocument("My Analysis");
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
const metadata = state.documentMetadata.get(documentId);
|
const metadata = state.documentMetadata.get(documentId);
|
||||||
expect(metadata?.title).toBe('My Analysis');
|
expect(metadata?.title).toBe("My Analysis");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should initialize document with default types', () => {
|
it("should initialize document with default types", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const documentId = createDocument();
|
const documentId = createDocument();
|
||||||
|
|
@ -159,7 +159,7 @@ describe('workspaceStore', () => {
|
||||||
expect(document?.edgeTypes).toHaveLength(2);
|
expect(document?.edgeTypes).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should save document to localStorage', () => {
|
it("should save document to localStorage", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const documentId = createDocument();
|
const documentId = createDocument();
|
||||||
|
|
@ -168,24 +168,25 @@ describe('workspaceStore', () => {
|
||||||
expect(loaded).toBeTruthy();
|
expect(loaded).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show success toast', () => {
|
it("should show success toast", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
createDocument('Test Doc');
|
createDocument("Test Doc");
|
||||||
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith(
|
expect(mockShowToast).toHaveBeenCalledWith(
|
||||||
'Document "Test Doc" created',
|
'Document "Test Doc" created',
|
||||||
'success'
|
"success",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createDocumentFromTemplate', () => {
|
describe("createDocumentFromTemplate", () => {
|
||||||
it('should create document from template with same types', () => {
|
it("should create document from template with same types", () => {
|
||||||
const { createDocument, createDocumentFromTemplate } = useWorkspaceStore.getState();
|
const { createDocument, createDocumentFromTemplate } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const sourceId = createDocument('Source');
|
const sourceId = createDocument("Source");
|
||||||
const newId = createDocumentFromTemplate(sourceId, 'From Template');
|
const newId = createDocumentFromTemplate(sourceId, "From Template");
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
const source = state.documents.get(sourceId);
|
const source = state.documents.get(sourceId);
|
||||||
|
|
@ -195,10 +196,11 @@ describe('workspaceStore', () => {
|
||||||
expect(newDoc?.edgeTypes).toEqual(source?.edgeTypes);
|
expect(newDoc?.edgeTypes).toEqual(source?.edgeTypes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create empty graph from template', () => {
|
it("should create empty graph from template", () => {
|
||||||
const { createDocument, createDocumentFromTemplate } = useWorkspaceStore.getState();
|
const { createDocument, createDocumentFromTemplate } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const sourceId = createDocument('Source');
|
const sourceId = createDocument("Source");
|
||||||
const newId = createDocumentFromTemplate(sourceId);
|
const newId = createDocumentFromTemplate(sourceId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -209,23 +211,24 @@ describe('workspaceStore', () => {
|
||||||
expect(newDoc?.edgeTypes).toHaveLength(2);
|
expect(newDoc?.edgeTypes).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle non-existent source document', () => {
|
it("should handle non-existent source document", () => {
|
||||||
const { createDocumentFromTemplate } = useWorkspaceStore.getState();
|
const { createDocumentFromTemplate } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const result = createDocumentFromTemplate('non-existent-id');
|
const result = createDocumentFromTemplate("non-existent-id");
|
||||||
|
|
||||||
expect(result).toBe('');
|
expect(result).toBe("");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Document Navigation', () => {
|
describe("Document Navigation", () => {
|
||||||
describe('switchToDocument', () => {
|
describe("switchToDocument", () => {
|
||||||
it('should switch active document', async () => {
|
it("should switch active document", async () => {
|
||||||
const { createDocument, switchToDocument } = useWorkspaceStore.getState();
|
const { createDocument, switchToDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const doc1 = createDocument('Doc 1');
|
const doc1 = createDocument("Doc 1");
|
||||||
createDocument('Doc 2');
|
createDocument("Doc 2");
|
||||||
|
|
||||||
await switchToDocument(doc1);
|
await switchToDocument(doc1);
|
||||||
|
|
||||||
|
|
@ -233,10 +236,11 @@ describe('workspaceStore', () => {
|
||||||
expect(state.activeDocumentId).toBe(doc1);
|
expect(state.activeDocumentId).toBe(doc1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add document to order if not present', async () => {
|
it("should add document to order if not present", async () => {
|
||||||
const { createDocument, closeDocument, switchToDocument } = useWorkspaceStore.getState();
|
const { createDocument, closeDocument, switchToDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
closeDocument(docId);
|
closeDocument(docId);
|
||||||
|
|
||||||
// Document closed but still in storage
|
// Document closed but still in storage
|
||||||
|
|
@ -247,13 +251,14 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('reorderDocuments', () => {
|
describe("reorderDocuments", () => {
|
||||||
it('should reorder document tabs', () => {
|
it("should reorder document tabs", () => {
|
||||||
const { createDocument, reorderDocuments } = useWorkspaceStore.getState();
|
const { createDocument, reorderDocuments } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const doc1 = createDocument('Doc 1');
|
const doc1 = createDocument("Doc 1");
|
||||||
const doc2 = createDocument('Doc 2');
|
const doc2 = createDocument("Doc 2");
|
||||||
const doc3 = createDocument('Doc 3');
|
const doc3 = createDocument("Doc 3");
|
||||||
|
|
||||||
reorderDocuments([doc3, doc1, doc2]);
|
reorderDocuments([doc3, doc1, doc2]);
|
||||||
|
|
||||||
|
|
@ -263,52 +268,53 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Document Modification', () => {
|
describe("Document Modification", () => {
|
||||||
describe('renameDocument', () => {
|
describe("renameDocument", () => {
|
||||||
it('should rename document', () => {
|
it("should rename document", () => {
|
||||||
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Old Name');
|
const docId = createDocument("Old Name");
|
||||||
renameDocument(docId, 'New Name');
|
renameDocument(docId, "New Name");
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
const metadata = state.documentMetadata.get(docId);
|
const metadata = state.documentMetadata.get(docId);
|
||||||
expect(metadata?.title).toBe('New Name');
|
expect(metadata?.title).toBe("New Name");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update lastModified timestamp', async () => {
|
it("should update lastModified timestamp", async () => {
|
||||||
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
const state1 = useWorkspaceStore.getState();
|
const state1 = useWorkspaceStore.getState();
|
||||||
const originalTime = state1.documentMetadata.get(docId)?.lastModified;
|
const originalTime = state1.documentMetadata.get(docId)?.lastModified;
|
||||||
|
|
||||||
// Small delay to ensure timestamp difference
|
// Small delay to ensure timestamp difference
|
||||||
await new Promise(resolve => setTimeout(resolve, 10));
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||||
|
|
||||||
renameDocument(docId, 'Renamed');
|
renameDocument(docId, "Renamed");
|
||||||
|
|
||||||
const state2 = useWorkspaceStore.getState();
|
const state2 = useWorkspaceStore.getState();
|
||||||
const newTime = state2.documentMetadata.get(docId)?.lastModified;
|
const newTime = state2.documentMetadata.get(docId)?.lastModified;
|
||||||
expect(newTime).not.toBe(originalTime);
|
expect(newTime).not.toBe(originalTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should persist rename to storage', () => {
|
it("should persist rename to storage", () => {
|
||||||
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
const { createDocument, renameDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
renameDocument(docId, 'Renamed');
|
renameDocument(docId, "Renamed");
|
||||||
|
|
||||||
const loaded = loadDocumentFromStorage(docId);
|
const loaded = loadDocumentFromStorage(docId);
|
||||||
expect(loaded?.metadata.title).toBe('Renamed');
|
expect(loaded?.metadata.title).toBe("Renamed");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('duplicateDocument', () => {
|
describe("duplicateDocument", () => {
|
||||||
it('should create copy of document', () => {
|
it("should create copy of document", () => {
|
||||||
const { createDocument, duplicateDocument } = useWorkspaceStore.getState();
|
const { createDocument, duplicateDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const originalId = createDocument('Original');
|
const originalId = createDocument("Original");
|
||||||
const duplicateId = duplicateDocument(originalId);
|
const duplicateId = duplicateDocument(originalId);
|
||||||
|
|
||||||
expect(duplicateId).toBeTruthy();
|
expect(duplicateId).toBeTruthy();
|
||||||
|
|
@ -316,13 +322,14 @@ describe('workspaceStore', () => {
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
const metadata = state.documentMetadata.get(duplicateId);
|
const metadata = state.documentMetadata.get(duplicateId);
|
||||||
expect(metadata?.title).toBe('Original (Copy)');
|
expect(metadata?.title).toBe("Original (Copy)");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should copy document types', () => {
|
it("should copy document types", () => {
|
||||||
const { createDocument, duplicateDocument } = useWorkspaceStore.getState();
|
const { createDocument, duplicateDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const originalId = createDocument('Original');
|
const originalId = createDocument("Original");
|
||||||
const duplicateId = duplicateDocument(originalId);
|
const duplicateId = duplicateDocument(originalId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -333,24 +340,25 @@ describe('workspaceStore', () => {
|
||||||
expect(duplicate?.edgeTypes).toEqual(original?.edgeTypes);
|
expect(duplicate?.edgeTypes).toEqual(original?.edgeTypes);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle non-existent document', () => {
|
it("should handle non-existent document", () => {
|
||||||
const { duplicateDocument } = useWorkspaceStore.getState();
|
const { duplicateDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const result = duplicateDocument('non-existent');
|
const result = duplicateDocument("non-existent");
|
||||||
|
|
||||||
expect(result).toBe('');
|
expect(result).toBe("");
|
||||||
expect(mockShowToast).toHaveBeenCalledWith(
|
expect(mockShowToast).toHaveBeenCalledWith(
|
||||||
'Failed to duplicate: Document not found',
|
"Failed to duplicate: Document not found",
|
||||||
'error'
|
"error",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('markDocumentDirty / saveDocument', () => {
|
describe("markDocumentDirty / saveDocument", () => {
|
||||||
it('should mark document as dirty', () => {
|
it("should mark document as dirty", () => {
|
||||||
const { createDocument, markDocumentDirty } = useWorkspaceStore.getState();
|
const { createDocument, markDocumentDirty } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
markDocumentDirty(docId);
|
markDocumentDirty(docId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -358,10 +366,11 @@ describe('workspaceStore', () => {
|
||||||
expect(metadata?.isDirty).toBe(true);
|
expect(metadata?.isDirty).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear dirty flag on save', () => {
|
it("should clear dirty flag on save", () => {
|
||||||
const { createDocument, markDocumentDirty, saveDocument } = useWorkspaceStore.getState();
|
const { createDocument, markDocumentDirty, saveDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
markDocumentDirty(docId);
|
markDocumentDirty(docId);
|
||||||
saveDocument(docId);
|
saveDocument(docId);
|
||||||
|
|
||||||
|
|
@ -370,15 +379,15 @@ describe('workspaceStore', () => {
|
||||||
expect(metadata?.isDirty).toBe(false);
|
expect(metadata?.isDirty).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update updatedAt timestamp on save', async () => {
|
it("should update updatedAt timestamp on save", async () => {
|
||||||
const { createDocument, saveDocument } = useWorkspaceStore.getState();
|
const { createDocument, saveDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
const state1 = useWorkspaceStore.getState();
|
const state1 = useWorkspaceStore.getState();
|
||||||
const doc1 = state1.documents.get(docId);
|
const doc1 = state1.documents.get(docId);
|
||||||
const originalTime = doc1?.metadata.updatedAt;
|
const originalTime = doc1?.metadata.updatedAt;
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 10));
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||||
saveDocument(docId);
|
saveDocument(docId);
|
||||||
|
|
||||||
const state2 = useWorkspaceStore.getState();
|
const state2 = useWorkspaceStore.getState();
|
||||||
|
|
@ -388,12 +397,12 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Document Deletion', () => {
|
describe("Document Deletion", () => {
|
||||||
describe('closeDocument', () => {
|
describe("closeDocument", () => {
|
||||||
it('should close document and remove from memory', () => {
|
it("should close document and remove from memory", () => {
|
||||||
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
closeDocument(docId);
|
closeDocument(docId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -401,10 +410,11 @@ describe('workspaceStore', () => {
|
||||||
expect(state.documentOrder).not.toContain(docId);
|
expect(state.documentOrder).not.toContain(docId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prompt if document has unsaved changes', () => {
|
it("should prompt if document has unsaved changes", () => {
|
||||||
const { createDocument, markDocumentDirty, closeDocument } = useWorkspaceStore.getState();
|
const { createDocument, markDocumentDirty, closeDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
markDocumentDirty(docId);
|
markDocumentDirty(docId);
|
||||||
|
|
||||||
global.confirm = vi.fn(() => false);
|
global.confirm = vi.fn(() => false);
|
||||||
|
|
@ -414,11 +424,11 @@ describe('workspaceStore', () => {
|
||||||
expect(global.confirm).toHaveBeenCalled();
|
expect(global.confirm).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should switch to next document after close', () => {
|
it("should switch to next document after close", () => {
|
||||||
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const doc1 = createDocument('Doc 1');
|
const doc1 = createDocument("Doc 1");
|
||||||
const doc2 = createDocument('Doc 2');
|
const doc2 = createDocument("Doc 2");
|
||||||
|
|
||||||
closeDocument(doc2);
|
closeDocument(doc2);
|
||||||
|
|
||||||
|
|
@ -426,10 +436,10 @@ describe('workspaceStore', () => {
|
||||||
expect(state.activeDocumentId).toBe(doc1);
|
expect(state.activeDocumentId).toBe(doc1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set active to null if no documents left', () => {
|
it("should set active to null if no documents left", () => {
|
||||||
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
const { createDocument, closeDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Only Doc');
|
const docId = createDocument("Only Doc");
|
||||||
closeDocument(docId);
|
closeDocument(docId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -437,11 +447,11 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteDocument', () => {
|
describe("deleteDocument", () => {
|
||||||
it('should delete document completely', () => {
|
it("should delete document completely", () => {
|
||||||
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
deleteDocument(docId);
|
deleteDocument(docId);
|
||||||
|
|
||||||
const state = useWorkspaceStore.getState();
|
const state = useWorkspaceStore.getState();
|
||||||
|
|
@ -450,35 +460,35 @@ describe('workspaceStore', () => {
|
||||||
expect(state.documentOrder).not.toContain(docId);
|
expect(state.documentOrder).not.toContain(docId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove from localStorage', () => {
|
it("should remove from localStorage", () => {
|
||||||
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
deleteDocument(docId);
|
deleteDocument(docId);
|
||||||
|
|
||||||
const loaded = loadDocumentFromStorage(docId);
|
const loaded = loadDocumentFromStorage(docId);
|
||||||
expect(loaded).toBeNull();
|
expect(loaded).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show success toast', () => {
|
it("should show success toast", () => {
|
||||||
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
const { createDocument, deleteDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test Doc');
|
const docId = createDocument("Test Doc");
|
||||||
deleteDocument(docId);
|
deleteDocument(docId);
|
||||||
|
|
||||||
expect(mockShowToast).toHaveBeenCalledWith(
|
expect(mockShowToast).toHaveBeenCalledWith(
|
||||||
'Document "Test Doc" deleted',
|
'Document "Test Doc" deleted',
|
||||||
'info'
|
"info",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Viewport Management', () => {
|
describe("Viewport Management", () => {
|
||||||
it('should save viewport state', () => {
|
it("should save viewport state", () => {
|
||||||
const { createDocument, saveViewport } = useWorkspaceStore.getState();
|
const { createDocument, saveViewport } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
const viewport = { x: 100, y: 200, zoom: 1.5 };
|
const viewport = { x: 100, y: 200, zoom: 1.5 };
|
||||||
|
|
||||||
saveViewport(docId, viewport);
|
saveViewport(docId, viewport);
|
||||||
|
|
@ -488,10 +498,11 @@ describe('workspaceStore', () => {
|
||||||
expect(metadata?.viewport).toEqual(viewport);
|
expect(metadata?.viewport).toEqual(viewport);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve viewport state', () => {
|
it("should retrieve viewport state", () => {
|
||||||
const { createDocument, saveViewport, getViewport } = useWorkspaceStore.getState();
|
const { createDocument, saveViewport, getViewport } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
const viewport = { x: 100, y: 200, zoom: 1.5 };
|
const viewport = { x: 100, y: 200, zoom: 1.5 };
|
||||||
|
|
||||||
saveViewport(docId, viewport);
|
saveViewport(docId, viewport);
|
||||||
|
|
@ -500,21 +511,21 @@ describe('workspaceStore', () => {
|
||||||
expect(retrieved).toEqual(viewport);
|
expect(retrieved).toEqual(viewport);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined for non-existent document', () => {
|
it("should return undefined for non-existent document", () => {
|
||||||
const { getViewport } = useWorkspaceStore.getState();
|
const { getViewport } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const result = getViewport('non-existent');
|
const result = getViewport("non-existent");
|
||||||
|
|
||||||
expect(result).toBeUndefined();
|
expect(result).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Workspace Operations', () => {
|
describe("Workspace Operations", () => {
|
||||||
describe('saveWorkspace', () => {
|
describe("saveWorkspace", () => {
|
||||||
it('should persist workspace state', () => {
|
it("should persist workspace state", () => {
|
||||||
const { createDocument, saveWorkspace } = useWorkspaceStore.getState();
|
const { createDocument, saveWorkspace } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
createDocument('Test');
|
createDocument("Test");
|
||||||
saveWorkspace();
|
saveWorkspace();
|
||||||
|
|
||||||
const loaded = loadWorkspaceState();
|
const loaded = loadWorkspaceState();
|
||||||
|
|
@ -523,8 +534,8 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('clearWorkspace', () => {
|
describe("clearWorkspace", () => {
|
||||||
it('should prompt for confirmation', () => {
|
it("should prompt for confirmation", () => {
|
||||||
const { clearWorkspace } = useWorkspaceStore.getState();
|
const { clearWorkspace } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
global.confirm = vi.fn(() => false);
|
global.confirm = vi.fn(() => false);
|
||||||
|
|
@ -533,11 +544,11 @@ describe('workspaceStore', () => {
|
||||||
expect(global.confirm).toHaveBeenCalled();
|
expect(global.confirm).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear all documents when confirmed', () => {
|
it("should clear all documents when confirmed", () => {
|
||||||
const { createDocument, clearWorkspace } = useWorkspaceStore.getState();
|
const { createDocument, clearWorkspace } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
createDocument('Doc 1');
|
createDocument("Doc 1");
|
||||||
createDocument('Doc 2');
|
createDocument("Doc 2");
|
||||||
|
|
||||||
global.confirm = vi.fn(() => true);
|
global.confirm = vi.fn(() => true);
|
||||||
clearWorkspace();
|
clearWorkspace();
|
||||||
|
|
@ -548,10 +559,10 @@ describe('workspaceStore', () => {
|
||||||
expect(state.documentOrder).toEqual([]);
|
expect(state.documentOrder).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear localStorage', () => {
|
it("should clear localStorage", () => {
|
||||||
const { createDocument, clearWorkspace } = useWorkspaceStore.getState();
|
const { createDocument, clearWorkspace } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
|
|
||||||
// Verify document exists
|
// Verify document exists
|
||||||
expect(loadDocumentFromStorage(docId)).toBeTruthy();
|
expect(loadDocumentFromStorage(docId)).toBeTruthy();
|
||||||
|
|
@ -569,11 +580,12 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getActiveDocument', () => {
|
describe("getActiveDocument", () => {
|
||||||
it('should return active document', () => {
|
it("should return active document", () => {
|
||||||
const { createDocument, getActiveDocument } = useWorkspaceStore.getState();
|
const { createDocument, getActiveDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test');
|
const docId = createDocument("Test");
|
||||||
|
|
||||||
const activeDoc = getActiveDocument();
|
const activeDoc = getActiveDocument();
|
||||||
|
|
||||||
|
|
@ -581,7 +593,7 @@ describe('workspaceStore', () => {
|
||||||
expect(activeDoc?.metadata.documentId).toBe(docId);
|
expect(activeDoc?.metadata.documentId).toBe(docId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if no active document', () => {
|
it("should return null if no active document", () => {
|
||||||
const { getActiveDocument } = useWorkspaceStore.getState();
|
const { getActiveDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const result = getActiveDocument();
|
const result = getActiveDocument();
|
||||||
|
|
@ -591,33 +603,40 @@ describe('workspaceStore', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Document Presentation Preference', () => {
|
describe("Document Presentation Preference", () => {
|
||||||
describe('setDocumentPresentationPreference', () => {
|
describe("setDocumentPresentationPreference", () => {
|
||||||
it('should set document presentation preference', () => {
|
it("should set document presentation preference", () => {
|
||||||
const { createDocument, setDocumentPresentationPreference } = useWorkspaceStore.getState();
|
const { createDocument, setDocumentPresentationPreference } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test Doc');
|
const docId = createDocument("Test Doc");
|
||||||
setDocumentPresentationPreference(docId, true);
|
setDocumentPresentationPreference(docId, true);
|
||||||
|
|
||||||
const metadata = useWorkspaceStore.getState().documentMetadata.get(docId);
|
const metadata = useWorkspaceStore
|
||||||
|
.getState()
|
||||||
|
.documentMetadata.get(docId);
|
||||||
expect(metadata?.preferPresentationMode).toBe(true);
|
expect(metadata?.preferPresentationMode).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update existing document preference', () => {
|
it("should update existing document preference", () => {
|
||||||
const { createDocument, setDocumentPresentationPreference } = useWorkspaceStore.getState();
|
const { createDocument, setDocumentPresentationPreference } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test Doc');
|
const docId = createDocument("Test Doc");
|
||||||
setDocumentPresentationPreference(docId, true);
|
setDocumentPresentationPreference(docId, true);
|
||||||
setDocumentPresentationPreference(docId, false);
|
setDocumentPresentationPreference(docId, false);
|
||||||
|
|
||||||
const metadata = useWorkspaceStore.getState().documentMetadata.get(docId);
|
const metadata = useWorkspaceStore
|
||||||
|
.getState()
|
||||||
|
.documentMetadata.get(docId);
|
||||||
expect(metadata?.preferPresentationMode).toBe(false);
|
expect(metadata?.preferPresentationMode).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should persist document presentation preference to storage', () => {
|
it("should persist document presentation preference to storage", () => {
|
||||||
const { createDocument, setDocumentPresentationPreference } = useWorkspaceStore.getState();
|
const { createDocument, setDocumentPresentationPreference } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
const docId = createDocument('Test Doc');
|
const docId = createDocument("Test Doc");
|
||||||
setDocumentPresentationPreference(docId, true);
|
setDocumentPresentationPreference(docId, true);
|
||||||
|
|
||||||
// Verify it persists by checking localStorage (using correct prefix)
|
// Verify it persists by checking localStorage (using correct prefix)
|
||||||
|
|
@ -628,31 +647,34 @@ describe('workspaceStore', () => {
|
||||||
expect(parsed.preferPresentationMode).toBe(true);
|
expect(parsed.preferPresentationMode).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle invalid document ID gracefully', () => {
|
it("should handle invalid document ID gracefully", () => {
|
||||||
const { setDocumentPresentationPreference } = useWorkspaceStore.getState();
|
const { setDocumentPresentationPreference } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
// Should not throw error
|
// Should not throw error
|
||||||
expect(() => setDocumentPresentationPreference('invalid', true)).not.toThrow();
|
expect(() =>
|
||||||
|
setDocumentPresentationPreference("invalid", true),
|
||||||
|
).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Tangible Management', () => {
|
describe("Tangible Management", () => {
|
||||||
let documentId: string;
|
let documentId: string;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
documentId = useWorkspaceStore.getState().createDocument('Test Doc');
|
documentId = useWorkspaceStore.getState().createDocument("Test Doc");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('addTangibleToDocument', () => {
|
describe("addTangibleToDocument", () => {
|
||||||
it('should add tangible to document', () => {
|
it("should add tangible to document", () => {
|
||||||
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const tangible = {
|
const tangible = {
|
||||||
name: 'Red Block',
|
name: "Red Block",
|
||||||
mode: 'filter' as const,
|
mode: "filter" as const,
|
||||||
filterLabels: ['label-1'],
|
filterLabels: ["label-1"],
|
||||||
hardwareId: 'token-001',
|
hardwareId: "token-001",
|
||||||
};
|
};
|
||||||
|
|
||||||
addTangibleToDocument(documentId, tangible as TangibleConfig);
|
addTangibleToDocument(documentId, tangible as TangibleConfig);
|
||||||
|
|
@ -660,17 +682,17 @@ describe('workspaceStore', () => {
|
||||||
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
||||||
expect(doc?.tangibles).toHaveLength(1);
|
expect(doc?.tangibles).toHaveLength(1);
|
||||||
expect(doc?.tangibles?.[0].id).toMatch(/^tangible_\d+_[a-z0-9]+$/); // Random ID format
|
expect(doc?.tangibles?.[0].id).toMatch(/^tangible_\d+_[a-z0-9]+$/); // Random ID format
|
||||||
expect(doc?.tangibles?.[0].name).toBe('Red Block');
|
expect(doc?.tangibles?.[0].name).toBe("Red Block");
|
||||||
expect(doc?.tangibles?.[0].hardwareId).toBe('token-001');
|
expect(doc?.tangibles?.[0].hardwareId).toBe("token-001");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow duplicate tangible names', () => {
|
it("should allow duplicate tangible names", () => {
|
||||||
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const tangible = {
|
const tangible = {
|
||||||
name: 'Red Block',
|
name: "Red Block",
|
||||||
mode: 'filter' as const,
|
mode: "filter" as const,
|
||||||
filterLabels: ['label-1'],
|
filterLabels: ["label-1"],
|
||||||
};
|
};
|
||||||
|
|
||||||
addTangibleToDocument(documentId, tangible as TangibleConfig);
|
addTangibleToDocument(documentId, tangible as TangibleConfig);
|
||||||
|
|
@ -681,82 +703,89 @@ describe('workspaceStore', () => {
|
||||||
expect(doc?.tangibles?.[0].id).not.toBe(doc?.tangibles?.[1].id); // Different IDs
|
expect(doc?.tangibles?.[0].id).not.toBe(doc?.tangibles?.[1].id); // Different IDs
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle invalid document ID", () => {
|
||||||
it('should handle invalid document ID', () => {
|
|
||||||
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const tangible = {
|
const tangible = {
|
||||||
name: 'Red Block',
|
name: "Red Block",
|
||||||
mode: 'filter' as const,
|
mode: "filter" as const,
|
||||||
filterLabels: [],
|
filterLabels: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
// Should not throw
|
// Should not throw
|
||||||
expect(() => addTangibleToDocument('invalid-id', tangible as TangibleConfig)).not.toThrow();
|
expect(() =>
|
||||||
|
addTangibleToDocument("invalid-id", tangible as TangibleConfig),
|
||||||
|
).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateTangibleInDocument', () => {
|
describe("updateTangibleInDocument", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
||||||
addTangibleToDocument(documentId, {
|
addTangibleToDocument(documentId, {
|
||||||
name: 'Original',
|
name: "Original",
|
||||||
mode: 'filter' as const,
|
mode: "filter" as const,
|
||||||
filterLabels: ['label-1'],
|
filterLabels: ["label-1"],
|
||||||
} as TangibleConfig);
|
} as TangibleConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update tangible in document', () => {
|
it("should update tangible in document", () => {
|
||||||
const { updateTangibleInDocument } = useWorkspaceStore.getState();
|
const { updateTangibleInDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
// Get the auto-generated ID
|
// Get the auto-generated ID
|
||||||
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
||||||
const tangibleId = doc?.tangibles?.[0].id!;
|
const tangibleId = doc!.tangibles![0].id!;
|
||||||
|
|
||||||
updateTangibleInDocument(documentId, tangibleId, { name: 'Updated', hardwareId: 'token-002' });
|
updateTangibleInDocument(documentId, tangibleId, {
|
||||||
|
name: "Updated",
|
||||||
|
hardwareId: "token-002",
|
||||||
|
});
|
||||||
|
|
||||||
const updatedDoc = useWorkspaceStore.getState().documents.get(documentId);
|
const updatedDoc = useWorkspaceStore
|
||||||
expect(updatedDoc?.tangibles?.[0].name).toBe('Updated');
|
.getState()
|
||||||
expect(updatedDoc?.tangibles?.[0].hardwareId).toBe('token-002');
|
.documents.get(documentId);
|
||||||
|
expect(updatedDoc?.tangibles?.[0].name).toBe("Updated");
|
||||||
|
expect(updatedDoc?.tangibles?.[0].hardwareId).toBe("token-002");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteTangibleFromDocument', () => {
|
describe("deleteTangibleFromDocument", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
const { addTangibleToDocument } = useWorkspaceStore.getState();
|
||||||
addTangibleToDocument(documentId, {
|
addTangibleToDocument(documentId, {
|
||||||
name: 'T1',
|
name: "T1",
|
||||||
mode: 'filter' as const,
|
mode: "filter" as const,
|
||||||
filterLabels: ['label-1'],
|
filterLabels: ["label-1"],
|
||||||
} as TangibleConfig);
|
} as TangibleConfig);
|
||||||
addTangibleToDocument(documentId, {
|
addTangibleToDocument(documentId, {
|
||||||
name: 'T2',
|
name: "T2",
|
||||||
mode: 'state' as const,
|
mode: "state" as const,
|
||||||
stateId: 's1',
|
stateId: "s1",
|
||||||
} as TangibleConfig);
|
} as TangibleConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete tangible from document', () => {
|
it("should delete tangible from document", () => {
|
||||||
const { deleteTangibleFromDocument } = useWorkspaceStore.getState();
|
const { deleteTangibleFromDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
// Get the first tangible's ID
|
// Get the first tangible's ID
|
||||||
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
const doc = useWorkspaceStore.getState().documents.get(documentId);
|
||||||
const firstTangibleId = doc?.tangibles?.[0].id!;
|
const firstTangibleId = doc!.tangibles![0].id!;
|
||||||
const secondTangibleId = doc?.tangibles?.[1].id!;
|
const secondTangibleId = doc!.tangibles![1].id!;
|
||||||
|
|
||||||
deleteTangibleFromDocument(documentId, firstTangibleId);
|
deleteTangibleFromDocument(documentId, firstTangibleId);
|
||||||
|
|
||||||
const updatedDoc = useWorkspaceStore.getState().documents.get(documentId);
|
const updatedDoc = useWorkspaceStore
|
||||||
|
.getState()
|
||||||
|
.documents.get(documentId);
|
||||||
expect(updatedDoc?.tangibles).toHaveLength(1);
|
expect(updatedDoc?.tangibles).toHaveLength(1);
|
||||||
expect(updatedDoc?.tangibles?.[0].id).toBe(secondTangibleId);
|
expect(updatedDoc?.tangibles?.[0].id).toBe(secondTangibleId);
|
||||||
expect(updatedDoc?.tangibles?.[0].name).toBe('T2');
|
expect(updatedDoc?.tangibles?.[0].name).toBe("T2");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Edge Cases', () => {
|
describe("Edge Cases", () => {
|
||||||
it('should handle rapid document creation', () => {
|
it("should handle rapid document creation", () => {
|
||||||
const { createDocument } = useWorkspaceStore.getState();
|
const { createDocument } = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const ids = [];
|
const ids = [];
|
||||||
|
|
@ -774,21 +803,27 @@ describe('workspaceStore', () => {
|
||||||
expect(uniqueIds.size).toBe(10);
|
expect(uniqueIds.size).toBe(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle document operations with invalid IDs', () => {
|
it("should handle document operations with invalid IDs", () => {
|
||||||
const { renameDocument, saveDocument, deleteDocument } = useWorkspaceStore.getState();
|
const { renameDocument, saveDocument, deleteDocument } =
|
||||||
|
useWorkspaceStore.getState();
|
||||||
|
|
||||||
// Should not throw errors
|
// Should not throw errors
|
||||||
expect(() => renameDocument('invalid', 'New Name')).not.toThrow();
|
expect(() => renameDocument("invalid", "New Name")).not.toThrow();
|
||||||
expect(() => saveDocument('invalid')).not.toThrow();
|
expect(() => saveDocument("invalid")).not.toThrow();
|
||||||
expect(() => deleteDocument('invalid')).not.toThrow();
|
expect(() => deleteDocument("invalid")).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should maintain data integrity across operations', () => {
|
it("should maintain data integrity across operations", () => {
|
||||||
const { createDocument, renameDocument, duplicateDocument, deleteDocument } = useWorkspaceStore.getState();
|
const {
|
||||||
|
createDocument,
|
||||||
|
renameDocument,
|
||||||
|
duplicateDocument,
|
||||||
|
deleteDocument,
|
||||||
|
} = useWorkspaceStore.getState();
|
||||||
|
|
||||||
const doc1 = createDocument('Doc 1');
|
const doc1 = createDocument("Doc 1");
|
||||||
const doc2 = createDocument('Doc 2');
|
const doc2 = createDocument("Doc 2");
|
||||||
renameDocument(doc1, 'Renamed');
|
renameDocument(doc1, "Renamed");
|
||||||
duplicateDocument(doc1);
|
duplicateDocument(doc1);
|
||||||
deleteDocument(doc2);
|
deleteDocument(doc2);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue