Update tests for new activeStateTangibles tracking

Changes:
- Replace lastStateChangeSource with activeStateTangibles in tests
- Update tuioStore.test.ts to test array-based tracking
- Add tests for adding/removing multiple state tangibles
- Add test for duplicate prevention
- Update TUIO integration tests to use new API
- Pass fromTangible=true parameter to switchToState in tests

All 447 tests now passing.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik Bruhn 2026-01-19 11:50:48 +01:00
parent 68ca121b19
commit 010d8a558c
2 changed files with 43 additions and 28 deletions

View file

@ -308,14 +308,14 @@ describe('TUIO Integration', () => {
const config = useGraphStore.getState().tangibles.find((t) => t.hardwareId === '99');
if (config?.stateId) {
useTimelineStore.getState().switchToState(config.stateId);
useTuioStore.getState().setLastStateChangeSource('99');
useTuioStore.getState().addActiveStateTangible('99');
useTimelineStore.getState().switchToState(config.stateId, true);
}
// Verify state was switched
const currentStateId = useTimelineStore.getState().timelines.get(docId)?.currentStateId;
expect(currentStateId).toBe(stateId);
expect(useTuioStore.getState().lastStateChangeSource).toBe('99');
expect(useTuioStore.getState().activeStateTangibles).toContain('99');
});
it('should not revert state when state tangible is removed', () => {
@ -333,11 +333,12 @@ describe('TUIO Integration', () => {
} as TangibleConfig);
// Switch to new state
useTimelineStore.getState().switchToState(newStateId);
useTuioStore.getState().setLastStateChangeSource('100');
useTuioStore.getState().addActiveStateTangible('100');
useTimelineStore.getState().switchToState(newStateId, true);
// Remove tangible
useTuioStore.getState().removeActiveTangible('100');
useTuioStore.getState().removeActiveStateTangible('100');
// State should NOT revert
const currentStateId = useTimelineStore.getState().timelines.get(docId)?.currentStateId;

View file

@ -13,7 +13,7 @@ describe('tuioStore', () => {
isConnected: false,
connectionError: null,
activeTangibles: new Map(),
lastStateChangeSource: null,
activeStateTangibles: [],
});
});
@ -25,7 +25,7 @@ describe('tuioStore', () => {
expect(state.isConnected).toBe(false);
expect(state.connectionError).toBe(null);
expect(state.activeTangibles.size).toBe(0);
expect(state.lastStateChangeSource).toBe(null);
expect(state.activeStateTangibles).toEqual([]);
});
});
@ -365,15 +365,15 @@ describe('tuioStore', () => {
expect(state.activeTangibles.size).toBe(0);
});
it('should reset lastStateChangeSource', () => {
const { setLastStateChangeSource, clearActiveTangibles } = useTuioStore.getState();
it('should reset activeStateTangibles', () => {
const { addActiveStateTangible, clearActiveTangibles } = useTuioStore.getState();
setLastStateChangeSource('42');
expect(useTuioStore.getState().lastStateChangeSource).toBe('42');
addActiveStateTangible('42');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42']);
clearActiveTangibles();
expect(useTuioStore.getState().lastStateChangeSource).toBe(null);
expect(useTuioStore.getState().activeStateTangibles).toEqual([]);
});
it('should handle clearing empty tangibles map', () => {
@ -386,32 +386,46 @@ describe('tuioStore', () => {
});
});
describe('setLastStateChangeSource', () => {
it('should set last state change source', () => {
const { setLastStateChangeSource } = useTuioStore.getState();
describe('activeStateTangibles', () => {
it('should add active state tangible', () => {
const { addActiveStateTangible } = useTuioStore.getState();
setLastStateChangeSource('42');
addActiveStateTangible('42');
expect(useTuioStore.getState().lastStateChangeSource).toBe('42');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42']);
});
it('should clear last state change source', () => {
const { setLastStateChangeSource } = useTuioStore.getState();
it('should remove active state tangible', () => {
const { addActiveStateTangible, removeActiveStateTangible } = useTuioStore.getState();
setLastStateChangeSource('42');
setLastStateChangeSource(null);
addActiveStateTangible('42');
addActiveStateTangible('13');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42', '13']);
expect(useTuioStore.getState().lastStateChangeSource).toBe(null);
removeActiveStateTangible('42');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['13']);
});
it('should update last state change source', () => {
const { setLastStateChangeSource } = useTuioStore.getState();
it('should track multiple state tangibles in order', () => {
const { addActiveStateTangible } = useTuioStore.getState();
setLastStateChangeSource('42');
expect(useTuioStore.getState().lastStateChangeSource).toBe('42');
addActiveStateTangible('42');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42']);
setLastStateChangeSource('13');
expect(useTuioStore.getState().lastStateChangeSource).toBe('13');
addActiveStateTangible('13');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42', '13']);
addActiveStateTangible('99');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42', '13', '99']);
});
it('should not add duplicate tangibles', () => {
const { addActiveStateTangible } = useTuioStore.getState();
addActiveStateTangible('42');
addActiveStateTangible('42');
expect(useTuioStore.getState().activeStateTangibles).toEqual(['42']);
});
});