mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
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
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user