There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
test: workspace passive provider (#4446)
Alex Yang98f6b3e6855c
diff --git a/packages/infra/src/__internal__/workspace.ts b/packages/infra/src/__internal__/workspace.tsindex 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 useconst workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();-// Whether the workspace has been enabled the passive effect (background)-const workspacePassiveEffectWeakMap = new WeakMap<Workspace, number>();+/**+ * Whether the workspace has been enabled the passive effect (background)+ *+ * @internal+ */+export const workspacePassiveEffectWeakMap = new WeakMap<Workspace, number>();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.tsnew file mode 100644index 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);+});