|
|
@@ -456,10 +456,10 @@ describe('home learning modules', () => {
|
|
|
const api = TestBed.inject(ApiService) as unknown as LearningModulesApiService;
|
|
|
const get = api.get.bind(api);
|
|
|
spyOn(api, 'get').and.callFake((action, params) => action === 'e_words_list'
|
|
|
- ? of({ retcode: 1, result: [
|
|
|
- { GeneralID: 601, Title: 'tend@张雅茜', xxcs: 0, detail: [{ GeneralID: 701, Title: 'tend', sy: '照顾' }] },
|
|
|
- { GeneralID: 602, Title: 'prepare@张雅茜', xxcs: 2, detail: [{ GeneralID: 702, Title: 'prepare', sy: '准备' }] },
|
|
|
- ], page: { itemCount: 2, pageCount: 1, pageIndex: 1, pageSize: 100 } } as ApiEnvelope<any>)
|
|
|
+ ? of({ retcode: 1, result: params?.['learningStatus'] === 'completed'
|
|
|
+ ? [{ GeneralID: 602, Title: 'prepare@张雅茜', xxcs: 2, detail: [{ GeneralID: 702, Title: 'prepare', sy: '准备' }] }]
|
|
|
+ : [{ GeneralID: 601, Title: 'tend@张雅茜', xxcs: 0, detail: [{ GeneralID: 701, Title: 'tend', sy: '照顾' }] }],
|
|
|
+ page: { itemCount: 1, pendingCount: 1, completedCount: 1, pageCount: 1, pageIndex: 1, pageSize: 30 } } as ApiEnvelope<any>)
|
|
|
: get(action, params));
|
|
|
const harness = await RouterTestingHarness.create();
|
|
|
await harness.navigateByUrl('/pages/member/starshop');
|
|
|
@@ -481,6 +481,44 @@ describe('home learning modules', () => {
|
|
|
expect(harness.routeNativeElement?.querySelector('.pending-column .word-select-list > button.selected')).not.toBeNull();
|
|
|
});
|
|
|
|
|
|
+ it('shows 30 wordbook words per page while counting every learning status', async () => {
|
|
|
+ const api = TestBed.inject(ApiService) as unknown as LearningModulesApiService;
|
|
|
+ const get = api.get.bind(api);
|
|
|
+ const pending = Array.from({ length: 65 }, (_, index) => ({ GeneralID: 601 + index, xxcs: 0, detail: [{ GeneralID: 701 + index, Title: `pending-${index + 1}` }] }));
|
|
|
+ const completed = Array.from({ length: 7 }, (_, index) => ({ GeneralID: 801 + index, xxcs: 1, detail: [{ GeneralID: 901 + index, Title: `completed-${index + 1}` }] }));
|
|
|
+ const requests: Record<string, unknown>[] = [];
|
|
|
+ spyOn(api, 'get').and.callFake((action, params) => {
|
|
|
+ if (action !== 'e_words_list') return get(action, params);
|
|
|
+ requests.push(params ?? {});
|
|
|
+ const rows = params?.['learningStatus'] === 'completed' ? completed : pending;
|
|
|
+ const page = Number(params?.['cpage']);
|
|
|
+ const size = Number(params?.['psize']);
|
|
|
+ return of({ retcode: 1, result: rows.slice((page - 1) * size, page * size),
|
|
|
+ page: { itemCount: rows.length, pendingCount: pending.length, completedCount: completed.length,
|
|
|
+ pageCount: Math.ceil(rows.length / size), pageIndex: page, pageSize: size } } as ApiEnvelope<any>);
|
|
|
+ });
|
|
|
+ const harness = await RouterTestingHarness.create();
|
|
|
+ await harness.navigateByUrl('/pages/member/starshop');
|
|
|
+ harness.fixture.detectChanges();
|
|
|
+ const view = () => harness.routeNativeElement!;
|
|
|
+ const rows = () => view().querySelectorAll('.pending-column .word-select-list > button');
|
|
|
+ expect(requests[0]).toEqual(jasmine.objectContaining({ learningStatus: 'pending', cpage: 1, psize: 30 }));
|
|
|
+ expect(rows().length).toBe(30);
|
|
|
+ expect(view().querySelectorAll('.word-selection-tabs b')[0].textContent).toContain('65');
|
|
|
+ expect(view().querySelectorAll('.word-selection-tabs b')[1].textContent).toContain('7');
|
|
|
+ (rows()[0] as HTMLButtonElement).click();
|
|
|
+ (view().querySelectorAll('.mobile-pagination button')[1] as HTMLButtonElement).click();
|
|
|
+ harness.fixture.detectChanges();
|
|
|
+ expect(requests[1]).toEqual(jasmine.objectContaining({ learningStatus: 'pending', cpage: 2, psize: 30 }));
|
|
|
+ expect(rows().length).toBe(30);
|
|
|
+ expect(view().querySelector('.mobile-pagination')?.textContent).toContain('第 2 / 3 页');
|
|
|
+ (view().querySelectorAll('.word-selection-tabs button')[1] as HTMLButtonElement).click();
|
|
|
+ harness.fixture.detectChanges();
|
|
|
+ expect(requests[2]).toEqual(jasmine.objectContaining({ learningStatus: 'completed', cpage: 1, psize: 30 }));
|
|
|
+ expect(view().querySelectorAll('.completed-column .word-select-list > button').length).toBe(7);
|
|
|
+ expect(view().querySelector('.selection-header strong')?.textContent).toContain('已选 1 个单词');
|
|
|
+ });
|
|
|
+
|
|
|
it('saves completed wordbook study before showing the word in the learned tab', async () => {
|
|
|
const prefix = 'xiaoshu.learning.100.100.practice.';
|
|
|
const word = { GeneralID: 701, Title: 'tend', sy: '照顾' };
|
|
|
@@ -491,7 +529,12 @@ describe('home learning modules', () => {
|
|
|
const api = TestBed.inject(ApiService) as unknown as LearningModulesApiService;
|
|
|
const get = api.get.bind(api);
|
|
|
spyOn(api, 'get').and.callFake((action, params) => action === 'e_words_list'
|
|
|
- ? of({ retcode: 1, result: [{ GeneralID: 601, Title: 'tend@张雅茜', xxcs: api.lastLearningWordUpdate['save'] ? 1 : 0, detail: [word] }], page: { itemCount: 1, pageCount: 1, pageIndex: 1, pageSize: 100 } } as ApiEnvelope<any>)
|
|
|
+ ? of({ retcode: 1, result: api.lastLearningWordUpdate['save'] === 1 && params?.['learningStatus'] === 'completed'
|
|
|
+ ? [{ GeneralID: 601, Title: 'tend@张雅茜', xxcs: 1, detail: [word] }]
|
|
|
+ : api.lastLearningWordUpdate['save'] === 1 ? [] : [{ GeneralID: 601, Title: 'tend@张雅茜', xxcs: 0, detail: [word] }],
|
|
|
+ page: { itemCount: params?.['learningStatus'] === 'completed' ? 1 : api.lastLearningWordUpdate['save'] === 1 ? 0 : 1,
|
|
|
+ pendingCount: api.lastLearningWordUpdate['save'] === 1 ? 0 : 1, completedCount: api.lastLearningWordUpdate['save'] === 1 ? 1 : 0,
|
|
|
+ pageCount: 1, pageIndex: 1, pageSize: 30 } } as ApiEnvelope<any>)
|
|
|
: get(action, params));
|
|
|
const harness = await RouterTestingHarness.create();
|
|
|
const router = TestBed.inject(Router);
|