|
|
@@ -193,4 +193,35 @@ describe('ReadingExerciseComponent', () => {
|
|
|
}));
|
|
|
expect(reload).toHaveBeenCalled();
|
|
|
});
|
|
|
+ it('lets the reader close a generation error and return without another generation request', async () => {
|
|
|
+ const params = component.params;
|
|
|
+ fixture.detectChanges();await fixture.whenStable();
|
|
|
+ component.params = params;reading.createArticle.calls.reset();
|
|
|
+ reading.createArticle.and.rejectWith(new Error('模拟生成失败'));
|
|
|
+ await component.load();
|
|
|
+ fixture.detectChanges();
|
|
|
+ expect(component.dialog()?.action).toBe('retry');
|
|
|
+ (fixture.nativeElement.querySelector('[aria-label="关闭弹窗"]') as HTMLButtonElement).click();
|
|
|
+ fixture.detectChanges();
|
|
|
+ expect(fixture.nativeElement.querySelector('.result-backdrop')).toBeNull();
|
|
|
+ expect(component.error()).toBe('模拟生成失败');
|
|
|
+ expect(reading.createArticle).toHaveBeenCalledTimes(1);
|
|
|
+ (fixture.nativeElement.querySelector('[aria-label="返回原页面"]') as HTMLButtonElement).click();
|
|
|
+ await fixture.whenStable();
|
|
|
+ expect(router.navigateByUrl).toHaveBeenCalledWith('/pages/his/his?date=2026-09-10', {replaceUrl:true});
|
|
|
+ });
|
|
|
+
|
|
|
+ it('offers an exit instead of a retry loop when the generation service needs administrator attention', async () => {
|
|
|
+ const params = component.params;
|
|
|
+ fixture.detectChanges();await fixture.whenStable();
|
|
|
+ component.params = params;reading.createArticle.calls.reset();
|
|
|
+ reading.createArticle.and.rejectWith(new Error('阅读生成服务授权异常,请联系管理员处理'));
|
|
|
+ await component.load();fixture.detectChanges();
|
|
|
+ expect(component.dialog()?.action).toBe('back');
|
|
|
+ expect(fixture.nativeElement.querySelector('.result-dialog')?.textContent).not.toContain('立即重试');
|
|
|
+ document.dispatchEvent(new KeyboardEvent('keydown', {key:'Escape'}));fixture.detectChanges();
|
|
|
+ expect(component.dialog()).toBeNull();
|
|
|
+ expect(reading.createArticle).toHaveBeenCalledTimes(1);
|
|
|
+ });
|
|
|
+
|
|
|
});
|