refactor(editor): remove assertExists (#10615)

This commit is contained in:
Saul-Mirone
2025-03-05 00:13:08 +00:00
parent a6692f70aa
commit b8ecfbdae6
106 changed files with 863 additions and 517 deletions

View File

@@ -2,7 +2,7 @@ import '../declare-test-window.js';
import type { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
import type { IPoint, IVec } from '@blocksuite/global/gfx';
import { assertExists, sleep } from '@blocksuite/global/utils';
import { sleep } from '@blocksuite/global/utils';
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
@@ -253,8 +253,7 @@ export async function locatorEdgelessZoomToolButton(
fitToScreen: 'Fit to screen',
}[type];
const screenWidth = page.viewportSize()?.width;
assertExists(screenWidth);
const screenWidth = page.viewportSize()?.width ?? 0;
let zoomBarClass = 'horizontal';
if (screenWidth < ZOOM_BAR_RESPONSIVE_SCREEN_WIDTH) {
await toggleZoomBarWhenSmallScreenWidth(page);
@@ -958,8 +957,7 @@ export async function zoomInByKeyboard(page: Page) {
}
export async function getZoomLevel(page: Page) {
const screenWidth = page.viewportSize()?.width;
assertExists(screenWidth);
const screenWidth = page.viewportSize()?.width ?? 0;
let zoomBarClass = 'horizontal';
if (screenWidth < ZOOM_BAR_RESPONSIVE_SCREEN_WIDTH) {
await toggleZoomBarWhenSmallScreenWidth(page);
@@ -1456,7 +1454,9 @@ export function getEdgelessLineWidthPanel(page: Page) {
export async function changeShapeStrokeWidth(page: Page) {
const lineWidthPanel = getEdgelessLineWidthPanel(page);
const lineWidthPanelRect = await lineWidthPanel.boundingBox();
assertExists(lineWidthPanelRect);
if (!lineWidthPanelRect) {
throw new Error('lineWidthPanelRect is not found');
}
// click line width panel by position
const x = lineWidthPanelRect.x + 40;
const y = lineWidthPanelRect.y + 10;
@@ -1907,7 +1907,9 @@ export async function createNote(
export async function hoverOnNote(page: Page, id: string, offset = [0, 0]) {
const blockRect = await page.locator(`[data-block-id="${id}"]`).boundingBox();
assertExists(blockRect);
if (!blockRect) {
throw new Error('blockRect is not found');
}
await page.mouse.move(
blockRect.x + blockRect.width / 2 + offset[0],

View File

@@ -5,7 +5,6 @@ import type {
ListType,
RichText,
} from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import type { InlineRange, InlineRootElement } from '@blocksuite/inline';
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
import type { BlockModel } from '@blocksuite/store';
@@ -42,7 +41,9 @@ export const getSelectionRect = async (page: Page): Promise<DOMRect> => {
const rect = await page.evaluate(() => {
return getSelection()?.getRangeAt(0).getBoundingClientRect();
});
assertExists(rect);
if (!rect) {
throw new Error('rect is not found');
}
return rect;
};
@@ -864,7 +865,9 @@ export async function getClipboardSnapshot(page: Page) {
page,
'BLOCKSUITE/SNAPSHOT'
);
assertExists(dataInClipboard);
if (!dataInClipboard) {
throw new Error('dataInClipboard is not found');
}
const json = JSON.parse(dataInClipboard as string);
return json;
}