Răsfoiți Sursa

fix(mobile): match coach review student names by ID

彭峰 6 zile în urmă
părinte
comite
efb49ce286

+ 33 - 0
projects/xiaoshu-mobile/src/app/core/home-learning-modules.integration.spec.ts

@@ -8,6 +8,7 @@ import { Observable, of, Subject, throwError } from 'rxjs';
 import { CourseCenterPageComponent } from '../features/course-center/course-center-page.component';
 import { AppointmentPageComponent } from '../features/appointment/appointment-page.component';
 import { LearningPageComponent } from '../features/learning/learning-page.component';
+import { HomePageComponent } from '../features/home/home-page.component';
 import { routes } from '../app.routes';
 import { ApiService } from './api.service';
 import { ApiEnvelope, AppUser } from './models';
@@ -741,6 +742,38 @@ describe('home learning modules', () => {
     harness.fixture.detectChanges();
   });
 
+  it('matches coach review tasks to student names by ID when task name fields are blank', async () => {
+    user.set({ userId: 300, userName: 'coach', honeyName: '张老师', groupId: 3 });
+    session.groupId.set(3);
+    const api = TestBed.inject(ApiService) as unknown as LearningModulesApiService;
+    const response = new Subject<ApiEnvelope<unknown>>();
+    api.reviewPageResponse = response;
+    const harness = await RouterTestingHarness.create();
+    await harness.navigateByUrl('/pages/home/index');
+    response.next({ retcode: 1, result: {
+      items: [
+        { GeneralID: 102, yhid: 100, honeyName: '', Title: '旧姓名@复习', kywsj: '2025-07-19', fxzt: 0, xxjlid: 900 },
+        { GeneralID: 103, yhid: '101', honeyName: ' ', HoneyName: '', kywsj: '2025-07-15', fxzt: 0, xxjlid: 901 },
+      ],
+      students: [{ id: '101', name: '李同学', taskCount: 1 }, { id: '100', name: '张雅茜', taskCount: 1 }],
+      page: { itemCount: 2, pageCount: 1 },
+      summary: { total: 2, completed: 0, due: 2, today: 0, income: 0 }, dates: [],
+    } });
+    response.complete();
+    api.reviewPageResponse = null;
+    harness.fixture.detectChanges();
+    const names = Array.from(harness.routeNativeElement?.querySelectorAll('.coach-memory-copy strong') ?? []).map((node) => node.textContent);
+    expect(names).toEqual(['张雅茜', '李同学']);
+    const home = harness.fixture.debugElement.query(By.directive(HomePageComponent)).componentInstance as HomePageComponent;
+    expect(home.coachReviewStudent({ yhid: 102, honeyName: '', HoneyName: ' ', Title: '王同学@复习' })).toBe('王同学');
+    expect(home.coachReviewStudent({ yhid: 103, honeyName: '', Title: ' ' })).toBe('学员 103');
+    expect(home.coachReviewStudent({ honeyName: '' })).toBe('未关联学员');
+    (harness.routeNativeElement?.querySelectorAll('.coach-memory-list article > button')[1] as HTMLButtonElement).click();
+    await harness.fixture.whenStable();
+    expect(session.student()).toEqual(jasmine.objectContaining({ userId: 101, honeyName: '李同学' }));
+    expect(TestBed.inject(Router).url).toContain('/pages/stu/record?id=901&gid=103');
+  });
+
   it('keeps the complete point-reading flow available to coaches', async () => {
     user.set({ userId: 300, userName: 'coach', honeyName: '张老师', groupId: 3 });
     session.groupId.set(3);

+ 8 - 1
projects/xiaoshu-mobile/src/app/features/home/home-page.component.ts

@@ -85,7 +85,14 @@ export class HomePageComponent implements OnInit {
   }
 
   coachReviewStudent(item: Item): string {
-    return String(item['honeyName'] ?? item['HoneyName'] ?? item['Title'] ?? '关联学员').split('@')[0] || '关联学员';
+    const studentId = String(item['yhid'] ?? '').trim();
+    const student = this.reviewData()?.students?.find((entry) => String(entry.id) === studentId);
+    const names = [student?.name, item['honeyName'], item['HoneyName'], item['Title']];
+    for (const name of names) {
+      const displayName = String(name ?? '').split('@')[0].trim();
+      if (displayName) return displayName;
+    }
+    return studentId && studentId !== '0' ? `学员 ${studentId}` : '未关联学员';
   }
 
   coachReviewTitle(item: Item): string {