Files
upstream-affine/tests/affine-local/e2e/template.spec.ts
upstream-mirror 702cc698a7
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
Copilot Test Automatically / Setup Test (push) Failing after 1s
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
snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
2026-09-16 04:01:20 +05:00

279 lines
11 KiB
TypeScript

import { test } from '@affine-test/kit/playwright';
import {
confirmCreateJournal,
openHomePage,
} from '@affine-test/kit/utils/load-page';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { expect, type Locator, type Page } from '@playwright/test';
function getTemplateRow(page: Page) {
return page.locator(
'[data-testid="doc-property-row"][data-info-id="template"]'
);
}
async function toggleTemplate(row: Locator, value: boolean) {
const checkbox = row.locator('input[type="checkbox"]');
const state = await checkbox.inputValue();
const checked = state === 'on';
if (checked !== value) {
await checkbox.click();
const newState = await checkbox.inputValue();
const newChecked = newState === 'on';
expect(newChecked).toBe(value);
}
}
const createDocAndMarkAsTemplate = async (
page: Page,
title?: string,
onCreated?: () => Promise<void>
) => {
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
if (title) {
await page.keyboard.type(title);
}
const collapse = page.getByTestId('page-info-collapse');
const open = await collapse.getAttribute('aria-expanded');
if (open?.toLowerCase() !== 'true') {
await collapse.click();
}
// add if not exists
if ((await getTemplateRow(page).count()) === 0) {
const addPropertyButton = page.getByTestId('add-property-button');
if (!(await addPropertyButton.isVisible())) {
await page.getByTestId('property-collapsible-button').click();
}
await addPropertyButton.click();
await page
.locator('[role="menuitem"][data-property-type="journal"]')
.click();
await page.keyboard.press('Escape');
}
// expand if collapsed
else if (!(await getTemplateRow(page).isVisible())) {
await page.getByTestId('property-collapsible-button').click();
}
const templateRow = getTemplateRow(page);
await expect(templateRow).toBeVisible();
await toggleTemplate(templateRow, true);
// focus editor
await page.locator('affine-note').first().click();
await onCreated?.();
};
const getDocId = async (page: Page) => {
const docId = await page.evaluate(() => {
const url = window.location.href;
const id = url.split('/').pop()?.split('?')[0];
return id;
});
return docId;
};
const enableAskMeEveryTime = async (page: Page) => {
await page.getByTestId('slider-bar-workspace-setting-button').click();
await page.getByTestId('editor-panel-trigger').click();
await page.getByTestId('new-doc-default-mode-trigger').click();
await page.getByTestId('ask-every-time-trigger').click();
await page.keyboard.press('Escape');
};
test('create a doc and mark it as template', async ({ page }) => {
await openHomePage(page);
await createDocAndMarkAsTemplate(page, 'Test Template', async () => {
await page.keyboard.type('# Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a template doc');
});
});
test('create a doc, and initialize it from template', async ({ page }) => {
await openHomePage(page);
await createDocAndMarkAsTemplate(page, 'Test Template', async () => {
await page.keyboard.type('# Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a template doc');
});
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
await page.getByTestId('template-docs-badge').click();
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(page.getByText('This is a template doc')).toBeVisible();
// the starter bar should be hidden
await expect(page.getByTestId('template-docs-badge')).not.toBeVisible();
});
test('enable ask me every time for new doc', async ({ page }) => {
const withAskButton = page.getByTestId('sidebar-new-page-with-ask-button');
const withoutAskButton = page.getByTestId('sidebar-new-page-button');
await openHomePage(page);
await expect(withAskButton).not.toBeVisible();
await expect(withoutAskButton).toBeVisible();
await enableAskMeEveryTime(page);
await expect(withAskButton).toBeVisible();
await expect(withoutAskButton).not.toBeVisible();
});
test('set default template for page', async ({ page }) => {
await openHomePage(page);
await createDocAndMarkAsTemplate(page, 'Test Template', async () => {
await page.keyboard.type('# Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a template doc');
});
const templateDocId = await getDocId(page);
// create a new page, should not inherit template
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
await expect(page.getByText('This is a template doc')).not.toBeVisible();
// enable page template and set a template
await page.getByTestId('slider-bar-workspace-setting-button').click();
await page.getByTestId('workspace-setting:preference').click();
const pageTemplateSwitch = page.getByTestId('page-template-switch');
await pageTemplateSwitch.click();
const pageTemplateSelector = page.getByTestId('page-template-selector');
await expect(pageTemplateSelector).toBeVisible();
await pageTemplateSelector.click();
await page.getByTestId(`template-doc-item-${templateDocId}`).click();
// close setting, create a new page from sidebar
await page.getByTestId('modal-close-button').click();
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
await expect(page.getByText('This is a template doc')).toBeVisible();
// remove template
await page.getByTestId('slider-bar-workspace-setting-button').click();
await page.getByTestId('workspace-setting:preference').click();
await page.getByTestId('page-template-selector').click();
await page.getByTestId('template-doc-item-remove').click();
// close setting, create a new page from sidebar
await page.getByTestId('modal-close-button').click();
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
await expect(page.getByText('This is a template doc')).not.toBeVisible();
});
test('set default template for journal', async ({ page }) => {
await openHomePage(page);
await createDocAndMarkAsTemplate(page, 'Page Template', async () => {
await page.keyboard.type('# Page Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a page template doc');
});
const pageTemplateDocId = await getDocId(page);
await createDocAndMarkAsTemplate(page, 'Journal Template', async () => {
await page.keyboard.type('# Journal Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a journal template doc');
});
const journalTemplateDocId = await getDocId(page);
// by default create a journal, should not use template
await page.getByTestId('slider-bar-journals-button').click();
await confirmCreateJournal(page);
await waitForEditorLoad(page);
await expect(
page.getByText('This is a journal template doc')
).not.toBeVisible();
await expect(page.getByText('This is a page template doc')).not.toBeVisible();
// enable page template, new journal should use page template
await page.getByTestId('slider-bar-workspace-setting-button').click();
await page.getByTestId('workspace-setting:preference').click();
await page.getByTestId('page-template-switch').click();
await page.getByTestId('page-template-selector').click();
await page.getByTestId(`template-doc-item-${pageTemplateDocId}`).click();
await page.getByTestId('modal-close-button').click();
// create a new journal
const prevWeekButton = page.getByTestId('week-picker-prev');
await prevWeekButton.click();
await page.getByTestId('week-picker-day').first().click();
await confirmCreateJournal(page);
await waitForEditorLoad(page);
await expect(page.getByText('This is a page template doc')).toBeVisible();
// set journal template, new journal should use journal template
await page.getByTestId('slider-bar-workspace-setting-button').click();
await page.getByTestId('workspace-setting:preference').click();
await page.getByTestId('journal-template-selector').click();
await page.getByTestId(`template-doc-item-${journalTemplateDocId}`).click();
await page.getByTestId('modal-close-button').click();
// create a new journal
await prevWeekButton.click();
await page.getByTestId('week-picker-day').first().click();
await confirmCreateJournal(page);
await waitForEditorLoad(page);
await expect(page.getByText('This is a journal template doc')).toBeVisible();
});
test('open template doc from sidebar template entrance', async ({ page }) => {
await openHomePage(page);
await createDocAndMarkAsTemplate(page, 'Test Template', async () => {
await page.keyboard.type('# Template');
await page.keyboard.press('Enter');
await page.keyboard.type('This is a template doc');
});
const templateDocId = await getDocId(page);
await page.getByTestId('sidebar-new-page-button').click();
await waitForEditorLoad(page);
await expect(page.getByText('This is a template doc')).not.toBeVisible();
await page.getByTestId('sidebar-template-doc-entrance').click();
await page.getByTestId(`template-doc-item-${templateDocId}`).click();
await waitForEditorLoad(page);
await expect(page.getByText('This is a template doc')).toBeVisible();
});
test('create template doc from sidebar template entrance', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await page.getByTestId('sidebar-template-doc-entrance').click();
await page.getByTestId('template-doc-item-create').click();
await page.locator('affine-note').first().click();
await page.keyboard.press('Backspace');
await page.keyboard.type('Template');
const templateDocId = await getDocId(page);
await page.getByTestId('sidebar-template-doc-entrance').click();
await expect(
page.getByTestId(`template-doc-item-${templateDocId}`)
).toBeVisible();
});
test('should show starter-bar when doc is empty', async ({ page }) => {
await openHomePage(page);
await page.getByTestId('sidebar-new-page-button').click();
await page.keyboard.press('ArrowDown');
const starterBar = page.getByTestId('starter-bar');
await expect(starterBar).toBeVisible();
await page.keyboard.type('1', { delay: 100 });
await expect(starterBar).not.toBeVisible();
await page.keyboard.type('1', { delay: 100 });
await expect(starterBar).not.toBeVisible();
await page.keyboard.press('Backspace');
await expect(starterBar).not.toBeVisible();
await page.keyboard.press('Backspace');
await expect(starterBar).toBeVisible();
await page.keyboard.type('1', { delay: 100 });
await expect(starterBar).not.toBeVisible();
});