From ae895715196736decbd212f2f607cc25d73d9db9 Mon Sep 17 00:00:00 2001 From: Yura Bondarenko Date: Thu, 3 Mar 2022 18:44:55 +0100 Subject: [PATCH] 87968: Fix unit tests --- ...c-form-control-container.component.spec.ts | 2 ++ .../form/builder/form-builder.service.spec.ts | 2 +- .../claimed-task-actions.component.spec.ts | 2 +- ...imed-task-actions-reject.component.spec.ts | 16 ++++----- .../workspaceitem-actions.component.spec.ts | 27 ++++++++------ .../submission-form-footer.component.spec.ts | 36 +++++++++++-------- 6 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.spec.ts index 73b93ad827..b4d7ea75f3 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.spec.ts @@ -77,6 +77,7 @@ import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils'; import { FormService } from '../../form.service'; import { SubmissionService } from '../../../../submission/submission.service'; import { FormBuilderService } from '../form-builder.service'; +import { NgxMaskModule } from 'ngx-mask'; describe('DsDynamicFormControlContainerComponent test suite', () => { @@ -194,6 +195,7 @@ describe('DsDynamicFormControlContainerComponent test suite', () => { DynamicFormsCoreModule.forRoot(), SharedModule, TranslateModule.forRoot(), + NgxMaskModule.forRoot(), ], providers: [ DsDynamicFormControlContainerComponent, diff --git a/src/app/shared/form/builder/form-builder.service.spec.ts b/src/app/shared/form/builder/form-builder.service.spec.ts index cea4d7df6e..4055c84921 100644 --- a/src/app/shared/form/builder/form-builder.service.spec.ts +++ b/src/app/shared/form/builder/form-builder.service.spec.ts @@ -104,7 +104,7 @@ describe('FormBuilderService test suite', () => { new DynamicInputModel( { id: 'testInput', - mask: ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/], + mask: '(000) 000-0000', } ), diff --git a/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.spec.ts index fcaa2f455a..5e6938853a 100644 --- a/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.spec.ts @@ -170,7 +170,7 @@ describe('ClaimedTaskActionsComponent', () => { fixture.whenStable().then(() => { const debugElement = fixture.debugElement.query(By.css('.workflow-view')); expect(debugElement).toBeTruthy(); - expect(debugElement.nativeElement.innerText).toBe('submission.workflow.generic.view'); + expect(debugElement.nativeElement.innerText.trim()).toBe('submission.workflow.generic.view'); }); })); diff --git a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts index 5d3a2ec127..c7e1dd2ebb 100644 --- a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts @@ -32,14 +32,15 @@ const searchService = getMockSearchService(); const requestService = getMockRequestService(); +const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' }); + +const claimedTaskService = jasmine.createSpyObj('claimedTaskService', { + submitTask: of(new ProcessTaskResponse(true)) +}); + let mockPoolTaskDataService: PoolTaskDataService; describe('ClaimedTaskActionsRejectComponent', () => { - const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' }); - const claimedTaskService = jasmine.createSpyObj('claimedTaskService', { - submitTask: of(new ProcessTaskResponse(true)) - }); - beforeEach(waitForAsync(() => { mockPoolTaskDataService = new PoolTaskDataService(null, null, null, null, null, null, null, null); TestBed.configureTestingModule({ @@ -69,9 +70,6 @@ describe('ClaimedTaskActionsRejectComponent', () => { }).overrideComponent(ClaimedTaskActionsRejectComponent, { set: { changeDetection: ChangeDetectionStrategy.Default } }).compileComponents(); - })); - - beforeEach(() => { fixture = TestBed.createComponent(ClaimedTaskActionsRejectComponent); component = fixture.componentInstance; formBuilder = TestBed.inject(FormBuilder); @@ -80,7 +78,7 @@ describe('ClaimedTaskActionsRejectComponent', () => { component.modalRef = modalService.open('ok'); spyOn(component, 'initReloadAnchor').and.returnValue(undefined); fixture.detectChanges(); - }); + })); it('should init reject form properly', () => { expect(component.rejectForm).toBeDefined(); diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts index 8654740026..11568d2a68 100644 --- a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts @@ -132,22 +132,27 @@ describe('WorkspaceitemActionsComponent', () => { expect(btn).toBeDefined(); }); - it('should call confirmDiscard on discard confirmation', () => { - mockDataService.delete.and.returnValue(observableOf(true)); - spyOn(component, 'reload'); - const btn = fixture.debugElement.query(By.css('.btn-danger')); - btn.nativeElement.click(); - fixture.detectChanges(); + describe('on discard confirmation', () => { + beforeEach((done) => { + mockDataService.delete.and.returnValue(observableOf(true)); + spyOn(component, 'reload'); + const btn = fixture.debugElement.query(By.css('.btn-danger')); + btn.nativeElement.click(); + fixture.detectChanges(); - const confirmBtn: any = ((document as any).querySelector('.modal-footer .btn-danger')); - confirmBtn.click(); + const confirmBtn: any = ((document as any).querySelector('.modal-footer .btn-danger')); + confirmBtn.click(); - fixture.detectChanges(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(mockDataService.delete).toHaveBeenCalledWith(mockObject.id); + fixture.whenStable().then(() => { + done(); + }); }); + it('should call confirmDiscard', () => { + expect(mockDataService.delete).toHaveBeenCalledWith(mockObject.id); + }); }); it('should display a success notification on delete success', waitForAsync(() => { diff --git a/src/app/submission/form/footer/submission-form-footer.component.spec.ts b/src/app/submission/form/footer/submission-form-footer.component.spec.ts index 072f826deb..851852ba66 100644 --- a/src/app/submission/form/footer/submission-form-footer.component.spec.ts +++ b/src/app/submission/form/footer/submission-form-footer.component.spec.ts @@ -16,6 +16,10 @@ import { SubmissionFormFooterComponent } from './submission-form-footer.componen import { SubmissionRestService } from '../../../core/submission/submission-rest.service'; import { createTestComponent } from '../../../shared/testing/utils.test'; +const submissionServiceStub: SubmissionServiceStub = new SubmissionServiceStub(); + +const submissionId = mockSubmissionId; + describe('SubmissionFormFooterComponent Component', () => { let comp: SubmissionFormFooterComponent; @@ -24,9 +28,6 @@ describe('SubmissionFormFooterComponent Component', () => { let submissionRestServiceStub: SubmissionRestServiceStub; let scheduler: TestScheduler; - const submissionServiceStub: SubmissionServiceStub = new SubmissionServiceStub(); - const submissionId = mockSubmissionId; - beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [ @@ -182,22 +183,29 @@ describe('SubmissionFormFooterComponent Component', () => { expect(submissionServiceStub.dispatchDeposit).toHaveBeenCalledWith(submissionId); }); - it('should call dispatchDiscard on discard confirmation', (done) => { - comp.showDepositAndDiscard = observableOf(true); - fixture.detectChanges(); - const modalBtn = fixture.debugElement.query(By.css('.btn-danger')); + describe('on discard confirmation', () => { + beforeEach((done) => { + comp.showDepositAndDiscard = observableOf(true); + fixture.detectChanges(); + const modalBtn = fixture.debugElement.query(By.css('.btn-danger')); - modalBtn.nativeElement.click(); - fixture.detectChanges(); + modalBtn.nativeElement.click(); + fixture.detectChanges(); - const confirmBtn: any = ((document as any).querySelector('.btn-danger:nth-child(2)')); - confirmBtn.click(); + const confirmBtn: any = ((document as any).querySelector('.btn-danger:nth-child(2)')); - fixture.detectChanges(); + console.log(confirmBtn); - fixture.whenStable().then(() => { + confirmBtn.click(); + + fixture.detectChanges(); + fixture.whenStable().then(() => { + done(); + }); + }); + + it('should call dispatchDiscard', () => { expect(submissionServiceStub.dispatchDiscard).toHaveBeenCalledWith(submissionId); - done(); }); });