Add category-first template library and improve admin dashboard

This commit is contained in:
2026-11-21 23:44:26 +08:00
parent 2ef38bd716
commit 2cf63b61ba
18 changed files with 471 additions and 200 deletions
+62 -16
View File
@@ -33,6 +33,18 @@ async function run(browser) {
}
await post('/admin/new-page', {slug, name: '画布测试页'});
await page.goto('/admin');
const dashboard = page.locator('[data-page-list]');
await dashboard.locator('[data-page-search]').fill(slug);
assert.equal(await dashboard.locator('[data-page-item]:visible').count(), 1);
const draft = dashboard.locator('[data-page-item]:visible');
assert.equal(await draft.getAttribute('data-page-item'), 'draft');
assert.equal(await draft.getByRole('link', {name: '预览'}).getAttribute('href'), '/admin/pages/' + slug + '/preview');
await dashboard.locator('[data-page-status]').selectOption('published');
await dashboard.locator('[data-page-empty]').waitFor({state: 'visible'});
await dashboard.locator('[data-page-status]').selectOption('draft');
assert.equal(await dashboard.locator('[data-page-item]:visible').count(), 1);
assert.equal(await page.getByRole('navigation', {name: '后台导航'}).getByRole('link', {name: '页面'}).getAttribute('aria-current'), 'page');
await post('/admin/page-blocks/' + slug, {operation: 'create', key: 'fixtures', preset: 'text'});
await post('/admin/pages/' + slug + '/fixtures', {
version: '0', title: '媒体和链接', lead: '', style: 'plain',
@@ -147,21 +159,41 @@ async function run(browser) {
assert.equal(await sectionTitle.evaluate((node) => getComputedStyle(node).textAlign), 'center');
const gallery = page.locator('[data-canvas-presets]');
const modules = gallery.locator('[data-library-panel=modules]');
const elements = gallery.locator('[data-library-panel=elements]');
const moduleTab = gallery.getByRole('tab', {name: '组件'});
const elementTab = gallery.getByRole('tab', {name: '元素'});
const backToModules = () => modules.getByRole('button', {name: '返回分类'}).click();
const openModule = (key) => modules.locator('[data-library-category="' + key + '"]').click();
assert.equal(await modules.locator('[data-library-category]:visible').count(), 7);
assert.equal(await modules.locator('[data-template-card]:visible').count(), 0);
assert.equal(await modules.locator('[data-template-card]').count(), 26);
await copyText.first().click();
await gallery.getByText('基础元素', {exact: true}).click();
await gallery.getByRole('button', {name: '插入分割线'}).click();
await moduleTab.press('ArrowRight');
assert.equal(await elementTab.getAttribute('aria-selected'), 'true');
assert.equal(await elements.locator('[data-library-category]:visible').count(), 4);
assert.equal(await elements.locator('[data-canvas-element]:visible').count(), 0);
const structural = elements.locator('[data-library-category=structure-elements]');
await structural.click();
assert.equal(await elements.locator('[data-library-category]:visible').count(), 0);
assert.equal(await elements.locator('[data-canvas-element]:visible').count(), 5);
await elements.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) => {
await elements.getByRole('button', {name: '插入留白'}).click();
await frame.locator('#fixtures .studio-spacer').waitFor();
await elements.getByRole('button', {name: '返回分类'}).click();
assert(await structural.evaluate((button) => button === document.activeElement));
await moduleTab.click();
const brokenPreviews = await modules.locator('[data-template-card] img').evaluateAll(async (images) => {
for (const image of images) image.loading = 'eager';
await Promise.all(images.map((image) => image.decode()));
return images.filter((image) => image.naturalWidth !== 768).length;
});
assert.equal(brokenPreviews, 0);
await gallery.locator('[data-template-filter=cover]').click();
assert.equal(await gallery.locator('[data-template-card]:visible').count(), 2);
await openModule('cover');
assert.equal(await modules.locator('[data-template-card]:visible').count(), 3);
const cover = gallery.locator('[data-template-preview=cover]');
await cover.hover();
const peek = gallery.locator('[data-template-peek]');
@@ -175,17 +207,26 @@ async function run(browser) {
await dialog.locator('[data-template-use]').click();
await frame.locator('section[id^=block-] h2').filter({hasText: '图文封面'}).waitFor();
await gallery.locator('[data-template-filter=""]').click();
const search = gallery.locator('[data-template-search]');
await backToModules();
await openModule('layout');
const search = modules.locator('[data-template-search]');
await search.fill('does-not-exist');
await gallery.locator('[data-template-empty]').waitFor({state: 'visible'});
await modules.locator('[data-template-empty]').waitFor({state: 'visible'});
await search.fill('双栏');
assert.equal(await gallery.locator('[data-template-card]:visible').count(), 1);
assert.equal(await modules.locator('[data-template-card]:visible').count(), 1);
await search.fill('重点提示');
await gallery.locator('[data-canvas-template=notice]').click();
await modules.locator('[data-template-empty]').waitFor({state: 'visible'});
await backToModules();
await openModule('details');
await modules.locator('[data-canvas-template=pricing]').click();
await frame.locator('.studio-pricing').waitFor();
await backToModules();
await openModule('content');
await search.fill('重点提示');
await modules.locator('[data-canvas-template=notice]').click();
await frame.locator('.studio-notice').waitFor();
await search.fill('分类文章');
await gallery.locator('[data-canvas-template=articles]').click();
await modules.locator('[data-canvas-template=articles]').click();
await frame.locator('section[id^=block-] h2').filter({hasText: '分类文章'}).waitFor();
await Promise.all([
@@ -202,6 +243,8 @@ async function run(browser) {
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();
await frame.locator('#fixtures .studio-spacer').waitFor();
await frame.locator('.studio-pricing').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);
@@ -219,10 +262,13 @@ async function run(browser) {
phonePage.on('pageerror', (error) => errors.push(error.message));
await phonePage.goto(editorPath);
const phoneGallery = phonePage.locator('[data-canvas-presets]');
await phoneGallery.locator('[data-template-filter=cover]').tap();
await phoneGallery.locator('[data-library-category=cover]').tap();
await phoneGallery.locator('[data-template-preview=banner]').tap();
await phoneGallery.locator('[data-template-dialog]').waitFor({state: 'visible'});
assert.equal(await phoneGallery.locator('[data-template-dialog] h2').textContent(), '横幅');
await phonePage.goto(editorPath + '#blocks');
assert.equal(await phoneGallery.getByRole('tab', {name: '图层'}).getAttribute('aria-selected'), 'true');
assert(await phoneGallery.locator('#blocks').evaluate((details) => details.open));
await phone.close();
await verifyArticleLibrary(browser, context, page, post, slug, feedId);
assert.deepEqual(errors, []);
@@ -372,7 +418,7 @@ async function verifyScopedArchive(context, admin, page, post, slug, feedId, cat
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
try {
await run(browser);
console.log('Passed Chromium canvas alignment, editor elements and modules, persistence, and scoped article archives.');
console.log('Passed Chromium dashboard, categorized library, canvas persistence, and scoped article archives.');
} finally {
await browser.close();
}