|
|
@@ -1,5 +1,7 @@
|
|
|
-import { TestBed } from '@angular/core/testing';
|
|
|
-import { ActivatedRoute, convertToParamMap } from '@angular/router';
|
|
|
+import { BehaviorSubject, Subject } from 'rxjs';
|
|
|
+import { OperationsLiveRefreshService } from '../operations-live-refresh.service';
|
|
|
+import { ComponentFixture, fakeAsync, flushMicrotasks, TestBed } from '@angular/core/testing';
|
|
|
+import { ActivatedRoute, convertToParamMap, ParamMap } from '@angular/router';
|
|
|
import { matchesScheduleSearch, OperationsScheduleComponent, scheduleCoachBusy, scheduleCoachesWithAppointments, scheduleCourseAvailable, scheduleCoursesForStudent, schedulePreflightCandidates, scheduleRowActions } from './operations-schedule.component';
|
|
|
import { ScheduleAppointment, ScheduleCalendarData } from '../admin.models';
|
|
|
import { OperationsService } from '../operations.service';
|
|
|
@@ -284,3 +286,47 @@ describe('排课表单预检', () => {
|
|
|
expect(component.date()).toBe('2026-10-04');expect(component.startTime()).toBe('09:00');expect(component.recurrence()).toBe('once');expect(component.occurrences()).toBe(1);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+describe('排课页面复用后的会员与开课数据', () => {
|
|
|
+ let changes: Subject<'local' | 'broadcast'>;
|
|
|
+ let params: BehaviorSubject<ParamMap>;
|
|
|
+ let route: { snapshot: { queryParamMap: ParamMap }; queryParamMap: BehaviorSubject<ParamMap> };
|
|
|
+ let schedule: jasmine.Spy;
|
|
|
+ let fixture: ComponentFixture<OperationsScheduleComponent>;
|
|
|
+ const empty = (): ScheduleCalendarData => ({ members: [], courses: [], appointments: [], coaches: [], unassigned: [], dataDateTo: '' } as unknown as ScheduleCalendarData);
|
|
|
+ const current = (): ScheduleCalendarData => ({ ...empty(), members: [{objectId:'new-member',userId:1935,displayName:'新学员',mobileMasked:'',readOnly:false}], courses: [{bindingId:'new-binding',courseId:447,courseName:'新开单词课',memberIds:[1935],mappingConfirmed:true,supportedDurations:[30]}] } as ScheduleCalendarData);
|
|
|
+ beforeEach(async () => {
|
|
|
+ changes = new Subject(); params = new BehaviorSubject(convertToParamMap({}));
|
|
|
+ route = {snapshot:{queryParamMap:params.value},queryParamMap:params};
|
|
|
+ schedule = jasmine.createSpy('schedule').and.callFake(async () => empty());
|
|
|
+ await TestBed.configureTestingModule({imports:[OperationsScheduleComponent],providers:[
|
|
|
+ {provide:OperationsService,useValue:{schedule,dataChanges$:changes}},
|
|
|
+ {provide:ActivatedRoute,useValue:route},
|
|
|
+ {provide:OperationsLiveRefreshService,useValue:{watch:()=>()=>undefined}},
|
|
|
+ ]}).compileComponents();
|
|
|
+ fixture=TestBed.createComponent(OperationsScheduleComponent);fixture.detectChanges();await fixture.whenStable();
|
|
|
+ });
|
|
|
+ afterEach(()=>fixture.destroy());
|
|
|
+ function navigateToMember():void {route.snapshot.queryParamMap=convertToParamMap({studentId:'1935'});params.next(route.snapshot.queryParamMap);}
|
|
|
+ it('离开期间新增会员、充值和开课后,返回更新候选;普通返回不重复读取', fakeAsync(() => {
|
|
|
+ fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();expect(schedule).toHaveBeenCalledTimes(1);
|
|
|
+ changes.next('local');changes.next('broadcast');schedule.and.callFake(async()=>current());
|
|
|
+ fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();
|
|
|
+ expect(schedule).toHaveBeenCalledTimes(2);expect(fixture.componentInstance.data()?.members[0].userId).toBe(1935);
|
|
|
+ fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();expect(schedule).toHaveBeenCalledTimes(2);
|
|
|
+ }));
|
|
|
+ it('缓存页面收到会员排课入口时先读取新数据再选择会员,同一会员再次进入也可打开', fakeAsync(() => {
|
|
|
+ schedule.and.callFake(async()=>current());
|
|
|
+ fixture.componentInstance.onOperationsRouteAttach();navigateToMember();flushMicrotasks();
|
|
|
+ expect(schedule).toHaveBeenCalledTimes(2);expect(fixture.componentInstance.drawerOpen()).toBeTrue();
|
|
|
+ expect(fixture.componentInstance.studentId()).toBe(1935);expect(fixture.componentInstance.bindingId()).toBe('new-binding');
|
|
|
+ fixture.componentInstance.closeDrawer();fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();
|
|
|
+ expect(schedule).toHaveBeenCalledTimes(3);expect(fixture.componentInstance.drawerOpen()).toBeTrue();
|
|
|
+ }));
|
|
|
+ it('读取失败时不拿旧候选假装已选择新会员,返回重试可恢复', fakeAsync(() => {
|
|
|
+ schedule.and.rejectWith(new Error('读取失败'));navigateToMember();flushMicrotasks();
|
|
|
+ expect(fixture.componentInstance.error()).toBe('读取失败');expect(fixture.componentInstance.drawerOpen()).toBeFalse();
|
|
|
+ schedule.and.callFake(async()=>current());fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();
|
|
|
+ expect(fixture.componentInstance.studentId()).toBe(1935);
|
|
|
+ }));
|
|
|
+});
|