Просмотр исходного кода

Match learning record course titles to companion center

彭峰 2 недель назад
Родитель
Сommit
74dd80555f

+ 4 - 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 { StudyRecordsPageComponent } from '../features/study-records/study-records-page.component';
 import { HomePageComponent } from '../features/home/home-page.component';
 import { routes } from '../app.routes';
 import { ApiService } from './api.service';
@@ -751,6 +752,9 @@ describe('home learning modules', () => {
     const currentLearningCard = harness.routeNativeElement?.querySelector('.current-learning-card') as HTMLElement;
     const learningRecordCard = harness.routeNativeElement?.querySelector('.learning-record-card') as HTMLElement;
     expect(currentLearningCard.textContent).toContain('我的学习内容');
+    const records = harness.fixture.debugElement.query(By.directive(StudyRecordsPageComponent)).componentInstance as StudyRecordsPageComponent;
+    expect(records.courseTitle({ Title: '单词课|高中@人教版2022年录', Title2: '人教版2022年录' })).toBe('【高中】人教版2022年录');
+    expect(records.courseTitle({ Title: '单词课|初中@人教版2024年9月录', Title2: '人教版2024年9月录' })).toBe('【初中】人教版2024年9月录');
     expect(currentLearningCard.querySelectorAll('.current-learning-list button').length).toBe(2);
     expect((currentLearningCard.querySelectorAll('.current-learning-list button')[1] as HTMLButtonElement).disabled).toBeFalse();
     expect(currentLearningCard.compareDocumentPosition(learningRecordCard) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();

+ 12 - 5
projects/xiaoshu-mobile/src/app/features/study-records/study-records-page.component.ts

@@ -262,11 +262,18 @@ export class StudyRecordsPageComponent implements OnInit, OnDestroy {
 
   courseCategory(item: Item): string { return String(item['categoryName'] || ({word:'单词课',trial:'体验课',primary_writing:'小学语法写作课',middle_writing:'中学语法写作课',high_writing:'高中语法写作课',word_self_study:'单词自学课'} as Record<string,string>)[String(item['categoryKey'])] || ''); }
   courseTitle(item: Item): string {
-    const title = String(item['Title2'] ?? item['Title'] ?? '课程内容');
-    if (item['Title2'] || !title.includes('@')) return title;
-    const parts = title.split('@');
-    const first = parts[0].slice(parts[0].lastIndexOf('|') + 1);
-    return `【${first}】${parts.at(-1) ?? ''}`;
+    const sourceTitle = String(item['Title'] ?? '').trim();
+    if (sourceTitle.includes('@')) {
+      const parts = sourceTitle.split('@');
+      const stage = parts[0].slice(parts[0].lastIndexOf('|') + 1).trim();
+      const name = String(parts.at(-1) ?? '').trim();
+      if (stage && name) return `【${stage}】${name}`;
+      if (name) return name;
+    }
+    const joinedTitle = String(item['Title2'] ?? '').trim();
+    if (joinedTitle) return joinedTitle;
+    const assignedUnit = this.assignedUnits(item)[0];
+    return assignedUnit ? `${assignedUnit.name}学习内容` : '已绑定学习内容';
   }
 
   courseHint(item: Item): string {