mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 00:06:09 +08:00
fix: reduce useState and useEffect (#2223)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
@@ -10,7 +11,7 @@ import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
|
||||
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { describe, expect, test, vitest } from 'vitest';
|
||||
import { beforeEach } from 'vitest';
|
||||
|
||||
import { useBlockSuiteWorkspaceName } from '../use-block-suite-workspace-name';
|
||||
@@ -30,9 +31,9 @@ beforeEach(async () => {
|
||||
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
|
||||
page.addBlock('affine:paragraph', {}, frameId);
|
||||
};
|
||||
initPage(blockSuiteWorkspace.createPage('page0'));
|
||||
initPage(blockSuiteWorkspace.createPage('page1'));
|
||||
initPage(blockSuiteWorkspace.createPage('page2'));
|
||||
initPage(blockSuiteWorkspace.createPage({ id: 'page0' }));
|
||||
initPage(blockSuiteWorkspace.createPage({ id: 'page1' }));
|
||||
initPage(blockSuiteWorkspace.createPage({ id: 'page2' }));
|
||||
});
|
||||
|
||||
describe('useBlockSuiteWorkspaceName', () => {
|
||||
@@ -48,6 +49,17 @@ describe('useBlockSuiteWorkspaceName', () => {
|
||||
workspaceNameHook.result.current[1]('test 3');
|
||||
expect(blockSuiteWorkspace.meta.name).toBe('test 3');
|
||||
});
|
||||
|
||||
test('null', () => {
|
||||
const workspaceNameHook = renderHook(() =>
|
||||
useBlockSuiteWorkspaceName(null)
|
||||
);
|
||||
vitest.spyOn(globalThis.console, 'warn');
|
||||
expect(workspaceNameHook.result.current[0]).toBe(UNTITLED_WORKSPACE_NAME);
|
||||
workspaceNameHook.result.current[1]('test');
|
||||
expect(globalThis.console.warn).toHaveBeenCalledTimes(2);
|
||||
expect(workspaceNameHook.result.current[0]).toBe(UNTITLED_WORKSPACE_NAME);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useBlockSuiteWorkspacePageTitle', () => {
|
||||
|
||||
Reference in New Issue
Block a user