|
@@ -45,3 +45,22 @@ describe('ReadingSetupComponent', () => {
|
|
|
}) });
|
|
}) });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+describe('阅读类型和题材的随机选择',()=>{
|
|
|
|
|
+ async function screen(extra:Record<string,unknown>={}) {
|
|
|
|
|
+ const router=jasmine.createSpyObj<Router>('Router',['navigate','navigateByUrl']);router.navigate.and.resolveTo(true);
|
|
|
|
|
+ const cloud=jasmine.createSpyObj<ReadingCloudService>('ReadingCloudService',['ensureUser','updateUser'],{user:null});cloud.ensureUser.and.resolveTo({objectId:'learner',sessionToken:'r:local'});
|
|
|
|
|
+ const reading=jasmine.createSpyObj<EnglishReadingService>('EnglishReadingService',['findArticles','duplicateExists','countArticles']);reading.findArticles.and.resolveTo([]);reading.duplicateExists.and.resolveTo(false);reading.countArticles.and.resolveTo(0);
|
|
|
|
|
+ await TestBed.configureTestingModule({imports:[ReadingSetupComponent],providers:[
|
|
|
|
|
+ {provide:ActivatedRoute,useValue:{snapshot:{queryParamMap:convertToParamMap({studentId:'100',GeneralID:'201',wordList:'apple,river',level:'初二',...extra})}}},
|
|
|
|
|
+ {provide:Router,useValue:router},{provide:SessionService,useValue:{groupId:()=>3,user:()=>({userId:300,groupId:3}),student:()=>({userId:100,groupId:1,honeyName:'测试学员'})}},
|
|
|
|
|
+ {provide:PlatformService,useValue:jasmine.createSpyObj<PlatformService>('PlatformService',['toast'])},
|
|
|
|
|
+ ]}).overrideComponent(ReadingSetupComponent,{set:{providers:[{provide:ReadingCloudService,useValue:cloud},{provide:EnglishReadingService,useValue:reading}]}}).compileComponents();
|
|
|
|
|
+ const fixture=TestBed.createComponent(ReadingSetupComponent);fixture.detectChanges();await fixture.whenStable();fixture.detectChanges();return{fixture,c:fixture.componentInstance,router,reading};
|
|
|
|
|
+ }
|
|
|
|
|
+ it('新进入老师设置页时两个下拉框默认显示随机并保留可选项',async()=>{const{fixture,c}=await screen();expect(c.type).toBe('随机');expect(c.theme).toBe('随机');for(const name of ['type','theme']){const select=fixture.nativeElement.querySelector(`select[name=${name}]`) as HTMLSelectElement;expect(select.value).toBe('随机');expect(select.options.length).toBeGreaterThan(1);}});
|
|
|
|
|
+ it('每次生成独立抽取具体类型和题材,但表单保留随机模式',async()=>{const{c,router}=await screen();spyOn(Math,'random').and.returnValues(0,0,0.999,0.999);await c.start();expect(router.navigate.calls.mostRecent().args[1]?.queryParams).toEqual(jasmine.objectContaining({type:'记叙文',theme:'科技创新',studentId:100,sourceStudyId:'201'}));expect(c.type).toBe('随机');expect(c.theme).toBe('随机');await c.start();expect(router.navigate.calls.mostRecent().args[1]?.queryParams).toEqual(jasmine.objectContaining({type:'新闻报道',theme:'古代科技'}));expect(c.type).toBe('随机');expect(c.theme).toBe('随机');});
|
|
|
|
|
+ it('老师手动选择时只随机仍为随机的字段',async()=>{const{fixture,c,router}=await screen();const select=fixture.nativeElement.querySelector('select[name=type]') as HTMLSelectElement;select.value='说明文';select.dispatchEvent(new Event('change'));await fixture.whenStable();fixture.detectChanges();c.theme='随机';const random=spyOn(Math,'random').and.returnValue(0.999);await c.start();expect(random).toHaveBeenCalledTimes(1);expect(router.navigate.calls.mostRecent().args[1]?.queryParams).toEqual(jasmine.objectContaining({type:'说明文',theme:'古代科技'}));expect(c.type).toBe('说明文');expect(c.theme).toBe('随机');});
|
|
|
|
|
+ it('保留路由或旧打包参数明确指定的类型和题材',async()=>{const{c,router}=await screen({params:encodeURIComponent(JSON.stringify({type:'新闻报道',theme:'历史发展'}))});const random=spyOn(Math,'random');await c.start();expect(random).not.toHaveBeenCalled();expect(router.navigate.calls.mostRecent().args[1]?.queryParams).toEqual(jasmine.objectContaining({type:'新闻报道',theme:'历史发展'}));});
|
|
|
|
|
+ it('查重拦截后不把随机模式改成一次抽取结果',async()=>{const{c,router,reading}=await screen({type:'随机',theme:'随机'});reading.duplicateExists.and.resolveTo(true);spyOn(Math,'random').and.returnValues(0,0);await c.start();expect(router.navigate).not.toHaveBeenCalled();expect(c.type).toBe('随机');expect(c.theme).toBe('随机');});
|
|
|
|
|
+});
|