diff --git a/src/__tests__/integration/tuio-integration.test.tsx b/src/__tests__/integration/tuio-integration.test.tsx index 39a940f..c733652 100644 --- a/src/__tests__/integration/tuio-integration.test.tsx +++ b/src/__tests__/integration/tuio-integration.test.tsx @@ -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; diff --git a/src/stores/tuioStore.test.ts b/src/stores/tuioStore.test.ts index 990fff5..26e947b 100644 --- a/src/stores/tuioStore.test.ts +++ b/src/stores/tuioStore.test.ts @@ -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']); }); });