mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 05:58:56 +08:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -36,7 +36,6 @@ import {
|
||||
assertBlockCount,
|
||||
assertBlockFlavour,
|
||||
assertBlockSelections,
|
||||
assertExists,
|
||||
assertParentBlockFlavour,
|
||||
assertRichTextInlineRange,
|
||||
} from './utils/asserts.js';
|
||||
@@ -261,7 +260,9 @@ test.describe('embed card toolbar', () => {
|
||||
await cardStyleListButton.click();
|
||||
await waitNextFrame(page);
|
||||
const listStyleBookmarkBox = await bookmark.boundingBox();
|
||||
assertExists(listStyleBookmarkBox);
|
||||
if (!listStyleBookmarkBox) {
|
||||
throw new Error('listStyleBookmarkBox is not found');
|
||||
}
|
||||
assertAlmostEqual(listStyleBookmarkBox.width, 752, 2);
|
||||
assertAlmostEqual(listStyleBookmarkBox.height, 48, 2);
|
||||
|
||||
@@ -269,7 +270,9 @@ test.describe('embed card toolbar', () => {
|
||||
await cardStyleHorizontalButton.click();
|
||||
await waitNextFrame(page);
|
||||
const horizontalStyleBookmarkBox = await bookmark.boundingBox();
|
||||
assertExists(horizontalStyleBookmarkBox);
|
||||
if (!horizontalStyleBookmarkBox) {
|
||||
throw new Error('horizontalStyleBookmarkBox is not found');
|
||||
}
|
||||
assertAlmostEqual(horizontalStyleBookmarkBox.width, 752, 2);
|
||||
assertAlmostEqual(horizontalStyleBookmarkBox.height, 116, 2);
|
||||
});
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
import {
|
||||
assertBlockTypes,
|
||||
assertClipItems,
|
||||
assertExists,
|
||||
assertRichTexts,
|
||||
assertText,
|
||||
assertTitle,
|
||||
@@ -127,8 +126,12 @@ test(scoped`split block when paste`, async ({ page }) => {
|
||||
const bottomRight789 = await getEditorLocator(page)
|
||||
.locator('[data-block-id="4"] .inline-editor')
|
||||
.boundingBox();
|
||||
assertExists(topLeft123);
|
||||
assertExists(bottomRight789);
|
||||
if (!topLeft123) {
|
||||
throw new Error('topLeft123 is not found');
|
||||
}
|
||||
if (!bottomRight789) {
|
||||
throw new Error('bottomRight789 is not found');
|
||||
}
|
||||
await dragBetweenCoords(page, topLeft123, bottomRight789);
|
||||
|
||||
// FIXME see https://github.com/toeverything/blocksuite/pull/878
|
||||
|
||||
@@ -51,7 +51,6 @@ import {
|
||||
assertBlockTypes,
|
||||
assertEdgelessNoteBackground,
|
||||
assertEdgelessSelectedModelRect,
|
||||
assertExists,
|
||||
assertRichTextModelType,
|
||||
assertRichTexts,
|
||||
assertText,
|
||||
@@ -111,7 +110,9 @@ test('copy a nested list by clicking button, the clipboard data should be comple
|
||||
await pasteContent(page, clipData);
|
||||
|
||||
const rootListBound = await page.locator('affine-list').first().boundingBox();
|
||||
assertExists(rootListBound);
|
||||
if (!rootListBound) {
|
||||
throw new Error('rootListBound is not found');
|
||||
}
|
||||
|
||||
// use drag element to test.
|
||||
await dragBetweenCoords(
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
assertConnectorStrokeColor,
|
||||
assertEdgelessCanvasText,
|
||||
assertEdgelessNoteBackground,
|
||||
assertExists,
|
||||
assertRichTexts,
|
||||
assertSelectedBound,
|
||||
} from '../utils/asserts.js';
|
||||
@@ -159,7 +158,9 @@ test.describe('auto-complete', () => {
|
||||
const note = document.body.querySelector('affine-edgeless-note');
|
||||
return note?.getAttribute('data-block-id');
|
||||
});
|
||||
assertExists(noteId);
|
||||
if (!noteId) {
|
||||
throw new Error('noteId is not found');
|
||||
}
|
||||
await assertEdgelessNoteBackground(
|
||||
page,
|
||||
noteId,
|
||||
@@ -167,7 +168,9 @@ test.describe('auto-complete', () => {
|
||||
);
|
||||
|
||||
const rect = await edgelessNote.boundingBox();
|
||||
assertExists(rect);
|
||||
if (!rect) {
|
||||
throw new Error('rect is not found');
|
||||
}
|
||||
|
||||
// blur note block
|
||||
await page.mouse.click(rect.x + rect.width / 2, rect.y + rect.height * 3);
|
||||
@@ -220,7 +223,9 @@ test.describe('auto-complete', () => {
|
||||
const note = document.body.querySelectorAll('affine-edgeless-note')[1];
|
||||
return note?.getAttribute('data-block-id');
|
||||
});
|
||||
assertExists(noteId2);
|
||||
if (!noteId2) {
|
||||
throw new Error('noteId2 is not found');
|
||||
}
|
||||
await assertEdgelessNoteBackground(
|
||||
page,
|
||||
noteId,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { expect, type Page } from '@playwright/test';
|
||||
|
||||
import {
|
||||
@@ -142,7 +141,9 @@ test.describe('auto-connect', () => {
|
||||
const noteBound = await getNoteBoundBoxInEdgeless(page, id2);
|
||||
const edgelessOnlyIndexLabelBound =
|
||||
await edgelessOnlyIndexLabel.boundingBox();
|
||||
assertExists(edgelessOnlyIndexLabelBound);
|
||||
if (!edgelessOnlyIndexLabelBound) {
|
||||
throw new Error('edgelessOnlyIndexLabelBound is not found');
|
||||
}
|
||||
const border = 1;
|
||||
const offset = 16;
|
||||
expect(edgelessOnlyIndexLabelBound.x).toBeCloseTo(
|
||||
@@ -166,7 +167,9 @@ test.describe('auto-connect', () => {
|
||||
const newNoteBound = await getNoteBoundBoxInEdgeless(page, id2);
|
||||
const newEdgelessOnlyIndexLabelBound =
|
||||
await edgelessOnlyIndexLabel.boundingBox();
|
||||
assertExists(newEdgelessOnlyIndexLabelBound);
|
||||
if (!newEdgelessOnlyIndexLabelBound) {
|
||||
throw new Error('newEdgelessOnlyIndexLabelBound is not found');
|
||||
}
|
||||
expect(newEdgelessOnlyIndexLabelBound.x).toBeCloseTo(
|
||||
newNoteBound.x +
|
||||
newNoteBound.width / 2 -
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import {
|
||||
@@ -323,7 +322,9 @@ test('the tooltip of more button should be hidden when the action menu is shown'
|
||||
const moreButtonBox = await moreButton.boundingBox();
|
||||
const tooltip = page.locator('.affine-tooltip');
|
||||
|
||||
assertExists(moreButtonBox);
|
||||
if (!moreButtonBox) {
|
||||
throw new Error('moreButtonBox is not found');
|
||||
}
|
||||
|
||||
// need to wait for previous tooltip to be hidden
|
||||
await page.waitForTimeout(100);
|
||||
@@ -383,8 +384,7 @@ test('should close zoom bar when click blank area', async ({ page }) => {
|
||||
await initEmptyEdgelessState(page);
|
||||
await switchEditorMode(page);
|
||||
|
||||
const screenWidth = page.viewportSize()?.width;
|
||||
assertExists(screenWidth);
|
||||
const screenWidth = page.viewportSize()?.width ?? 0;
|
||||
if (screenWidth > ZOOM_BAR_RESPONSIVE_SCREEN_WIDTH) {
|
||||
await page.setViewportSize({
|
||||
width: 1000,
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
assertConnectorPath,
|
||||
assertEdgelessNonSelectedRect,
|
||||
assertEdgelessSelectedRect,
|
||||
assertExists,
|
||||
} from '../../utils/asserts.js';
|
||||
import { test } from '../../utils/playwright.js';
|
||||
|
||||
@@ -223,7 +222,9 @@ test.describe('quick connect', () => {
|
||||
});
|
||||
|
||||
const bounds = await quickConnectBtn.boundingBox();
|
||||
assertExists(bounds);
|
||||
if (!bounds) {
|
||||
throw new Error('bounds is not found');
|
||||
}
|
||||
|
||||
await quickConnectBtn.click();
|
||||
|
||||
@@ -290,7 +291,9 @@ test.describe('quick connect', () => {
|
||||
name: 'Draw connector',
|
||||
});
|
||||
const bounds = await quickConnectBtn.boundingBox();
|
||||
assertExists(bounds);
|
||||
if (!bounds) {
|
||||
throw new Error('bounds is not found');
|
||||
}
|
||||
await quickConnectBtn.click();
|
||||
|
||||
// at right
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { expect, type Page } from '@playwright/test';
|
||||
|
||||
import {
|
||||
@@ -28,7 +27,9 @@ test.describe('connector label with straight shape', () => {
|
||||
const bounds = await page
|
||||
.locator('edgeless-connector-label-editor rich-text')
|
||||
.boundingBox();
|
||||
assertExists(bounds);
|
||||
if (!bounds) {
|
||||
throw new Error('bounds is not found');
|
||||
}
|
||||
const cx = bounds.x + bounds.width / 2;
|
||||
const cy = bounds.y + bounds.height / 2;
|
||||
return [cx, cy];
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
type,
|
||||
waitNextFrame,
|
||||
} from '../utils/actions/index.js';
|
||||
import { assertConnectorPath, assertExists } from '../utils/asserts.js';
|
||||
import { assertConnectorPath } from '../utils/asserts.js';
|
||||
import { test } from '../utils/playwright.js';
|
||||
|
||||
test.describe('note to linked doc', () => {
|
||||
@@ -39,12 +39,16 @@ test.describe('note to linked doc', () => {
|
||||
|
||||
await waitNextFrame(page, 200);
|
||||
const embedSyncedBlock = page.locator('affine-embed-synced-doc-block');
|
||||
assertExists(embedSyncedBlock);
|
||||
if (!embedSyncedBlock) {
|
||||
throw new Error('embedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const noteBlock = page.locator('affine-edgeless-note');
|
||||
assertExists(noteBlock);
|
||||
if (!noteBlock) {
|
||||
throw new Error('noteBlock is not found');
|
||||
}
|
||||
const noteContent = await noteBlock.innerText();
|
||||
expect(noteContent).toBe('Hello\nWorld');
|
||||
});
|
||||
@@ -62,7 +66,9 @@ test.describe('note to linked doc', () => {
|
||||
|
||||
await waitNextFrame(page, 200);
|
||||
const embedSyncedBlock = page.locator('affine-embed-synced-doc-block');
|
||||
assertExists(embedSyncedBlock);
|
||||
if (!embedSyncedBlock) {
|
||||
throw new Error('embedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await assertConnectorPath(page, [connectorPath[0], connectorPath[1]], 0);
|
||||
});
|
||||
@@ -117,7 +123,9 @@ test.describe('single edgeless element to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -140,7 +148,9 @@ test.describe('single edgeless element to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -157,7 +167,9 @@ test.describe('single edgeless element to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -185,7 +197,9 @@ test.describe('single edgeless element to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -222,7 +236,9 @@ test.describe('single edgeless element to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -269,7 +285,9 @@ test.describe('multiple edgeless elements to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -305,7 +323,9 @@ test.describe('multiple edgeless elements to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
@@ -334,7 +354,9 @@ test.describe('multiple edgeless elements to linked doc', () => {
|
||||
await triggerComponentToolbarAction(page, 'createLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
const linkedSyncedBlock = page.locator('affine-linked-synced-doc-block');
|
||||
assertExists(linkedSyncedBlock);
|
||||
if (!linkedSyncedBlock) {
|
||||
throw new Error('linkedSyncedBlock is not found');
|
||||
}
|
||||
|
||||
await triggerComponentToolbarAction(page, 'openLinkedDoc');
|
||||
await waitNextFrame(page, 200);
|
||||
|
||||
@@ -42,7 +42,6 @@ import {
|
||||
assertEdgelessNonSelectedRect,
|
||||
assertEdgelessNoteBackground,
|
||||
assertEdgelessSelectedRect,
|
||||
assertExists,
|
||||
assertNoteSequence,
|
||||
assertNoteXYWH,
|
||||
assertRichTextInlineRange,
|
||||
@@ -386,7 +385,9 @@ test.fixme(
|
||||
const paragraphBlock = await page
|
||||
.locator(`[data-block-id="3"]`)
|
||||
.boundingBox();
|
||||
assertExists(paragraphBlock);
|
||||
if (!paragraphBlock) {
|
||||
throw new Error('paragraphBlock is not found');
|
||||
}
|
||||
await page.mouse.dblclick(paragraphBlock.x, paragraphBlock.y);
|
||||
await waitNextFrame(page);
|
||||
await page.mouse.move(
|
||||
@@ -397,7 +398,9 @@ test.fixme(
|
||||
const handle = await page
|
||||
.locator('.affine-drag-handle-container')
|
||||
.boundingBox();
|
||||
assertExists(handle);
|
||||
if (!handle) {
|
||||
throw new Error('handle is not found');
|
||||
}
|
||||
await page.mouse.move(
|
||||
handle.x + handle.width / 2,
|
||||
handle.y + handle.height / 2,
|
||||
@@ -414,7 +417,9 @@ test.fixme(
|
||||
|
||||
// Click at empty note block to add a paragraph block
|
||||
const emptyNote = await page.locator(`[data-block-id="2"]`).boundingBox();
|
||||
assertExists(emptyNote);
|
||||
if (!emptyNote) {
|
||||
throw new Error('emptyNote is not found');
|
||||
}
|
||||
await page.mouse.click(
|
||||
emptyNote.x + emptyNote.width / 2,
|
||||
emptyNote.y + emptyNote.height / 2
|
||||
@@ -445,7 +450,9 @@ test('Should focus at closest text block when note collapse', async ({
|
||||
const notePortalBox = await page
|
||||
.locator('affine-edgeless-note')
|
||||
.boundingBox();
|
||||
assertExists(notePortalBox);
|
||||
if (!notePortalBox) {
|
||||
throw new Error('notePortalBox is not found');
|
||||
}
|
||||
await page.mouse.click(notePortalBox.x + 10, notePortalBox.y + 10);
|
||||
await waitNextFrame(page, 200);
|
||||
const selectedRect = page
|
||||
@@ -455,7 +462,9 @@ test('Should focus at closest text block when note collapse', async ({
|
||||
|
||||
// Collapse the note
|
||||
const selectedBox = await selectedRect.boundingBox();
|
||||
assertExists(selectedBox);
|
||||
if (!selectedBox) {
|
||||
throw new Error('selectedBox is not found');
|
||||
}
|
||||
await page.mouse.move(
|
||||
selectedBox.x + selectedBox.width / 2,
|
||||
selectedBox.y + selectedBox.height
|
||||
|
||||
@@ -40,7 +40,6 @@ import {
|
||||
assertEdgelessColorSameWithHexColor,
|
||||
assertEdgelessNonSelectedRect,
|
||||
assertEdgelessSelectedRect,
|
||||
assertExists,
|
||||
assertRichTexts,
|
||||
} from '../utils/asserts.js';
|
||||
import { test } from '../utils/playwright.js';
|
||||
@@ -218,7 +217,9 @@ test('the tooltip of shape tool button should be hidden when the shape menu is s
|
||||
const shapeToolBox = await shapeTool.boundingBox();
|
||||
const tooltip = page.locator('.affine-tooltip');
|
||||
|
||||
assertExists(shapeToolBox);
|
||||
if (!shapeToolBox) {
|
||||
throw new Error('shapeToolBox is not found');
|
||||
}
|
||||
|
||||
await page.mouse.move(shapeToolBox.x + 2, shapeToolBox.y + 2);
|
||||
await expect(tooltip).toBeVisible();
|
||||
@@ -275,7 +276,9 @@ test('edgeless toolbar shape menu shows up and close normally', async ({
|
||||
const shapeTool = await locatorEdgelessToolButton(page, 'shape');
|
||||
const shapeToolBox = await shapeTool.boundingBox();
|
||||
|
||||
assertExists(shapeToolBox);
|
||||
if (!shapeToolBox) {
|
||||
throw new Error('shapeToolBox is not found');
|
||||
}
|
||||
|
||||
await page.mouse.click(shapeToolBox.x + 2, shapeToolBox.y + 2);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { DatabaseBlockModel } from '@blocksuite/affine-model';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { expect, type Page } from '@playwright/test';
|
||||
|
||||
import { switchEditorMode } from './utils/actions/edgeless.js';
|
||||
@@ -22,7 +21,9 @@ test.describe('Embed synced doc', () => {
|
||||
const { createLinkedDoc } = getLinkedDocPopover(page);
|
||||
const linkedDoc = await createLinkedDoc('page1');
|
||||
const lickedDocBox = await linkedDoc.boundingBox();
|
||||
assertExists(lickedDocBox);
|
||||
if (!lickedDocBox) {
|
||||
throw new Error('lickedDocBox is not found');
|
||||
}
|
||||
await page.mouse.move(
|
||||
lickedDocBox.x + lickedDocBox.width / 2,
|
||||
lickedDocBox.y + lickedDocBox.height / 2
|
||||
@@ -60,7 +61,9 @@ test.describe('Embed synced doc', () => {
|
||||
|
||||
const syncedDoc = page.locator(`affine-embed-synced-doc-block`);
|
||||
const syncedDocBox = await syncedDoc.boundingBox();
|
||||
assertExists(syncedDocBox);
|
||||
if (!syncedDocBox) {
|
||||
throw new Error('syncedDocBox is not found');
|
||||
}
|
||||
await page.mouse.click(
|
||||
syncedDocBox.x + syncedDocBox.width / 2,
|
||||
syncedDocBox.y + syncedDocBox.height / 2
|
||||
@@ -95,7 +98,9 @@ test.describe('Embed synced doc', () => {
|
||||
// Focus on the embed synced doc
|
||||
const embedSyncedBlock = page.locator('affine-embed-synced-doc-block');
|
||||
let embedSyncedBox = await embedSyncedBlock.boundingBox();
|
||||
assertExists(embedSyncedBox);
|
||||
if (!embedSyncedBox) {
|
||||
throw new Error('embedSyncedBox is not found');
|
||||
}
|
||||
await page.mouse.click(
|
||||
embedSyncedBox.x + embedSyncedBox.width / 2,
|
||||
embedSyncedBox.y + embedSyncedBox.height / 2
|
||||
@@ -108,13 +113,17 @@ test.describe('Embed synced doc', () => {
|
||||
// Double click on note to enter edit status
|
||||
const noteBlock = page.locator('affine-edgeless-note');
|
||||
const noteBlockBox = await noteBlock.boundingBox();
|
||||
assertExists(noteBlockBox);
|
||||
if (!noteBlockBox) {
|
||||
throw new Error('noteBlockBox is not found');
|
||||
}
|
||||
await page.mouse.dblclick(noteBlockBox.x + 10, noteBlockBox.y + 10);
|
||||
await waitNextFrame(page, 200);
|
||||
|
||||
// Drag the embed synced doc to whiteboard
|
||||
embedSyncedBox = await embedSyncedBlock.boundingBox();
|
||||
assertExists(embedSyncedBox);
|
||||
if (!embedSyncedBox) {
|
||||
throw new Error('embedSyncedBox is not found');
|
||||
}
|
||||
const height = embedSyncedBox.height;
|
||||
await page.mouse.move(embedSyncedBox.x - 10, embedSyncedBox.y - 100);
|
||||
await page.mouse.move(embedSyncedBox.x - 10, embedSyncedBox.y + 10);
|
||||
@@ -129,7 +138,9 @@ test.describe('Embed synced doc', () => {
|
||||
);
|
||||
const EmbedSyncedDocBlockBox = await EmbedSyncedDocBlock.boundingBox();
|
||||
const border = 1;
|
||||
assertExists(EmbedSyncedDocBlockBox);
|
||||
if (!EmbedSyncedDocBlockBox) {
|
||||
throw new Error('EmbedSyncedDocBlockBox is not found');
|
||||
}
|
||||
expect(EmbedSyncedDocBlockBox.height).toBeCloseTo(height + 2 * border, 1);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -38,7 +38,6 @@ import {
|
||||
import {
|
||||
assertAlmostEqual,
|
||||
assertBlockChildrenIds,
|
||||
assertExists,
|
||||
assertLocatorVisible,
|
||||
assertRichImage,
|
||||
assertRichTextInlineRange,
|
||||
@@ -85,7 +84,9 @@ test('should format quick bar show when clicking drag handle', async ({
|
||||
await locator.hover();
|
||||
const dragHandle = page.locator('.affine-drag-handle-grabber');
|
||||
const dragHandleRect = await dragHandle.boundingBox();
|
||||
assertExists(dragHandleRect);
|
||||
if (!dragHandleRect) {
|
||||
throw new Error('dragHandleRect is not found');
|
||||
}
|
||||
await dragHandle.click();
|
||||
|
||||
const { formatBar } = getFormatBar(page);
|
||||
@@ -534,8 +535,12 @@ test('should format quick bar work in single block selection', async ({
|
||||
|
||||
const formatRect = await formatBar.boundingBox();
|
||||
const selectionRect = await blockSelections.boundingBox();
|
||||
assertExists(formatRect);
|
||||
assertExists(selectionRect);
|
||||
if (!formatRect) {
|
||||
throw new Error('formatRect is not found');
|
||||
}
|
||||
if (!selectionRect) {
|
||||
throw new Error('selectionRect is not found');
|
||||
}
|
||||
assertAlmostEqual(formatRect.x - selectionRect.x, 147.5, 10);
|
||||
assertAlmostEqual(formatRect.y - selectionRect.y, 33, 10);
|
||||
|
||||
@@ -588,7 +593,9 @@ test('should format quick bar work in multiple block selection', async ({
|
||||
throw new Error("formatBar doesn't exist");
|
||||
}
|
||||
const rect = await blockSelections.first().boundingBox();
|
||||
assertExists(rect);
|
||||
if (!rect) {
|
||||
throw new Error('rect is not found');
|
||||
}
|
||||
assertAlmostEqual(box.x - rect.x, 147.5, 10);
|
||||
assertAlmostEqual(box.y - rect.y, 99, 10);
|
||||
|
||||
@@ -955,7 +962,9 @@ test('create linked doc from block selection with format bar', async ({
|
||||
await expect(linkedDocBlock).toHaveCount(1);
|
||||
|
||||
const linkedDocBox = await linkedDocBlock.boundingBox();
|
||||
assertExists(linkedDocBox);
|
||||
if (!linkedDocBox) {
|
||||
throw new Error('linkedDocBox is not found');
|
||||
}
|
||||
await page.mouse.dblclick(
|
||||
linkedDocBox.x + linkedDocBox.width / 2,
|
||||
linkedDocBox.y + linkedDocBox.height / 2
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
waitNextFrame,
|
||||
} from './utils/actions/misc.js';
|
||||
import {
|
||||
assertExists,
|
||||
assertParentBlockFlavour,
|
||||
assertRichTexts,
|
||||
assertTitle,
|
||||
@@ -43,7 +42,9 @@ async function createAndConvertToEmbedLinkedDoc(page: Page) {
|
||||
const { createLinkedDoc } = getLinkedDocPopover(page);
|
||||
const linkedDoc = await createLinkedDoc('page1');
|
||||
const lickedDocBox = await linkedDoc.boundingBox();
|
||||
assertExists(lickedDocBox);
|
||||
if (!lickedDocBox) {
|
||||
throw new Error('lickedDocBox is not found');
|
||||
}
|
||||
await page.mouse.move(
|
||||
lickedDocBox.x + lickedDocBox.width / 2,
|
||||
lickedDocBox.y + lickedDocBox.height / 2
|
||||
|
||||
@@ -55,7 +55,6 @@ import {
|
||||
assertBlockSelections,
|
||||
assertClipItems,
|
||||
assertDivider,
|
||||
assertExists,
|
||||
assertNativeSelectionRangeCount,
|
||||
assertRichTextInlineRange,
|
||||
assertRichTexts,
|
||||
@@ -847,7 +846,9 @@ test('the cursor should move to closest editor block when clicking outside conta
|
||||
|
||||
const text2 = page.locator('[data-block-id="3"] .inline-editor');
|
||||
const rect = await text2.boundingBox();
|
||||
assertExists(rect);
|
||||
if (!rect) {
|
||||
throw new Error('rect is not found');
|
||||
}
|
||||
|
||||
// The behavior of mouse click is similar to touch in mobile device
|
||||
// await page.mouse.click(rect.x - 50, rect.y + 5);
|
||||
@@ -1760,7 +1761,9 @@ test('unexpected scroll when clicking padding area', async ({ page }) => {
|
||||
|
||||
const list = page.locator('[data-block-id="34"]');
|
||||
const listRect = await list.boundingBox();
|
||||
assertExists(listRect);
|
||||
if (!listRect) {
|
||||
throw new Error('listRect is not found');
|
||||
}
|
||||
await page.mouse.click(listRect.x - 30, listRect.y + 5);
|
||||
const newListRect = await list.boundingBox();
|
||||
// not scroll
|
||||
@@ -1770,7 +1773,9 @@ test('unexpected scroll when clicking padding area', async ({ page }) => {
|
||||
await type(page, '/tableview\n');
|
||||
const database = page.locator('affine-database');
|
||||
const databaseRect = await database.boundingBox();
|
||||
assertExists(databaseRect);
|
||||
if (!databaseRect) {
|
||||
throw new Error('databaseRect is not found');
|
||||
}
|
||||
await page.mouse.click(
|
||||
databaseRect.x + databaseRect.width + 10,
|
||||
databaseRect.y + 100
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
import {
|
||||
assertAlmostEqual,
|
||||
assertBlockCount,
|
||||
assertExists,
|
||||
assertRichTexts,
|
||||
} from './utils/asserts.js';
|
||||
import { test } from './utils/playwright.js';
|
||||
@@ -344,7 +343,9 @@ test.describe('slash menu should show and hide correctly', () => {
|
||||
const subMenu = page.locator('.slash-menu[data-testid=sub-menu-1]');
|
||||
|
||||
let rect = await slashItems.nth(4).boundingBox();
|
||||
assertExists(rect);
|
||||
if (!rect) {
|
||||
throw new Error('rect is not found');
|
||||
}
|
||||
await page.mouse.move(rect.x + 10, rect.y + 10);
|
||||
await expect(slashMenu).toBeVisible();
|
||||
await expect(slashItems.nth(4)).toHaveAttribute('hover', 'true');
|
||||
@@ -354,7 +355,9 @@ test.describe('slash menu should show and hide correctly', () => {
|
||||
await expect(subMenu).toBeVisible();
|
||||
|
||||
rect = await slashItems.nth(3).boundingBox();
|
||||
assertExists(rect);
|
||||
if (!rect) {
|
||||
throw new Error('rect is not found');
|
||||
}
|
||||
await page.mouse.move(rect.x + 10, rect.y + 10);
|
||||
await expect(slashMenu).toBeVisible();
|
||||
await expect(slashItems.nth(3)).toHaveAttribute('hover', 'true');
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import type {
|
||||
RichText,
|
||||
RootBlockModel,
|
||||
} from '@blocksuite/blocks';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { InlineRootElement } from '@blocksuite/inline';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
import { expect, type Locator, type Page } from '@playwright/test';
|
||||
@@ -53,8 +52,6 @@ import {
|
||||
} from './actions/misc.js';
|
||||
import { getStringFromRichText } from './inline-editor.js';
|
||||
|
||||
export { assertExists };
|
||||
|
||||
const BLOCK_ID_ATTR = 'data-block-id';
|
||||
|
||||
export const defaultStore = {
|
||||
|
||||
Reference in New Issue
Block a user