|
@@ -5,7 +5,7 @@ import { OperationsService } from '../operations.service';
|
|
|
describe('跨日期预约批量管理',()=>{
|
|
describe('跨日期预约批量管理',()=>{
|
|
|
let ops:jasmine.SpyObj<OperationsService>;
|
|
let ops:jasmine.SpyObj<OperationsService>;
|
|
|
const rows=Array.from({length:201},(_,i)=>({targetId:'a'+i,generalId:i+1,studentName:'学员'+i,coachName:'杨珍',courseName:'课程',startsAt:'2026-11-05T10:00:00+08:00',updatedAt:'2026-11-01T00:00:00.000Z',statusCode:i===199?10:0,cancelled:i===200,readOnly:false}));
|
|
const rows=Array.from({length:201},(_,i)=>({targetId:'a'+i,generalId:i+1,studentName:'学员'+i,coachName:'杨珍',courseName:'课程',startsAt:'2026-11-05T10:00:00+08:00',updatedAt:'2026-11-01T00:00:00.000Z',statusCode:i===199?10:0,cancelled:i===200,readOnly:false}));
|
|
|
- beforeEach(()=>{ops=jasmine.createSpyObj<OperationsService>('OperationsService',['list','mutate']);ops.list.and.callFake(async(_kind,page,size,search)=>({page,pageSize:size,total:rows.length,items:rows.slice((page-1)*size,page*size),refreshedAt:''}));TestBed.configureTestingModule({imports:[ScheduleBulkManagerComponent],providers:[{provide:OperationsService,useValue:ops}]});});
|
|
|
|
|
|
|
+ beforeEach(()=>{ops=jasmine.createSpyObj<OperationsService>('OperationsService',['list','mutate','batchMutations']);ops.batchMutations.and.callFake(async work=>work());ops.list.and.callFake(async(_kind,page,size,search)=>({page,pageSize:size,total:rows.length,items:rows.slice((page-1)*size,page*size),refreshedAt:''}));TestBed.configureTestingModule({imports:[ScheduleBulkManagerComponent],providers:[{provide:OperationsService,useValue:ops}]});});
|
|
|
it('按姓名跨日期查询,全选所有匹配页,排除已取消和训练中课程,并可取消单项',async()=>{
|
|
it('按姓名跨日期查询,全选所有匹配页,排除已取消和训练中课程,并可取消单项',async()=>{
|
|
|
const c=TestBed.createComponent(ScheduleBulkManagerComponent).componentInstance;c.searchInput='杨珍';await c.searchAppointments();
|
|
const c=TestBed.createComponent(ScheduleBulkManagerComponent).componentInstance;c.searchInput='杨珍';await c.searchAppointments();
|
|
|
expect(ops.list).toHaveBeenCalledWith('appointments',1,25,'杨珍',{dateFrom:'',dateTo:''});await c.selectAllMatching();expect(c.selected().size).toBe(199);expect(c.selected().has('a199')).toBeFalse();expect(c.selected().has('a200')).toBeFalse();
|
|
expect(ops.list).toHaveBeenCalledWith('appointments',1,25,'杨珍',{dateFrom:'',dateTo:''});await c.selectAllMatching();expect(c.selected().size).toBe(199);expect(c.selected().has('a199')).toBeFalse();expect(c.selected().has('a200')).toBeFalse();
|
|
@@ -59,4 +59,18 @@ describe('跨日期预约批量管理',()=>{
|
|
|
const count=ops.list.calls.count();await c.selectAllMatching();expect(ops.list.calls.count()).toBe(count);
|
|
const count=ops.list.calls.count();await c.selectAllMatching();expect(ops.list.calls.count()).toBe(count);
|
|
|
spyOn(window,'confirm').and.returnValue(true);await c.cancelSelected();expect(ops.mutate).not.toHaveBeenCalled();
|
|
spyOn(window,'confirm').and.returnValue(true);await c.cancelSelected();expect(ops.mutate).not.toHaveBeenCalled();
|
|
|
});
|
|
});
|
|
|
|
|
+ it('批量取消串行执行,响应失败但查到已取消时从待处理项移除',async()=>{
|
|
|
|
|
+ const c=TestBed.createComponent(ScheduleBulkManagerComponent).componentInstance;c.searchInput='杨珍';await c.searchAppointments();c.toggleRow(rows[0] as any);c.toggleRow(rows[1] as any);
|
|
|
|
|
+ spyOn(window,'confirm').and.returnValue(true);let running=0,max=0;
|
|
|
|
|
+ ops.mutate.and.callFake(async()=>{running++;max=Math.max(max,running);await Promise.resolve();running--;throw Error('连接中断');});
|
|
|
|
|
+ ops.list.and.resolveTo({items:rows.slice(0,2).map(r=>({...r,cancelled:true})),total:2} as any);
|
|
|
|
|
+ await c.cancelSelected();expect(max).toBe(1);expect(c.selected().size).toBe(0);expect(c.error()).toBe('');expect(c.message()).toContain('已取消 2 条');expect(ops.batchMutations).toHaveBeenCalledTimes(1);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('全部结果不确定时仍通知父页核对,关闭窗口后再核对一次',async()=>{
|
|
|
|
|
+ const c=TestBed.createComponent(ScheduleBulkManagerComponent).componentInstance;c.searchInput='杨珍';await c.searchAppointments();c.toggleRow(rows[0] as any);
|
|
|
|
|
+ spyOn(window,'confirm').and.returnValue(true);ops.mutate.and.rejectWith(Error('连接中断'));ops.list.and.rejectWith(Error('核对失败'));const changed=spyOn(c.changed,'emit');
|
|
|
|
|
+ await c.cancelSelected();expect(changed).toHaveBeenCalledTimes(1);expect(c.selected().size).toBe(1);c.close();expect(changed).toHaveBeenCalledTimes(2);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
});
|
|
});
|