test(editor): getFirstContentBlock & getLastContentBlock & isNothingSelected command (#10757)

### TL;DR

Added unit tests for block and selection commands, along with a new test helper system for creating test documents.

### What changed?

- Added unit tests for several commands:
  - `getFirstContentBlockCommand`
  - `getLastContentBlockCommand`
  - `isNothingSelectedCommand`
- Created a new test helpers make it easier to create structured test documents with a html-like syntax:

```typescript
import { describe, expect, it } from 'vitest';
import { affine } from '../__tests__/utils/affine-template';
describe('My Test', () => {
  it('should correctly handle document structure', () => {
    const doc = affine`
      <affine-page>
        <affine-note>
          <affine-paragraph>Test content</affine-paragraph>
        </affine-note>
      </affine-page>
    `;
    // Get blocks
    const pages = doc.getBlocksByFlavour('affine:page');
    const notes = doc.getBlocksByFlavour('affine:note');
    const paragraphs = doc.getBlocksByFlavour('affine:paragraph');
    expect(pages.length).toBe(1);
    expect(notes.length).toBe(1);
    expect(paragraphs.length).toBe(1);
    // Perform more tests here...
  });
});
```
This commit is contained in:
yoyoyohamapi
2025-03-14 02:35:21 +00:00
parent 04efca362e
commit d3aae962bc
9 changed files with 1040 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
export {
getBlockIndexCommand,
getFirstContentBlockCommand,
getLastContentBlockCommand,
getNextBlockCommand,
getPrevBlockCommand,
getSelectedBlocksCommand,
@@ -21,5 +23,6 @@ export {
getRangeRects,
getSelectionRectsCommand,
getTextSelectionCommand,
isNothingSelectedCommand,
type SelectionRect,
} from './selection/index.js';