test: workspace passive provider (#4446)

This commit is contained in:
Alex Yang
2023-09-21 10:50:14 -05:00
committed by GitHub
parent d5f4fbcdb5
commit 98f6b3e685
2 changed files with 43 additions and 2 deletions
+6 -2
View File
@@ -17,8 +17,12 @@ const workspaceActiveAtomWeakMap = new WeakMap<
// Whether the workspace is active to use
const 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);
@@ -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);
});