perMessageOpenContext.test.tsx1.7 KBView on GitHub import { DEFAULT_THREAD_ID } from '@/store/messages/MessageTypes';
import { useCedarStore } from '@/store/CedarStore';
describe('per-message openContext', () => {
beforeEach(() => {
useCedarStore.setState((state) => ({
...state,
threadMap: {
[DEFAULT_THREAD_ID]: { id: DEFAULT_THREAD_ID, lastLoaded: new Date().toISOString(), messages: [] },
},
mainThreadId: DEFAULT_THREAD_ID,
activeThreadId: DEFAULT_THREAD_ID,
messages: [],
}));
});
it('addMessage preserves openContext on the stored message', () => {
useCedarStore.getState().addMessage(
{
id: 'm1',
role: 'user',
type: 'text',
content: 'hi',
openContext: { kind: 'conversation', id: 'c1' },
},
true,
DEFAULT_THREAD_ID,
);
const msg = useCedarStore.getState().threadMap[DEFAULT_THREAD_ID].messages.at(-1);
expect(msg?.openContext).toEqual({ kind: 'conversation', id: 'c1' });
});
it('setSelectedArtifact drives the ACTIVE thread\'s per-thread artifact selection', () => {
useCedarStore.getState().setSelectedArtifact({ kind: 'file', id: 'd1' });
expect(useCedarStore.getState().threadMap[DEFAULT_THREAD_ID].selectedArtifact).toEqual({
kind: 'file',
id: 'd1',
});
expect(useCedarStore.getState().getDisplayArtifact()).toEqual({ kind: 'file', id: 'd1' });
useCedarStore.getState().setSelectedArtifact(null);
expect(useCedarStore.getState().threadMap[DEFAULT_THREAD_ID].selectedArtifact).toBeNull();
// No artifact open → the display artifact resolves to the calendar-agenda default.
expect(useCedarStore.getState().getDisplayArtifact()).toBeNull();
});
});