Scope article feeds and expand canvas editing

This commit is contained in:
2026-11-21 22:55:59 +08:00
parent a2fc628f08
commit 9bc0ee0e45
32 changed files with 476 additions and 67 deletions
+100 -7
View File
@@ -54,6 +54,8 @@ async function run(browser) {
const frame = page.frameLocator('iframe[title="可编辑页面画布"]');
const sizing = page.locator('[data-media-sizing]');
const properties = page.locator('[data-canvas-properties]');
const tools = page.getByRole('group', {name: '所选元素'});
const align = (label) => tools.getByRole('button', {name: label, exact: true}).click();
const closeProperties = () => properties.locator('[data-property-close]').click();
const image = frame.locator('#fixtures img');
@@ -77,6 +79,18 @@ async function run(browser) {
await properties.locator('[name=url]').fill('/assets/original/home-hero.webp');
await properties.locator('button[type=submit]').click();
assert.equal(await image.getAttribute('src'), '/assets/original/home-hero.webp');
await image.click();
await align('居右');
const rightEdge = await image.boundingBox();
const leftHandle = await handle.boundingBox();
assert(Math.abs(rightEdge.x - (leftHandle.x + leftHandle.width / 2)) < 2);
await align('居中');
const centeredImage = await image.evaluate((node) => {
const bounds = node.getBoundingClientRect();
const parent = node.parentElement.getBoundingClientRect();
return Math.abs((bounds.left + bounds.right) / 2 - (parent.left + parent.right) / 2) < 2;
});
assert(centeredImage);
const hero = frame.locator('[data-studio-hero-image]');
await page.locator('iframe[title="可编辑页面画布"]').evaluate((iframe) => iframe.contentWindow.scrollTo(0, 0));
@@ -88,8 +102,11 @@ async function run(browser) {
await sizing.locator('[data-replace-media]').click();
assert.equal(await properties.locator('h2').textContent(), '首屏图片');
await closeProperties();
const heroTitle = frame.locator('[data-studio-field=heading]');
await heroTitle.click();
await align('居右');
assert.equal(await heroTitle.evaluate((node) => getComputedStyle(node.parentElement).textAlign), 'right');
const tools = page.getByRole('group', {name: '所选元素'});
await frame.locator('#fixtures a').click();
await tools.getByRole('button', {name: '属性'}).click();
await properties.waitFor({state: 'visible'});
@@ -108,6 +125,11 @@ async function run(browser) {
const copyText = frame.locator('#fixtures').getByText('待复制段落', {exact: true});
await copyText.click();
await align('居中');
await align('居左');
assert.equal(await copyText.evaluate((node) => getComputedStyle(node).textAlign), 'left');
await align('居右');
assert.equal(await copyText.evaluate((node) => getComputedStyle(node).textAlign), 'right');
await tools.getByRole('button', {name: '复制'}).click();
assert.equal(await copyText.count(), 2);
assert.equal(await frame.locator('#copy-fixture').count(), 1);
@@ -119,9 +141,19 @@ async function run(browser) {
await tools.getByRole('button', {name: '删除'}).click();
assert.equal(await page.locator('[name=lead]').inputValue(), '');
const sectionTitle = frame.locator('#fixtures [data-studio-part=title]');
await sectionTitle.click();
await align('居中');
assert.equal(await sectionTitle.evaluate((node) => getComputedStyle(node).textAlign), 'center');
const gallery = page.locator('[data-canvas-presets]');
assert.equal(await gallery.locator('[data-template-group]').count(), 6);
assert.equal(await gallery.locator('[data-template-card]').count(), 14);
await copyText.first().click();
await gallery.getByText('基础元素', {exact: true}).click();
await gallery.getByRole('button', {name: '插入分割线'}).click();
await frame.locator('#fixtures .studio-divider').waitFor();
await gallery.getByText('基础元素', {exact: true}).click();
assert.equal(await gallery.locator('[data-template-group]').count(), 7);
assert.equal(await gallery.locator('[data-template-card]').count(), 22);
const brokenPreviews = await gallery.locator('[data-template-card] img').evaluateAll(async (images) => {
for (const image of images) image.loading = 'eager';
await Promise.all(images.map((image) => image.decode()));
@@ -149,6 +181,9 @@ async function run(browser) {
await gallery.locator('[data-template-empty]').waitFor({state: 'visible'});
await search.fill('双栏');
assert.equal(await gallery.locator('[data-template-card]:visible').count(), 1);
await search.fill('重点提示');
await gallery.locator('[data-canvas-template=notice]').click();
await frame.locator('.studio-notice').waitFor();
await search.fill('分类文章');
await gallery.locator('[data-canvas-template=articles]').click();
await frame.locator('section[id^=block-] h2').filter({hasText: '分类文章'}).waitFor();
@@ -161,7 +196,12 @@ async function run(browser) {
await frame.locator('section[id^=block-] .studio-cover').waitFor();
assert.equal(await frame.locator('#fixtures a').getAttribute('href'), '/articles');
assert.equal(await frame.locator('#fixtures img').getAttribute('src'), '/assets/original/home-hero.webp');
assert.equal(await frame.locator('#fixtures img').getAttribute('class'), imageSize);
assert.deepEqual((await image.getAttribute('class')).split(/\s+/).sort(), [imageSize, 'studio-align-center'].sort());
assert.equal(await heroTitle.evaluate((node) => getComputedStyle(node.parentElement).textAlign), 'right');
assert.equal(await sectionTitle.evaluate((node) => getComputedStyle(node).textAlign), 'center');
assert.deepEqual(await copyText.evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).textAlign)), ['right', 'right']);
await frame.locator('.studio-notice').waitFor();
await frame.locator('#fixtures .studio-divider').waitFor();
assert.match(await frame.locator('[data-visual]').getAttribute('class'), /studio-media-99/);
assert.equal(await copyText.count(), 2);
assert.equal(await frame.locator('#copy-fixture').count(), 1);
@@ -190,7 +230,7 @@ async function run(browser) {
}
async function verifyArticleLibrary(browser, context, page, post, slug, feedId) {
const category = slug + '-category';
const category = String(Date.now());
await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
const articleSlug = slug + '-article';
await page.goto('/admin/articles/new');
@@ -202,6 +242,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
await page.locator('[name=title]').fill('测试 Markdown 和富文本');
await page.locator('[name=slug]').fill(articleSlug);
await page.locator('[name="categories[]"][value="' + category + '"]').check();
await page.locator('[name="categories[]"][value=product]').check();
await page.locator('[name=status]').selectOption('published');
await markdown.fill('**Markdown 分屏**');
await preview.locator('strong').getByText('Markdown 分屏').waitFor();
@@ -211,7 +252,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
const publishedPath = '/articles/' + articleSlug;
const sourcePage = await context.newPage();
await sourcePage.goto(publishedPath);
assert.equal(await sourcePage.locator('[itemprop=articleSection]').count(), 2);
assert.equal(await sourcePage.locator('[itemprop=articleSection]').count(), 3);
await sourcePage.locator('[itemprop=articleBody] strong').getByText('Markdown 分屏').waitFor();
await page.goto(articleAdmin);
await editor.locator('.toastui-editor-mode-switch').getByText('所见即所得', {exact: true}).click();
@@ -241,6 +282,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
await page.locator('[name="feed_categories[]"][value="' + category + '"]').check();
await page.getByRole('button', {name: '保存区块'}).click();
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'});
assert(await page.locator('[name="feed_categories[]"][value="' + category + '"]').isChecked());
let contentVersion = await page.locator('[name=version]').inputValue();
assert.equal(contentVersion, '1');
const canvasPath = '/admin/pages/' + slug + '/preview';
@@ -268,6 +310,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
assert.equal(await noJSPage.locator('#' + feedId + ' a[href="' + publishedPath + '"]:visible').count(), 2);
await noJS.close();
assert((await context.request.get('/articles/category/' + category)).ok());
await verifyScopedArchive(context, page, sourcePage, post, slug, feedId, category, publishedPath);
await sourcePage.goto('/services');
await sourcePage.locator('.catalog-card').first().waitFor();
await sourcePage.goto('/network');
@@ -275,11 +318,61 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
await sourcePage.close();
}
async function verifyScopedArchive(context, admin, page, post, slug, feedId, category, articlePath) {
const scope = '/articles/feed/' + slug + '/' + feedId;
const scopedResponse = (query = '') => context.request.get(scope + query);
assert.equal((await scopedResponse()).status(), 404);
await admin.goto('/admin/pages/' + slug);
await admin.locator('[name=description]').fill('公开文章区块筛选测试。');
await admin.locator('[name=status]').selectOption('published');
await admin.getByRole('button', {name: '保存页面', exact: true}).first().click();
await admin.locator('[data-save-confirmation]').waitFor({state: 'visible'});
const excluded = await post('/admin/articles/new', {
title: '分类范围外测试文章', slug: slug + '-excluded', body_format: 'markdown',
body: '只属于公告分类。', status: 'published', 'categories[]': 'announcement',
});
assert(excluded.redirect);
await page.goto('/' + slug);
const archiveLink = page.locator('#' + feedId).getByRole('link', {name: '查看全部动态'});
assert.equal(await archiveLink.getAttribute('href'), scope);
await archiveLink.click();
await page.waitForURL('**' + scope);
const list = page.locator('main .article-list');
assert.equal(await list.locator('a[href="' + articlePath + '"]').count(), 1);
assert.equal(await list.locator('a[href="/articles/' + slug + '-excluded"]').count(), 0);
assert.doesNotMatch(await list.locator('a[href="' + articlePath + '"] .article-category').textContent(), /产品/);
const filters = page.getByRole('navigation', {name: '动态分类'});
assert.deepEqual(await filters.getByRole('link').allTextContents(), ['全部', '新闻', '自定义测试分类']);
assert.equal((await scopedResponse('?category=announcement')).status(), 404);
assert.equal((await scopedResponse('?category[]=news')).status(), 404);
assert.equal((await scopedResponse('?categories=announcement')).status(), 200);
assert.doesNotMatch(await (await scopedResponse('?categories=announcement')).text(), /分类范围外测试文章/);
for (let index = 0; index < 21; index++) {
await post('/admin/articles/new', {
title: '分类分页样例 ' + index, slug: slug + '-sample-' + index, body_format: 'markdown',
body: '所选分类中的分页样例。', status: 'published', 'categories[]': category,
});
}
const categoryPath = scope + '?category=' + category;
await filters.getByRole('link', {name: '自定义测试分类'}).click();
await page.waitForURL('**' + categoryPath);
const next = page.getByRole('link', {name: '下一页'});
assert.equal(await next.getAttribute('href'), categoryPath + '&page=2');
await next.click();
await page.waitForURL('**' + categoryPath + '&page=2');
assert.equal(await list.locator('a').count(), 2);
assert.equal(await page.getByRole('link', {name: '上一页'}).getAttribute('href'), categoryPath);
assert.equal(await filters.getByRole('link', {name: '全部'}).getAttribute('href'), scope);
assert.equal(await page.getByRole('link', {name: '返回原页面'}).getAttribute('href'), '/' + slug + '#' + feedId);
}
(async () => {
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
try {
await run(browser);
console.log('Passed Chromium canvas media/link interactions, template gallery, persistence, and the article library.');
console.log('Passed Chromium canvas alignment, editor elements and modules, persistence, and scoped article archives.');
} finally {
await browser.close();
}