57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
|
|
/**
|
||
|
|
* documentService Tests (Task A4.11).
|
||
|
|
* Prüft Registrierung/Löschung des aktiven Dokuments und die
|
||
|
|
* Undo/Redo-Delegation an CADDocument.
|
||
|
|
*/
|
||
|
|
import { describe, it, expect, afterEach } from 'vitest';
|
||
|
|
import { setActiveDocument, getActiveDocument, undoActive, redoActive } from '../src/kernel/document/documentService';
|
||
|
|
import { CADDocument } from '../src/kernel/document/CADDocument';
|
||
|
|
import { createInMemoryDoc } from './helpers/inMemoryDoc';
|
||
|
|
import type { CADElement } from '../src/types/cad.types';
|
||
|
|
|
||
|
|
function makeEl(id: string): CADElement {
|
||
|
|
return {
|
||
|
|
id,
|
||
|
|
type: 'rect',
|
||
|
|
layerId: 'l',
|
||
|
|
x: 0,
|
||
|
|
y: 0,
|
||
|
|
width: 1,
|
||
|
|
height: 1,
|
||
|
|
properties: {},
|
||
|
|
} as unknown as CADElement;
|
||
|
|
}
|
||
|
|
|
||
|
|
afterEach(() => {
|
||
|
|
setActiveDocument(null);
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('documentService', () => {
|
||
|
|
it('registriert und entregistriert das aktive Dokument', () => {
|
||
|
|
const { ydoc } = createInMemoryDoc();
|
||
|
|
const doc = new CADDocument(ydoc);
|
||
|
|
setActiveDocument(doc);
|
||
|
|
expect(getActiveDocument()).toBe(doc);
|
||
|
|
setActiveDocument(null);
|
||
|
|
expect(getActiveDocument()).toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('undoActive delegiert an das registrierte Dokument', () => {
|
||
|
|
const { ydoc } = createInMemoryDoc();
|
||
|
|
const doc = new CADDocument(ydoc);
|
||
|
|
doc.addElement(makeEl('x1'));
|
||
|
|
setActiveDocument(doc);
|
||
|
|
|
||
|
|
expect(undoActive()).toBe(true); // Element wird entfernt
|
||
|
|
expect(doc.getAllElements().length).toBe(0);
|
||
|
|
expect(redoActive()).toBe(true); // wiederhergestellt
|
||
|
|
expect(doc.getAllElements().length).toBe(1);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('undoActive liefert false ohne aktives Dokument', () => {
|
||
|
|
setActiveDocument(null);
|
||
|
|
expect(undoActive()).toBe(false);
|
||
|
|
expect(redoActive()).toBe(false);
|
||
|
|
});
|
||
|
|
});
|