test: workspace passive provider (#4446)
This commit is contained in:
@@ -17,8 +17,12 @@ const workspaceActiveAtomWeakMap = new WeakMap<
|
|||||||
// Whether the workspace is active to use
|
// Whether the workspace is active to use
|
||||||
const workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();
|
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) {
|
export function enablePassiveProviders(workspace: Workspace) {
|
||||||
const value = workspacePassiveEffectWeakMap.get(workspace);
|
const value = workspacePassiveEffectWeakMap.get(workspace);
|
||||||
|
|||||||
37
packages/infra/src/__tests__/workspace.spec.ts
Normal file
37
packages/infra/src/__tests__/workspace.spec.ts
Normal file
@@ -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);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user