You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

94 lines
5.3 KiB

const assert = require('node:assert/strict');
const { chromium } = require('playwright');
const base = 'http://127.0.0.1:4173/pages';
(async () => {
const browser = await chromium.launch({ channel: 'msedge', headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, locale: 'zh-CN' });
const errors = [];
page.on('pageerror', (error) => errors.push(error.message));
page.on('dialog', (dialog) => dialog.accept());
await page.goto(`${base}/login.html`);
await page.evaluate(() => window.YouthomeLocal.reset());
await page.goto(`${base}/login.html`);
await page.locator('#panel-password input[type="tel"]').fill('13800000000');
await page.locator('#panel-password input[type="password"]').fill('qinghe123');
await page.locator('#panel-password .btn-primary').click();
await page.waitForURL('**/feed.html');
// ---------- 真实动态详情:评论、点赞评论、回复评论 ----------
await page.goto(`${base}/post-detail.html?moment=demo-moment-1`);
await page.locator('html:not(.notification-route-pending)').waitFor();
await page.waitForTimeout(800);
assert.equal(await page.locator('.comment-list .comment-item').count(), 1, '示例动态应有 1 条评论');
assert.equal(await page.locator('.comment-list .reply-item').count(), 1, '该评论下应有 1 条回复');
// 发一条新评论
await page.locator('.comment-input').fill('评论功能回归测试');
await page.locator('.btn-send').click();
await page.locator('.web-toast', { hasText: '评论已发布' }).waitFor({ timeout: 8000 });
await page.waitForTimeout(400);
assert.equal(await page.locator('.comment-list .comment-item').count(), 2, '新评论应出现在列表里');
const mine = page.locator('.comment-list .comment-item').first();
assert.ok((await mine.innerText()).includes('评论功能回归测试'), '新评论内容应正确');
// 给评论点赞
const likeBtn = mine.locator('.like-btn');
await likeBtn.click();
await page.waitForFunction(() => {
const node = document.querySelector('.comment-list .comment-item .like-btn');
return node && node.textContent.replace(/[^0-9]/g, '') === '1';
}, null, { timeout: 8000 });
assert.ok(await mine.locator('.like-btn').evaluate((n) => n.classList.contains('liked')), '点赞后应有 liked 状态');
// 回复这条评论
await mine.locator('.comment-meta span', { hasText: '回复' }).click();
await page.waitForTimeout(300);
const chip = page.locator('.web-reply-chip');
assert.ok(await chip.isVisible(), '回复时应出现回复提示条');
assert.ok((await chip.innerText()).includes('正在回复'), '提示条应显示正在回复谁');
await page.locator('.comment-input').fill('回复一下自己的评论');
await page.locator('.btn-send').click();
await page.locator('.web-toast', { hasText: '回复已发布' }).waitFor({ timeout: 8000 });
await page.waitForTimeout(400);
assert.equal(await page.locator('.comment-list .comment-item').count(), 2, '回复不应新增顶级评论');
assert.ok((await mine.innerText()).includes('回复一下自己的评论'), '回复应出现在该评论下方');
assert.equal(await mine.locator('.reply-item').count(), 1, '该评论下应新增 1 条回复');
assert.ok(!(await chip.isVisible()), '发送后回复提示条应自动收起');
// 回复提示可以取消
await mine.locator('.comment-meta span', { hasText: '回复' }).click();
await page.waitForTimeout(200);
await chip.locator('button').click();
await page.waitForTimeout(200);
assert.ok(!(await chip.isVisible()), '点击取消后提示条应隐藏');
// ---------- 示例详情页:静态评论的点赞、回复与发送 ----------
await page.goto(`${base}/post-detail.html`);
await page.waitForTimeout(1000);
const staticList = page.locator('.comment-list');
const beforeCount = await staticList.locator('.comment-item').count();
const firstComment = staticList.locator('.comment-item').first();
const likeBefore = Number((await firstComment.locator('.like-btn').innerText()).replace(/[^0-9]/g, ''));
await firstComment.locator('.like-btn').click();
await page.waitForTimeout(300);
const likeAfter = Number((await firstComment.locator('.like-btn').innerText()).replace(/[^0-9]/g, ''));
assert.equal(likeAfter, likeBefore - 1, '已点赞的示例评论点一下应取消并减少计数');
await firstComment.locator('.comment-meta span', { hasText: '回复' }).click();
await page.waitForTimeout(300);
assert.ok(await page.locator('.web-reply-chip').isVisible(), '示例页回复也应出现提示条');
assert.ok(await page.locator('.comment-input').evaluate((node) => node === document.activeElement), '回复时应聚焦输入框');
await page.locator('.comment-input').fill('示例页评论回归');
await page.locator('.btn-send').click();
await page.waitForTimeout(500);
assert.equal(await staticList.locator('.comment-item').count(), beforeCount + 1, '示例页发送评论后应真的出现在列表里');
assert.ok((await staticList.locator('.comment-item').last().innerText()).includes('示例页评论回归'), '示例页新评论内容应正确');
assert.deepEqual(errors, []);
await browser.close();
console.log('comment like and reply passed in Edge');
})().catch((error) => { console.error(error); process.exitCode = 1; });