Fix course-package:610 flaky — use expect.poll for post-save API check

Replace fixed waitForTimeout(2000) with expect.poll({ timeout: 15_000 })
so the API verification retries until the created package and its item
association are queryable. CI is slower than local, causing false failures.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 22:09:38 +08:00
parent 92cce7612e
commit a2b7825188
2 changed files with 30 additions and 24 deletions
+22 -20
View File
@@ -708,27 +708,29 @@ test.describe('音乐教室端(huike-front)课包 UI', () => {
await page.getByText('保存').click();
// ---- Verify via API that package was created with this group ----
await page.waitForTimeout(2000);
const myRes = await request.get(
`${kcBase}/api/v1/clazz/course-package/my-packages?page=1&page_size=50`,
{ headers },
);
expect(myRes.ok()).toBeTruthy();
const myBody = await myRes.json();
const myList: any[] = myBody.d?.[0] ?? [];
const newPkg = myList.find((p: any) => p.package_name === pkgName);
expect(newPkg, '创建的课包应出现在我的课包列表中').toBeTruthy();
createdPkgId = newPkg.id;
// Use poll to retry — save may not be immediately reflected on CI
await expect(async () => {
const myRes = await request.get(
`${kcBase}/api/v1/clazz/course-package/my-packages?page=1&page_size=50`,
{ headers },
);
expect(myRes.ok()).toBeTruthy();
const myBody = await myRes.json();
const myList: any[] = myBody.d?.[0] ?? [];
const newPkg = myList.find((p: any) => p.package_name === pkgName);
expect(newPkg, '创建的课包应出现在我的课包列表中').toBeTruthy();
createdPkgId = newPkg!.id;
const itemsRes = await request.get(
`${kcBase}/api/v1/clazz/course-package/item/list/${createdPkgId}`,
{ headers },
);
expect(itemsRes.ok()).toBeTruthy();
const itemsBody = await itemsRes.json();
const items: any[] = itemsBody.d ?? [];
const matched = items.some((g: any) => g.course_group_id === groupId);
expect(matched, '保存后课包应包含选中的课节分组').toBe(true);
const itemsRes = await request.get(
`${kcBase}/api/v1/clazz/course-package/item/list/${createdPkgId}`,
{ headers },
);
expect(itemsRes.ok()).toBeTruthy();
const itemsBody = await itemsRes.json();
const items: any[] = itemsBody.d ?? [];
const matched = items.some((g: any) => g.course_group_id === groupId);
expect(matched, '保存后课包应包含选中的课节分组').toBe(true);
}).toPass({ timeout: 15_000 });
} finally {
// ---- Cleanup ----
if (createdPkgId) {