38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|||
|
|
|
||
|
|
import { ChildStoreManager } from './child-store';
|
||
|
|
|
||
|
|
describe('ChildStoreManager.subscribeAllSelected', () => {
|
||
|
|
test('ignores unrelated child-store updates', () => {
|
||
|
|
const manager = new ChildStoreManager();
|
||
|
|
const child = manager.ensureChild('/workspace', { bootstrap: false });
|
||
|
|
let notifications = 0;
|
||
|
|
const unsubscribe = manager.subscribeAllSelected((state) => state.session, () => {
|
||
|
|
notifications += 1;
|
||
|
|
});
|
||
|
|
|
||
|
|
child.setState({ session_status: { session: { type: 'busy' } } });
|
||
|
|
expect(notifications).toBe(0);
|
||
|
|
|
||
|
|
child.setState({ session: [...child.getState().session] });
|
||
|
|
expect(notifications).toBe(1);
|
||
|
|
|
||
|
|
unsubscribe();
|
||
|
|
manager.disposeAll();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('notifies when the child-store registry changes', () => {
|
||
|
|
const manager = new ChildStoreManager();
|
||
|
|
let notifications = 0;
|
||
|
|
const unsubscribe = manager.subscribeAllSelected((state) => state.session, () => {
|
||
|
|
notifications += 1;
|
||
|
|
});
|
||
|
|
|
||
|
|
manager.ensureChild('/workspace', { bootstrap: false });
|
||
|
|
expect(notifications).toBe(1);
|
||
|
|
|
||
|
|
unsubscribe();
|
||
|
|
manager.disposeAll();
|
||
|
|
});
|
||
|
|
});
|