Files
gym-manage/gym-manage-coach-uniapp/e2e/specs/coach-profile.spec.js
T

77 lines
2.3 KiB
JavaScript

const { launchMiniProgram, closeMiniProgram, sleep } = require('../helpers/automator');
const LoginPage = require('../pages/LoginPage');
const HomePage = require('../pages/HomePage');
const ProfilePage = require('../pages/ProfilePage');
let miniProgram;
let loginPage;
let homePage;
let profilePage;
describe('P2 - 教练个人中心测试', () => {
beforeAll(async () => {
miniProgram = await launchMiniProgram();
loginPage = new LoginPage(miniProgram);
homePage = new HomePage(miniProgram);
profilePage = new ProfilePage(miniProgram);
// 先完成登录
await loginPage.login('coach_test1', 'Test@123');
await loginPage.waitForLoginSuccess(20000);
await homePage.waitForLoad();
}, 120000);
afterAll(async () => {
await closeMiniProgram();
}, 30000);
test('从首页导航到个人中心', async () => {
await homePage.navigateToProfile();
const page = await miniProgram.currentPage();
expect(page.path).toContain('pages/profile/profile');
await profilePage.waitForLoad();
}, 20000);
test('个人中心应显示教练基本信息', async () => {
const info = await profilePage.getCoachInfo();
// 用户名应存在
expect(info.username).toBeTruthy();
// 教练 ID 应存在
expect(info.coachId).toBeTruthy();
}, 15000);
test('个人中心应显示业绩数据', async () => {
const perf = await profilePage.getPerformance();
// 授课量应存在
expect(perf.totalLessons).toBeDefined();
}, 15000);
test('个人中心违规记录区域应正常渲染', async () => {
// 获取违规次数,即使是 0 也是正常的
const count = await profilePage.getViolationCount();
expect(typeof count).toBe('number');
expect(count).toBeGreaterThanOrEqual(0);
}, 15000);
test('个人中心应包含退出登录按钮', async () => {
const page = await miniProgram.currentPage();
const logoutBtn = await page.$('.logout-btn');
expect(logoutBtn).not.toBeNull();
const btnText = await logoutBtn.text();
expect(btnText).toContain('退出登录');
}, 15000);
test('返回首页', async () => {
await profilePage.goBack();
const page = await miniProgram.currentPage();
// 应该回到首页
expect(page.path).toContain('pages/index/index');
}, 15000);
});