Files
AFFiNE-Mirror/tests/blocksuite/e2e/database/statistics.spec.ts
zzj3720 0f1a3c212d refactor(editor): add a layer of ui-logic to enhance type safety (#12511)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced modular UI logic layers for Kanban and Table views, enhancing maintainability and scalability.
  - Added new CSS-in-JS style modules for database blocks and table views, improving visual consistency.
  - Expanded telemetry event tracking for database views, properties, filters, and groups.
  - Added utility functions for lazy initialization and cached computed values.

- **Refactor**
  - Unified logic and state management across Kanban and Table views by replacing direct component dependencies with logic-centric architecture.
  - Updated components and widgets to use the new logic-based approach for state, selection, and event handling.
  - Replaced inline styles with CSS classes; updated class names to align with new component structure.
  - Centralized state access through UI logic instances, eliminating direct DOM queries and simplifying dependencies.
  - Consolidated Kanban and Table view presets effects for streamlined initialization.
  - Replaced Lit reactive state with Preact signals in multiple components for improved reactivity.
  - Split monolithic components into separate logic and UI classes for clearer separation of concerns.
  - Removed obsolete components and consolidated exports for cleaner API surface.

- **Bug Fixes**
  - Enhanced selection and interaction reliability in database cells and views.
  - Fixed scrolling issues on mobile table views for improved compatibility.

- **Chores**
  - Updated end-to-end test selectors to reflect new component names and structure.
  - Removed deprecated utilities and cleaned up unused imports.

- **Documentation**
  - Improved type definitions and public API exports for better developer experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-27 09:36:44 +00:00

108 lines
3.6 KiB
TypeScript

import { expect, type Page } from '@playwright/test';
import { type } from '../utils/actions/index.js';
import {
enterPlaygroundRoom,
getAddRow,
initEmptyDatabaseState,
waitNextFrame,
} from '../utils/actions/misc.js';
import { test } from '../utils/playwright.js';
import {
changeColumnType,
moveToCenterOf,
press,
pressKey,
} from './actions.js';
const addRow = async (page: Page, count: number = 1) => {
await waitNextFrame(page);
const addRow = getAddRow(page);
for (let i = 0; i < count; i++) {
await addRow.click();
}
await press(page, 'Escape');
await waitNextFrame(page);
};
const insertRightColumn = async (page: Page, index = 0) => {
await waitNextFrame(page);
await page.locator('affine-database-header-column').nth(index).click();
await waitNextFrame(page, 200);
await pressKey(page, 'Escape');
const menu = page.locator('.affine-menu-button', {
hasText: new RegExp('Insert Right'),
});
await menu.click();
await waitNextFrame(page, 200);
await pressKey(page, 'Enter');
};
const menuSelect = async (page: Page, selectors: string[]) => {
await waitNextFrame(page);
for (const name of selectors) {
const menu = page.locator('.affine-menu-button', {
hasText: new RegExp(name),
});
await menu.click();
}
};
test.describe('title', () => {
test('empty count', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyDatabaseState(page);
await addRow(page, 3);
const statCell = page.locator('affine-database-column-stats-cell').nth(0);
await moveToCenterOf(page, statCell);
await statCell.click();
await menuSelect(page, ['Count', 'Count Empty']);
const value = statCell.locator('.value');
expect((await value.textContent())?.trim()).toBe('3');
await page.locator('dv-table-view-cell-container').nth(0).click();
await pressKey(page, 'Enter');
await type(page, 'asd');
await pressKey(page, 'Escape');
expect((await value.textContent())?.trim()).toBe('2');
});
});
test.describe('rich-text', () => {
test('empty count', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyDatabaseState(page);
await addRow(page, 3);
await insertRightColumn(page);
await changeColumnType(page, 1, 'text');
const statCell = page.locator('affine-database-column-stats-cell').nth(1);
await moveToCenterOf(page, statCell);
await statCell.click();
await menuSelect(page, ['Count', 'Count Empty']);
const value = statCell.locator('.value');
expect((await value.textContent())?.trim()).toBe('3');
await page.locator('dv-table-view-cell-container').nth(1).click();
await pressKey(page, 'Enter');
await type(page, 'asd');
await pressKey(page, 'Escape');
expect((await value.textContent())?.trim()).toBe('2');
});
});
test.describe('select', () => {
test('empty count', async ({ page }) => {
await enterPlaygroundRoom(page);
await initEmptyDatabaseState(page);
await addRow(page, 3);
await insertRightColumn(page);
await changeColumnType(page, 1, 'select');
const statCell = page.locator('affine-database-column-stats-cell').nth(1);
await moveToCenterOf(page, statCell);
await statCell.click();
await menuSelect(page, ['Count', 'Count Empty']);
const value = statCell.locator('.value');
expect((await value.textContent())?.trim()).toBe('3');
await page.locator('dv-table-view-cell-container').nth(1).click();
await pressKey(page, 'Enter');
await type(page, 'select');
await pressKey(page, 'Enter');
expect((await value.textContent())?.trim()).toBe('2');
});
});