У меня есть эта функция, для которой я пишу модульный тест.
public showAdminAction(hraData: PhpGrid) {
if (this.isInvalidMasterChildHealthPlanMapped(hraData.MasterChildHealthPlanId)) {
this.showInvalidMasterChildHealthPlanPopUp(hraData);
}
else this.hraLockService.getHraLockDetail(hraData.HraId).then((res: any) => {
if (res.LockedBy) {
this.customDialogService.error(this.translateService.get("RecordLocked"), this.translateService.get("RecordLockedFromAdminAction").format(res.LockedBy));
} else {
this.customDialogService.createDialog(hraData, AdminActionComponent);
}
});
}
private isInvalidMasterChildHealthPlanMapped(masterChildHealthPlanId: number): boolean {
if (this.siteService.getSiteHealthPlans() && masterChildHealthPlanId && !this.siteService.getSiteHealthPlans().find(x => x.Id == masterChildHealthPlanId)) {
return true;
}
return false;
}
private showInvalidMasterChildHealthPlanPopUp(phpRowData: PhpGrid) {
this.loggingService.log(this.translateService.get('IncorrectMasterChildHealthPlanMappedHraLog').replace('##hraId##', phpRowData.HraId.toString()).replace('##masterChildHealthPlanId##', phpRowData.MasterChildHealthPlanId.toString()).replace('##code##', MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra.toString()), MasterEventTypeEnum.Error, MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra, MasterLogLevelEnum.Error, MasterEventRecordTypeEnum.HRA, phpRowData.HraId);
this.customDialogService.error(this.translateService.get("Error"), this.translateService.get("IncorrectMasterChildHealthPlanMappedHra").replace("##code##", MasterEventLookupTypeEnum.IncorrectMasterChildHealthPlanMappedHra.toString()));
}
Это UT, которые я написал
describe('showAdminAction', () => {
it('shows error dialog when InvalidMasterChildHealthPlanMapped', () => {
let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
let data = dataHelper.getPhpGridDataRawFormat();
let res: any = { LockedBy: 'TestUser' };
let siteHealthPlan: SiteHealthPlan[] = [{ Id: 2, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];
spyOn(customDialogService, 'error');
spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);
pwqGridComponent.showAdminAction(data.Rows[2]);
expect(customDialogService.error).toHaveBeenCalled();
});
});
describe('showAdminAction', () => {
it('shows error dialog when validMasterChildHealthPlanMapped but locked by user', () => {
let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
let data = dataHelper.getPhpGridDataRawFormat();
let res: any = { LockedBy: 'TestUser' };
let siteHealthPlan: SiteHealthPlan[] = [{ Id: 1, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];
spyOn(customDialogService, 'error');
spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);
pwqGridComponent.showAdminAction(data.Rows[2]);
expect(customDialogService.error).toHaveBeenCalled();
});
});
describe('showAdminAction', () => {
it('shows custom dialog when validMasterChildHealthPlanMapped and not locked by user', () => {
let dataHelper: PhpGridMockDataHelper = new PhpGridMockDataHelper();
let data = dataHelper.getPhpGridDataRawFormat();
let res: any = { LockedBy: null };
let siteHealthPlan: SiteHealthPlan[] = [{ Id: 1, Name: "OTHER STANDARD | MEDICARE", HraTypeFlag: 31, DefaultHraTypeId: 1, MasterPlanTypeId: 1, MasterPlanTypeName: null, VisitTypes: null, SortOrder: 3 }];
spyOn(customDialogService, 'createDialog').and.returnValue(Observable.of(true));
spyOn(hraLockService, 'getHraLockDetail').and.returnValue(Promise.resolve(res));
spyOn(siteService, 'getSiteHealthPlans').and.returnValue(siteHealthPlan);
pwqGridComponent.showAdminAction(data.Rows[2]);
expect(customDialogService.createDialog).toHaveBeenCalled();
});
});
Но я получаю приведенную ниже ошибку для двух последних UT:
FAILED PwqGrid Компонент showAdminAction показываетдиалоговое окно ошибки, когда validMasterChildHealthPlanMapped, но заблокирован пользователем
zone.js: 199 Uncaught Ожидаемая шпионская ошибка была вызвана.на UserContext.(http://localhost:9876/base/config/spec-bundle.js:128900:47)
FAILED Компонент PwqGrid showAdminAction показывает настраиваемое диалоговое окно, когда validMasterChildHealthPlanMapped и не заблокировано пользователем
zone.js: 199 Неизвестный Ожидаемый шпион createDialog, который был вызван. В UserContext. (http://localhost:9876/base/config/spec-bundle.js:128913:54)