Files
tuhui.cloud/frontend/cypress/e2e/works.cy.js
2026-03-08 19:28:32 +08:00

71 lines
2.0 KiB
JavaScript

describe('作品浏览测试', () => {
beforeEach(() => {
cy.visit('/');
});
it('应该显示作品列表', () => {
// 等待作品列表加载
cy.get('.work-card', { timeout: 15000 }).should('have.length.at.least', 1);
// 获取作品数量
cy.get('.work-card').then($cards => {
cy.log(`✅ 作品列表测试通过 - 共 ${$cards.length} 个作品`);
});
});
it('应该能够查看作品详情', () => {
// 等待作品列表加载
cy.get('.work-card', { timeout: 15000 }).should('exist');
// 点击第一个作品
cy.get('.work-card').first().click();
// 等待详情页加载
cy.url().should('include', '/detail/');
cy.get('.work-detail-page', { timeout: 10000 }).should('be.visible');
// 验证标题存在
cy.get('h1, h2').should('exist');
// 获取作品标题
cy.get('h1, h2').first().invoke('text').then(title => {
cy.log(`✅ 作品详情测试通过 - 作品: ${title.trim()}`);
});
});
it('应该显示作品信息', () => {
// 进入作品详情页
cy.get('.work-card', { timeout: 15000 }).first().click();
cy.wait(2000);
// 验证作品信息显示
cy.get('.work-detail-page').should('be.visible');
// 验证关键元素
cy.get('.work-title').should('exist');
cy.get('.download-btn').should('exist');
cy.log('✅ 作品信息显示测试通过');
});
it('应该显示相关作品', () => {
// 进入作品详情页
cy.get('.work-card', { timeout: 15000 }).first().click();
cy.wait(2000);
// 向下滚动查看相关作品
cy.scrollTo('bottom', { duration: 1000 });
cy.wait(1000);
// 验证相关作品存在(如果有的话)
cy.get('body').then($body => {
if ($body.find('.related-works, .similar-works').length > 0) {
cy.get('.related-works, .similar-works').should('be.visible');
cy.log('✅ 相关作品显示测试通过');
} else {
cy.log('✅ 相关作品功能未实现(跳过)');
}
});
});
});