forked from laysense/laysense.cn
Add whole-page template collections and Caddy examples
This commit is contained in:
@@ -32,6 +32,7 @@ async function run(browser) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
await verifyPageTemplateDrawer(context, page, slug, csrf);
|
||||
await post('/admin/new-page', {slug, name: '画布测试页'});
|
||||
await page.goto('/admin');
|
||||
const dashboard = page.locator('[data-page-list]');
|
||||
@@ -294,6 +295,77 @@ async function run(browser) {
|
||||
await context.close();
|
||||
}
|
||||
|
||||
async function verifyPageTemplateDrawer(context, page, slug, csrf) {
|
||||
await page.goto('/admin/articles');
|
||||
assert.equal(await page.locator('[src="/assets/page-template-drawer.js"]').count(), 0);
|
||||
await page.goto('/admin');
|
||||
const opener = page.getByRole('button', {name: '整页模板'});
|
||||
await opener.click();
|
||||
const drawer = page.getByRole('dialog', {name: '整页模板'});
|
||||
const groups = drawer.locator('[data-template-group]:visible');
|
||||
assert.equal(await groups.count(), 3);
|
||||
const assertThumbnails = async (cards) => {
|
||||
assert(await cards.locator('img').evaluateAll(async (images) => {
|
||||
await Promise.all(images.map((image) => image.decode()));
|
||||
return images.length > 0 && images.every((image) => image.naturalWidth === 768);
|
||||
}));
|
||||
};
|
||||
await assertThumbnails(groups);
|
||||
for (const theme of ['cobalt', 'studio', 'dusk']) {
|
||||
await drawer.locator(`[data-template-group="${theme}"]`).click();
|
||||
const pages = drawer.locator('[data-page-template]:visible');
|
||||
assert.equal(await pages.count(), 2);
|
||||
await assertThumbnails(pages);
|
||||
await drawer.getByRole('button', {name: '返回套系'}).click();
|
||||
}
|
||||
await page.keyboard.press('Escape');
|
||||
await drawer.waitFor({state: 'hidden'});
|
||||
assert(await opener.evaluate((link) => link === document.activeElement));
|
||||
|
||||
await page.setViewportSize({width: 390, height: 844});
|
||||
await opener.click();
|
||||
await drawer.getByRole('button', {name: /Dusk/}).click();
|
||||
await drawer.getByRole('button', {name: '版本与动态'}).click();
|
||||
assert.equal((await drawer.boundingBox()).width, 390);
|
||||
const preview = drawer.getByRole('link', {name: '打开完整页面预览'});
|
||||
const response = await context.request.get(await preview.getAttribute('href'));
|
||||
assert.equal(response.status(), 200);
|
||||
assert.match(response.headers()['x-robots-tag'], /noindex/);
|
||||
assert.match(await response.text(), /theme-dusk/);
|
||||
await drawer.getByRole('button', {name: '返回套内页面'}).click();
|
||||
await drawer.getByRole('button', {name: '版本与动态'}).click();
|
||||
|
||||
const newSlug = slug.replace('studio-browser-', 'page-template-');
|
||||
await drawer.getByLabel('页面名称').fill('模板草稿测试');
|
||||
await drawer.getByLabel('网址标识').fill(newSlug);
|
||||
await drawer.getByRole('button', {name: '用此模板创建草稿'}).click();
|
||||
await page.waitForURL('**/admin/pages/' + newSlug);
|
||||
await page.setViewportSize({width: 1480, height: 960});
|
||||
assert.equal((await context.request.get('/' + newSlug)).status(), 404);
|
||||
const frame = page.frameLocator('iframe[title="可编辑页面画布"]');
|
||||
await frame.locator('main.theme-dusk').waitFor();
|
||||
const title = frame.locator('#release-notes h2');
|
||||
await title.fill('本周更新记录');
|
||||
await frame.locator('#latest-notes[data-studio-dynamic]').waitFor();
|
||||
await page.locator('#studio-page-settings [name=status]').selectOption('published');
|
||||
await page.getByRole('button', {name: '保存页面', exact: true}).first().click();
|
||||
await page.locator('[data-save-confirmation]').waitFor();
|
||||
|
||||
const published = await context.request.get('/' + newSlug);
|
||||
assert.equal(published.status(), 200);
|
||||
const html = await published.text();
|
||||
assert.match(html, /page-themes\.css/);
|
||||
assert.match(html, /本周更新记录/);
|
||||
assert.doesNotMatch(html, /page-template-drawer\.(?:js|css)/);
|
||||
assert.doesNotMatch(await (await context.request.get('/')).text(), /page-themes\.css/);
|
||||
const duplicate = await context.request.post('/admin/new-page', {
|
||||
form: {csrf, slug: newSlug, name: '重复地址', template: 'studio-case'},
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
});
|
||||
assert.equal(duplicate.status(), 422);
|
||||
assert.match(await (await context.request.get('/' + newSlug)).text(), /theme-dusk/);
|
||||
}
|
||||
|
||||
async function verifyArticleLibrary(browser, context, page, post, slug, feedId) {
|
||||
const category = String(Date.now());
|
||||
await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
|
||||
@@ -593,7 +665,7 @@ async function verifyDirectoryWidth(directory) {
|
||||
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
|
||||
try {
|
||||
await run(browser);
|
||||
console.log('Passed Chromium dashboard, template library, dynamic modules, homepage link reflow, scoped archives, and article deletion.');
|
||||
console.log('Passed Chromium dashboard, page and component templates, dynamic modules, homepage links, scoped archives, and article deletion.');
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user