diff --git a/packages/infra/src/__internal__/workspace.ts b/packages/infra/src/__internal__/workspace.ts index 5a8d3f9198..865d2446e1 100644 --- a/packages/infra/src/__internal__/workspace.ts +++ b/packages/infra/src/__internal__/workspace.ts @@ -17,8 +17,12 @@ const workspaceActiveAtomWeakMap = new WeakMap< // Whether the workspace is active to use const workspaceActiveWeakMap = new WeakMap(); -// Whether the workspace has been enabled the passive effect (background) -const workspacePassiveEffectWeakMap = new WeakMap(); +/** + * Whether the workspace has been enabled the passive effect (background) + * + * @internal + */ +export const workspacePassiveEffectWeakMap = new WeakMap(); export function enablePassiveProviders(workspace: Workspace) { const value = workspacePassiveEffectWeakMap.get(workspace); diff --git a/packages/infra/src/__tests__/workspace.spec.ts b/packages/infra/src/__tests__/workspace.spec.ts new file mode 100644 index 0000000000..f0a52c6595 --- /dev/null +++ b/packages/infra/src/__tests__/workspace.spec.ts @@ -0,0 +1,37 @@ +import { AffineSchemas } from '@blocksuite/blocks/models'; +import { Schema, Workspace } from '@blocksuite/store'; +import { expect, test } from 'vitest'; + +import { + disablePassiveProviders, + enablePassiveProviders, + getWorkspace, + INTERNAL_BLOCKSUITE_HASH_MAP, + workspacePassiveEffectWeakMap, +} from '../__internal__/workspace'; + +const schema = new Schema(); + +schema.register(AffineSchemas); + +const createWorkspace = (id: string) => { + return new Workspace({ + id, + schema, + }); +}; + +test('workspace passive provider should enable correctly', () => { + INTERNAL_BLOCKSUITE_HASH_MAP.set('1', createWorkspace('1')); + INTERNAL_BLOCKSUITE_HASH_MAP.set('2', createWorkspace('2')); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('1'))).toBe(undefined); + enablePassiveProviders(getWorkspace('1')); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('1'))).toBe(1); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('2'))).toBe(undefined); + enablePassiveProviders(getWorkspace('1')); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('1'))).toBe(2); + disablePassiveProviders(getWorkspace('1')); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('1'))).toBe(1); + disablePassiveProviders(getWorkspace('1')); + expect(workspacePassiveEffectWeakMap.get(getWorkspace('1'))).toBe(undefined); +});