|
|
@@ -329,6 +329,56 @@ describe('home learning modules', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ for (const role of [1,3]) {
|
|
|
+ it(`numbers learning records in reverse across pages and date filters for role ${role}`, async () => {
|
|
|
+ user.set({userId:role===3?300:100,groupId:role});session.groupId.set(role);
|
|
|
+ const api=TestBed.inject(ApiService), original=api.post.bind(api);
|
|
|
+ spyOn(TestBed.inject(LiveDataRefreshService),'watch').and.returnValue(()=>{});
|
|
|
+ spyOn(api,'post').and.callFake(((action:string,params:Record<string,unknown>={})=>{
|
|
|
+ if(action!=='app_learning_overview')return original(action,params);
|
|
|
+ const total=params['date']?2:26,offset=(Number(params['page'])-1)*20;
|
|
|
+ return of({retcode:0,result:{records:Array.from({length:Math.min(20,total-offset)},(_,i)=>({GeneralID:1000+offset+i,CreateTime:params['date']||'2026-11-12 12:00',con:'课程 '+(total-offset-i)})),courses:[],schedules:[],recordDateCounts:{},scheduleDateCounts:{},page:{itemCount:total,pageCount:Math.ceil(total/20)}}});
|
|
|
+ }) as typeof api.post);
|
|
|
+ const harness=await RouterTestingHarness.create('/pages/his/his');await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ const component=harness.fixture.debugElement.query(By.directive(StudyRecordsPageComponent)).componentInstance as StudyRecordsPageComponent;
|
|
|
+ const numbers=()=>Array.from(harness.routeNativeElement!.querySelectorAll('.learning-item .record-number'),node=>node.textContent!.trim());
|
|
|
+ expect(numbers()).toEqual(Array.from({length:20},(_,i)=>String(26-i)));
|
|
|
+ component.goToRecordPage(2);await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ expect(numbers()).toEqual(['6','5','4','3','2','1']);
|
|
|
+ component.selectDate('2026-11-12');await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ expect(numbers()).toEqual(['2','1']);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const role of [1,3]) {
|
|
|
+ it(`numbers training records across date groups and pages with newest first for role ${role}`, async () => {
|
|
|
+ user.set({userId:role===3?300:100,groupId:role});session.groupId.set(role);
|
|
|
+ const api=TestBed.inject(ApiService), original=api.post.bind(api);
|
|
|
+ spyOn(TestBed.inject(LiveDataRefreshService),'watch').and.returnValue(()=>{});
|
|
|
+ const calls:Record<string,unknown>[]=[];
|
|
|
+ const delayed = new Subject<ApiEnvelope<unknown>>();let retryPage = false;
|
|
|
+ spyOn(api,'post').and.callFake(((action:string,params:Record<string,unknown>={})=>{
|
|
|
+ if(action!=='app_companion_overview')return original(action,params);
|
|
|
+ calls.push(params);if(Number(params['page'])===2 && !retryPage)return delayed;
|
|
|
+ const total=26,offset=(Number(params['page'])-1)*20;
|
|
|
+ return of({retcode:0,result:{schedules:Array.from({length:Math.min(20,total-offset)},(_,i)=>({GeneralID:1000+offset+i,bxrq:'2026-11-'+String(26-offset-i).padStart(2,'0'),sdsd:'19:00',Title:'训练 '+(26-offset-i),dszt:30})),courses:[],studentOptions:[],dates:[],earningsSummary:{amount:0,pendingCount:0},page:{itemCount:26,pageCount:2}}});
|
|
|
+ }) as typeof api.post);
|
|
|
+ const harness=await RouterTestingHarness.create(role===3?'/pages/member/ke_xiao':'/pages/home/cart?csStatus=finished&csRange=all');
|
|
|
+ await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ const component=harness.fixture.debugElement.query(By.directive(CourseCenterPageComponent)).componentInstance as CourseCenterPageComponent;
|
|
|
+ const numbers=()=>Array.from(harness.routeNativeElement!.querySelectorAll('.schedule-list .record-number'),node=>node.textContent!.trim());
|
|
|
+ expect(calls[0]['history']).toBe(role===3);
|
|
|
+ expect(numbers()).toEqual(Array.from({length:20},(_,i)=>String(26-i)));
|
|
|
+ expect(harness.routeNativeElement!.querySelector('.schedule-copy strong')?.textContent).toContain('训练 26');
|
|
|
+ component.turnPage(1);harness.fixture.detectChanges();
|
|
|
+ expect(numbers()).toEqual(Array.from({length:20},(_,i)=>String(26-i)));
|
|
|
+ delayed.error(new Error('翻页失败'));await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ expect(numbers()).toEqual(Array.from({length:20},(_,i)=>String(26-i)));
|
|
|
+ retryPage=true;component.load(true,true);await harness.fixture.whenStable();harness.fixture.detectChanges();
|
|
|
+ expect(numbers()).toEqual(['6','5','4','3','2','1']);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
it('filters teacher history students before restoring a stale selection and uses server pagination', async () => {
|
|
|
user.set({userId:300, groupId:3}); session.groupId.set(3);
|
|
|
const watch = spyOn(TestBed.inject(LiveDataRefreshService), 'watch').and.returnValue(() => {});
|