Add canvas element tools and categorized article editing
This commit is contained in:
+132
-6
@@ -38,6 +38,7 @@ async function run(browser) {
|
||||
version: '0', title: '媒体和链接', lead: '', style: 'plain',
|
||||
body: '<p><img src="/assets/favicon.png" alt="示例图片" width="96"></p>'
|
||||
+ '<p><a href="/services">示例链接</a></p>'
|
||||
+ '<p id="copy-fixture">待复制段落</p><p>待删除段落</p>'
|
||||
+ '<video controls width="260" preload="none"><source src="/assets/original/drag-in-components.mp4"></video>'
|
||||
+ '<audio controls src="/assets/original/drag-in-components.mp4" preload="none"></audio>',
|
||||
});
|
||||
@@ -46,7 +47,7 @@ async function run(browser) {
|
||||
const version = await page.locator('#studio-page-settings [name=version]').inputValue();
|
||||
await post(editorPath, {
|
||||
version, name: '画布测试页', status: 'draft', title: '画布测试页',
|
||||
description: '', heading: '画布测试页', accent: '', lead: '',
|
||||
description: '', heading: '画布测试页', accent: '', lead: '待删除的首屏简介',
|
||||
image: '/assets/original/home-hero.webp', alt: '首屏示例', image_scale: '0',
|
||||
});
|
||||
await page.reload();
|
||||
@@ -59,8 +60,17 @@ async function run(browser) {
|
||||
await image.click();
|
||||
await sizing.waitFor({state: 'visible'});
|
||||
assert.equal(await image.getAttribute('data-studio-selected'), '');
|
||||
await sizing.locator('[data-media-width]').selectOption('50');
|
||||
assert.match(await image.getAttribute('class'), /studio-media-50/);
|
||||
const handle = page.getByRole('slider', {name: '媒体宽度'});
|
||||
const initial = await image.boundingBox();
|
||||
const grip = await handle.boundingBox();
|
||||
await page.mouse.move(grip.x + grip.width / 2, grip.y + grip.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(grip.x + grip.width / 2 + 145, grip.y + grip.height / 2, {steps: 8});
|
||||
assert((await image.boundingBox()).width > initial.width + 100);
|
||||
await page.mouse.up();
|
||||
const imageSize = await image.getAttribute('class');
|
||||
assert.match(imageSize, /studio-media-\d+/);
|
||||
assert.notEqual(imageSize, 'studio-media-100');
|
||||
await image.dblclick();
|
||||
await properties.waitFor({state: 'visible'});
|
||||
assert.equal(await properties.locator('h2').textContent(), '正文图片');
|
||||
@@ -73,11 +83,15 @@ async function run(browser) {
|
||||
await hero.click();
|
||||
await sizing.waitFor({state: 'visible'});
|
||||
assert.equal(await hero.getAttribute('data-studio-selected'), '');
|
||||
await handle.press('ArrowLeft');
|
||||
assert.equal(await page.locator('[name=image_scale]').inputValue(), '99');
|
||||
await sizing.locator('[data-replace-media]').click();
|
||||
assert.equal(await properties.locator('h2').textContent(), '首屏图片');
|
||||
await closeProperties();
|
||||
|
||||
const tools = page.getByRole('group', {name: '所选元素'});
|
||||
await frame.locator('#fixtures a').click();
|
||||
await tools.getByRole('button', {name: '属性'}).click();
|
||||
await properties.waitFor({state: 'visible'});
|
||||
assert.equal(await properties.locator('h2').textContent(), '正文链接');
|
||||
await properties.locator('[name=url]').fill('/articles');
|
||||
@@ -92,9 +106,22 @@ async function run(browser) {
|
||||
await closeProperties();
|
||||
}
|
||||
|
||||
const copyText = frame.locator('#fixtures').getByText('待复制段落', {exact: true});
|
||||
await copyText.click();
|
||||
await tools.getByRole('button', {name: '复制'}).click();
|
||||
assert.equal(await copyText.count(), 2);
|
||||
assert.equal(await frame.locator('#copy-fixture').count(), 1);
|
||||
const oldParagraph = frame.getByText('待删除段落', {exact: true});
|
||||
await oldParagraph.click();
|
||||
await tools.getByRole('button', {name: '删除'}).click();
|
||||
assert.equal(await oldParagraph.count(), 0);
|
||||
await frame.getByText('待删除的首屏简介', {exact: true}).click();
|
||||
await tools.getByRole('button', {name: '删除'}).click();
|
||||
assert.equal(await page.locator('[name=lead]').inputValue(), '');
|
||||
|
||||
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(), 13);
|
||||
assert.equal(await gallery.locator('[data-template-card]').count(), 14);
|
||||
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()));
|
||||
@@ -122,6 +149,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=articles]').click();
|
||||
await frame.locator('section[id^=block-] h2').filter({hasText: '分类文章'}).waitFor();
|
||||
|
||||
await Promise.all([
|
||||
page.waitForResponse((response) => response.url().endsWith(editorPath) && response.request().method() === 'POST' && response.ok()),
|
||||
@@ -131,6 +161,15 @@ 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.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);
|
||||
assert.equal(await oldParagraph.count(), 0);
|
||||
assert.equal(await page.locator('[name=lead]').inputValue(), '');
|
||||
const feedSection = frame.locator('section[id^=block-]').filter({hasText: '分类文章'});
|
||||
const feedId = await feedSection.getAttribute('id');
|
||||
await feedSection.locator('.article-list').waitFor();
|
||||
|
||||
const phone = await browser.newContext({
|
||||
baseURL, viewport: {width: 390, height: 844}, isMobile: true, hasTouch: true,
|
||||
@@ -144,16 +183,103 @@ async function run(browser) {
|
||||
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(), '横幅');
|
||||
assert.deepEqual(errors, []);
|
||||
await phone.close();
|
||||
await verifyArticleLibrary(browser, context, page, post, slug, feedId);
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
}
|
||||
|
||||
async function verifyArticleLibrary(browser, context, page, post, slug, feedId) {
|
||||
const category = slug + '-category';
|
||||
await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
|
||||
const articleSlug = slug + '-article';
|
||||
await page.goto('/admin/articles/new');
|
||||
const editor = page.locator('[data-editor-host]');
|
||||
const markdown = editor.locator('.toastui-editor-md-container .ProseMirror');
|
||||
const preview = editor.locator('.toastui-editor-md-preview');
|
||||
await markdown.waitFor();
|
||||
await preview.waitFor();
|
||||
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=status]').selectOption('published');
|
||||
await markdown.fill('**Markdown 分屏**');
|
||||
await preview.locator('strong').getByText('Markdown 分屏').waitFor();
|
||||
await page.getByRole('button', {name: '保存文章'}).click();
|
||||
await page.waitForURL(/\/admin\/articles\/\d+/);
|
||||
const articleAdmin = new URL(page.url()).pathname;
|
||||
const publishedPath = '/articles/' + articleSlug;
|
||||
const sourcePage = await context.newPage();
|
||||
await sourcePage.goto(publishedPath);
|
||||
assert.equal(await sourcePage.locator('[itemprop=articleSection]').count(), 2);
|
||||
await sourcePage.locator('[itemprop=articleBody] strong').getByText('Markdown 分屏').waitFor();
|
||||
await page.goto(articleAdmin);
|
||||
await editor.locator('.toastui-editor-mode-switch').getByText('所见即所得', {exact: true}).click();
|
||||
const rich = editor.locator('.toastui-editor-ww-container .ProseMirror');
|
||||
await rich.waitFor();
|
||||
await rich.press('End');
|
||||
await page.keyboard.insertText(' 富文本');
|
||||
await page.getByRole('button', {name: '从媒体库插入图片'}).click();
|
||||
await page.locator('[data-media-query]').fill('favicon.png');
|
||||
page.once('dialog', (dialog) => dialog.accept('媒体库图片'));
|
||||
await page.locator('.picker-item', {hasText: 'favicon.png'}).click();
|
||||
await rich.locator('img[alt="媒体库图片"]').waitFor();
|
||||
await page.getByRole('button', {name: '保存文章'}).click();
|
||||
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'});
|
||||
await page.reload();
|
||||
await rich.waitFor();
|
||||
assert.equal(await page.locator('[name=body_format]').inputValue(), 'html');
|
||||
await sourcePage.reload();
|
||||
assert.match(await sourcePage.locator('[itemprop=articleBody]').textContent(), /Markdown 分屏 富文本/);
|
||||
await sourcePage.locator('[itemprop=articleBody] img[alt="媒体库图片"]').waitFor();
|
||||
|
||||
const sectionPath = '/admin/pages/' + slug + '/' + feedId;
|
||||
await page.goto(sectionPath);
|
||||
await page.locator('[name=feed_mode]').selectOption('merged');
|
||||
await page.locator('[name="feed_categories[]"][value=announcement]').uncheck();
|
||||
await page.locator('[name="feed_categories[]"][value=product]').uncheck();
|
||||
await page.locator('[name="feed_categories[]"][value="' + category + '"]').check();
|
||||
await page.getByRole('button', {name: '保存区块'}).click();
|
||||
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'});
|
||||
let contentVersion = await page.locator('[name=version]').inputValue();
|
||||
assert.equal(contentVersion, '1');
|
||||
const canvasPath = '/admin/pages/' + slug + '/preview';
|
||||
await sourcePage.goto(canvasPath);
|
||||
const feed = sourcePage.locator('#' + feedId + ' .article-feed');
|
||||
assert.equal(await feed.locator('a[href="' + publishedPath + '"]').count(), 1);
|
||||
assert.equal(await feed.getByRole('tab').count(), 0);
|
||||
|
||||
await page.locator('[name=feed_mode]').selectOption('tabs');
|
||||
await page.getByRole('button', {name: '保存区块'}).click();
|
||||
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'});
|
||||
contentVersion = await page.locator('[name=version]').inputValue();
|
||||
assert.equal(contentVersion, '2');
|
||||
await sourcePage.reload();
|
||||
const customTab = feed.getByRole('tab', {name: '自定义测试分类'});
|
||||
await customTab.waitFor();
|
||||
await feed.getByRole('tab', {name: '新闻'}).press('ArrowRight');
|
||||
assert.equal(await customTab.getAttribute('aria-selected'), 'true');
|
||||
assert.equal(await feed.getByRole('tabpanel').count(), 1);
|
||||
assert.equal(await feed.locator('a[href="' + publishedPath + '"]:visible').count(), 1);
|
||||
|
||||
const noJS = await browser.newContext({baseURL, javaScriptEnabled: false, storageState: await context.storageState()});
|
||||
const noJSPage = await noJS.newPage();
|
||||
await noJSPage.goto(canvasPath);
|
||||
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 sourcePage.goto('/services');
|
||||
await sourcePage.locator('.catalog-card').first().waitFor();
|
||||
await sourcePage.goto('/network');
|
||||
assert.equal(await sourcePage.locator('.network-group').count(), 2);
|
||||
await sourcePage.close();
|
||||
}
|
||||
|
||||
(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, and persistence.');
|
||||
console.log('Passed Chromium canvas media/link interactions, template gallery, persistence, and the article library.');
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user