Some checks failed
Build & Test / Analyze (javascript, affine) (push) Failing after 4s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 4s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 3s
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 4s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 3s
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Release / Canary Gate (push) Has been skipped
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Release / Prepare (push) Failing after 2s
Release / Release Cloud (push) Has been skipped
Release / Release Desktop (push) Has been skipped
Release / Release Docker Image (push) Has been skipped
Release / Release Mobile (push) Has been skipped
Copilot Test Automatically / Setup Test (push) Failing after 1s
280 lines
8.2 KiB
TypeScript
280 lines
8.2 KiB
TypeScript
import { test } from '@affine-test/kit/playwright';
|
|
import {
|
|
clickEdgelessModeButton,
|
|
clickPageModeButton,
|
|
createEdgelessNoteBlock,
|
|
} from '@affine-test/kit/utils/editor';
|
|
import {
|
|
pressBackspace,
|
|
pressEnter,
|
|
selectAllByKeyboard,
|
|
} from '@affine-test/kit/utils/keyboard';
|
|
import { openHomePage } from '@affine-test/kit/utils/load-page';
|
|
import {
|
|
clickNewPageButton,
|
|
createLinkedPage,
|
|
type,
|
|
waitForEditorLoad,
|
|
} from '@affine-test/kit/utils/page-logic';
|
|
import { expect, type Locator, type Page } from '@playwright/test';
|
|
|
|
import {
|
|
createHeadings,
|
|
createTitle,
|
|
getVerticalCenterFromLocator,
|
|
} from './utils';
|
|
|
|
function getIndicators(container: Page | Locator) {
|
|
return container.locator('affine-outline-viewer .outline-viewer-indicator');
|
|
}
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await openHomePage(page);
|
|
await clickNewPageButton(page);
|
|
await waitForEditorLoad(page);
|
|
});
|
|
|
|
test('should display indicators when non-empty headings exists', async ({
|
|
page,
|
|
}) => {
|
|
const indicators = getIndicators(page);
|
|
await createHeadings(page);
|
|
|
|
await expect(indicators).toHaveCount(6);
|
|
for (let i = 0; i < 6; i++) {
|
|
await expect(indicators.nth(i)).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('should be hidden when only empty headings exists', async ({ page }) => {
|
|
const indicators = getIndicators(page);
|
|
await expect(indicators).toHaveCount(0);
|
|
|
|
for (let i = 1; i <= 6; i++) {
|
|
// empty heading
|
|
await type(page, `${'#'.repeat(i)} `);
|
|
await pressEnter(page);
|
|
}
|
|
|
|
await expect(indicators).toHaveCount(0);
|
|
});
|
|
|
|
test('should update indicator when clear title or headings', async ({
|
|
page,
|
|
}) => {
|
|
const indicators = getIndicators(page);
|
|
const title = await createTitle(page);
|
|
const headings = await createHeadings(page);
|
|
|
|
await expect(indicators).toHaveCount(7);
|
|
|
|
await title.scrollIntoViewIfNeeded();
|
|
await title.click();
|
|
await selectAllByKeyboard(page);
|
|
await pressBackspace(page);
|
|
await expect(indicators).toHaveCount(6);
|
|
|
|
for (let i = 1; i <= 6; i++) {
|
|
await headings[i - 1].click();
|
|
await selectAllByKeyboard(page);
|
|
await pressBackspace(page);
|
|
await expect(indicators).toHaveCount(6 - i);
|
|
}
|
|
});
|
|
|
|
test('should display simple outline panel when hovering over indicators', async ({
|
|
page,
|
|
}) => {
|
|
const indicators = getIndicators(page);
|
|
await createTitle(page);
|
|
await createHeadings(page);
|
|
await indicators.first().hover({ force: true });
|
|
|
|
const items = page.locator('.outline-viewer-item');
|
|
await expect(items).toHaveCount(8);
|
|
await expect(items.nth(0)).toContainText(['Table of Contents']);
|
|
await expect(items.nth(1)).toContainText(['Title']);
|
|
for (let i = 2; i <= 7; i++) {
|
|
await expect(items.nth(i)).toContainText([`Heading ${i - 1}`]);
|
|
}
|
|
});
|
|
|
|
test('should highlight indicator when scrolling', async ({ page }) => {
|
|
const indicators = getIndicators(page);
|
|
const title = await createTitle(page);
|
|
for (let i = 1; i <= 3; i++) {
|
|
await pressEnter(page);
|
|
}
|
|
const headings = await createHeadings(page, 10);
|
|
await title.scrollIntoViewIfNeeded();
|
|
|
|
const viewportCenter = await getVerticalCenterFromLocator(
|
|
page.locator('body')
|
|
);
|
|
for (let i = 0; i < headings.length; i++) {
|
|
const lastHeadingCenter = await getVerticalCenterFromLocator(headings[i]);
|
|
await expect(indicators.nth(i)).toHaveClass(/active/);
|
|
await page.mouse.wheel(0, lastHeadingCenter - viewportCenter + 20);
|
|
await page.waitForTimeout(10);
|
|
}
|
|
});
|
|
|
|
test('should highlight indicator when click item in outline panel', async ({
|
|
page,
|
|
}) => {
|
|
const viewer = page.locator('affine-outline-viewer');
|
|
const indicators = getIndicators(page);
|
|
const headings = await createHeadings(page, 10);
|
|
|
|
await indicators.first().hover({ force: true });
|
|
|
|
const headingsInPanel = Array.from({ length: 6 }, (_, i) =>
|
|
viewer.getByTestId(`outline-block-preview-h${i + 1}`)
|
|
);
|
|
await headingsInPanel[2].click();
|
|
await expect(headings[2]).toBeVisible();
|
|
await expect(indicators.nth(2)).toHaveClass(/active/);
|
|
});
|
|
|
|
test('outline viewer should hide in edgeless mode', async ({ page }) => {
|
|
await createTitle(page);
|
|
await pressEnter(page);
|
|
|
|
await type(page, '# ');
|
|
await type(page, 'Heading 1');
|
|
|
|
const indicators = getIndicators(page);
|
|
await expect(indicators).toHaveCount(2);
|
|
|
|
await clickEdgelessModeButton(page);
|
|
await expect(indicators).toHaveCount(0);
|
|
|
|
await clickPageModeButton(page);
|
|
await expect(indicators).toHaveCount(2);
|
|
});
|
|
|
|
test('should hide edgeless-only note headings', async ({ page }) => {
|
|
await createTitle(page);
|
|
await pressEnter(page);
|
|
await type(page, '# Heading 1');
|
|
await pressEnter(page);
|
|
await type(page, '## Heading 2');
|
|
|
|
await clickEdgelessModeButton(page);
|
|
await createEdgelessNoteBlock(page, [100, 100]);
|
|
await type(page, '# Edgeless');
|
|
|
|
await clickPageModeButton(page);
|
|
await waitForEditorLoad(page);
|
|
const indicators = getIndicators(page);
|
|
await expect(indicators).toHaveCount(3);
|
|
await indicators.first().hover({ force: true });
|
|
|
|
const viewer = page.locator('affine-outline-viewer');
|
|
await expect(viewer).toBeVisible();
|
|
const h1InPanel = viewer
|
|
.getByTestId('outline-block-preview-h1')
|
|
.locator('span');
|
|
await h1InPanel.waitFor({ state: 'visible' });
|
|
await expect(h1InPanel).toContainText(['Heading 1']);
|
|
});
|
|
|
|
test('outline viewer should update after change heading in edgeless mode', async ({
|
|
page,
|
|
}) => {
|
|
await createTitle(page);
|
|
await pressEnter(page);
|
|
|
|
await type(page, '# ');
|
|
await type(page, 'Heading 1');
|
|
|
|
await clickEdgelessModeButton(page);
|
|
const note = page.locator('affine-edgeless-note');
|
|
await note.dblclick();
|
|
await type(page, '# New Heading');
|
|
await clickPageModeButton(page);
|
|
|
|
const indicators = getIndicators(page);
|
|
await expect(indicators).toHaveCount(3);
|
|
});
|
|
|
|
test('outline viewer should be useable in doc peek preview', async ({
|
|
page,
|
|
}) => {
|
|
await pressEnter(page);
|
|
await createLinkedPage(page, 'Test Page');
|
|
|
|
await page.locator('affine-reference').hover();
|
|
|
|
const toolbar = page.locator('affine-toolbar-widget editor-toolbar');
|
|
await expect(toolbar).toBeVisible();
|
|
|
|
await toolbar.getByLabel(/^Open doc with$/).click();
|
|
await toolbar
|
|
.getByLabel('Open doc menu')
|
|
.getByLabel('Open in center peek')
|
|
.click();
|
|
|
|
const peekView = page.getByTestId('peek-view-modal');
|
|
await expect(peekView).toBeVisible();
|
|
|
|
const title = peekView.locator('doc-title .inline-editor');
|
|
await title.click();
|
|
await pressEnter(page);
|
|
|
|
await type(page, '# Heading 1');
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
await pressEnter(page);
|
|
}
|
|
|
|
await type(page, '## Heading 2');
|
|
|
|
const outlineViewer = peekView.locator('affine-outline-viewer');
|
|
const outlineViewerBound = await outlineViewer.boundingBox();
|
|
expect(outlineViewerBound).not.toBeNull();
|
|
|
|
const indicators = getIndicators(peekView);
|
|
await expect(indicators).toHaveCount(3);
|
|
await expect(indicators.nth(0)).toBeVisible();
|
|
await expect(indicators.nth(1)).toBeVisible();
|
|
await expect(indicators.nth(2)).toBeVisible();
|
|
|
|
await indicators.first().hover({ force: true });
|
|
const viewer = peekView.locator('affine-outline-viewer');
|
|
await expect(viewer).toBeVisible();
|
|
|
|
// position of outline viewer should be fixed
|
|
{
|
|
const headingButtons = peekView.locator(
|
|
'affine-outline-viewer .outline-viewer-item:not(.outline-viewer-header)'
|
|
);
|
|
await expect(headingButtons).toHaveCount(3);
|
|
await expect(headingButtons.nth(0)).toBeVisible();
|
|
await expect(headingButtons.nth(1)).toBeVisible();
|
|
await expect(headingButtons.nth(2)).toBeVisible();
|
|
|
|
await headingButtons.last().click();
|
|
await page.mouse.move(0, 0);
|
|
await headingButtons.last().waitFor({ state: 'hidden' });
|
|
|
|
const currentOutlineViewerBound = await outlineViewer.boundingBox();
|
|
expect(currentOutlineViewerBound).not.toBeNull();
|
|
expect(outlineViewerBound).toEqual(currentOutlineViewerBound);
|
|
}
|
|
|
|
// outline viewer should be hidden when clicking the outline panel toggle button
|
|
{
|
|
await indicators.first().hover({ force: true });
|
|
const toggleButton = peekView.locator(
|
|
'.outline-viewer-header edgeless-tool-icon-button'
|
|
);
|
|
await toggleButton.click();
|
|
|
|
await page.waitForTimeout(500);
|
|
await expect(peekView).toBeHidden();
|
|
await expect(viewer).toBeHidden();
|
|
await expect(page.locator('affine-outline-panel')).toBeVisible();
|
|
}
|
|
});
|