|
|
@@ -1,4 +1,4 @@
|
|
|
-import { TestBed } from '@angular/core/testing';
|
|
|
+import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
|
import { ActivatedRoute, convertToParamMap, Router } from '@angular/router';
|
|
|
import { PlatformService } from '../../core/platform.service';
|
|
|
import { SessionService } from '../../core/session.service';
|
|
|
@@ -9,7 +9,7 @@ import { ReadingPdfComponent } from './reading-pdf.component';
|
|
|
|
|
|
describe('ReadingPdfComponent', () => {
|
|
|
const article: ReadingArticle = {
|
|
|
- objectId: 'article-1', type: 'reading', title: 'A story', content: 'Apple grows by the river.',
|
|
|
+ objectId: 'article-1', type: 'reading', title: 'A story', content: 'Apple grows by the river.', createdAt:'2026-10-04T04:00:00.000Z',
|
|
|
createOptions: { tpl: 'article', params: { wordList: ['apple'], count: 120, stage: '小学', level: '三年级', type: '记叙文', theme: '校园' } },
|
|
|
};
|
|
|
const questions: ReadingQuestion[] = Array.from({ length: 5 }, (_, index) => ({
|
|
|
@@ -27,7 +27,7 @@ describe('ReadingPdfComponent', () => {
|
|
|
await TestBed.configureTestingModule({
|
|
|
imports: [ReadingPdfComponent],
|
|
|
providers: [
|
|
|
- { provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ sid: article.objectId }), queryParamMap: convertToParamMap({}) } } },
|
|
|
+ { provide: ActivatedRoute, useValue: { snapshot: { paramMap: convertToParamMap({ sid: article.objectId }), queryParamMap: convertToParamMap({ name:'林同学' }) } } },
|
|
|
{ provide: Router, useValue: jasmine.createSpyObj<Router>('Router', ['navigate', 'navigateByUrl']) },
|
|
|
{ provide: SessionService, useValue: { groupId: () => 1, user: () => ({ userId: 7 }), student: () => null } },
|
|
|
{ provide: PlatformService, useValue: jasmine.createSpyObj<PlatformService>('PlatformService', ['toast']) },
|
|
|
@@ -38,20 +38,32 @@ describe('ReadingPdfComponent', () => {
|
|
|
{ provide: EnglishReadingService, useValue: reading },
|
|
|
] },
|
|
|
}).compileComponents();
|
|
|
- const component = TestBed.createComponent(ReadingPdfComponent).componentInstance;
|
|
|
+ const fixture: ComponentFixture<ReadingPdfComponent> = TestBed.createComponent(ReadingPdfComponent);
|
|
|
+ const component = fixture.componentInstance;
|
|
|
await component.ngOnInit();
|
|
|
- return component;
|
|
|
+ return { component, fixture };
|
|
|
}
|
|
|
|
|
|
it('refuses direct PDF access while the cloud has only one question', async () => {
|
|
|
- const component = await setup(questions.slice(0, 1));
|
|
|
+ const { component } = await setup(questions.slice(0, 1));
|
|
|
expect(component.questions()).toEqual([]);
|
|
|
expect(component.error()).toContain('题目尚未完整保存');
|
|
|
});
|
|
|
|
|
|
it('loads five saved questions without requiring an online answer log', async () => {
|
|
|
- const component = await setup(questions);
|
|
|
+ const { component } = await setup(questions);
|
|
|
expect(component.error()).toBe('');
|
|
|
expect(component.questions().length).toBe(5);
|
|
|
});
|
|
|
+
|
|
|
+ it('includes the learner name and creation date before grade in printed content', async () => {
|
|
|
+ const { fixture } = await setup(questions);
|
|
|
+ fixture.detectChanges();
|
|
|
+ await fixture.whenStable();
|
|
|
+ fixture.detectChanges();
|
|
|
+ const metadata = (fixture.nativeElement as HTMLElement).querySelector('.document-meta');
|
|
|
+ expect(metadata?.textContent).toContain('学生:林同学');
|
|
|
+ expect(metadata?.textContent).toContain('生成日期:2026-10-04');
|
|
|
+ expect(metadata?.textContent?.indexOf('林同学')).toBeLessThan(metadata?.textContent?.indexOf('三年级') ?? 0);
|
|
|
+ });
|
|
|
});
|