From 499725659b1eeabe53d161fc6ad7c6643d407fbd Mon Sep 17 00:00:00 2001 From: Tomasz Gnyp <49343696+tomgny@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:47:53 +0200 Subject: [PATCH] [AAE-10644] Fix tests that have no expectations - core lib part 2 (#7893) * [AAE-10644] Fix tests that have no expectations - core lib part 2 * implement improvements --- .../datatable/datatable.component.spec.ts | 51 ++++--- .../directives/node-delete.directive.spec.ts | 133 +++++++----------- .../lib/directives/upload.directive.spec.ts | 17 ++- .../widgets/checkbox/checkbox.widget.spec.ts | 15 +- .../widgets/content/content.widget.spec.ts | 50 +++---- .../widgets/core/form.model.spec.ts | 16 +-- .../components/widgets/core/form.model.ts | 4 +- .../date-time/date-time.widget.spec.ts | 52 +++---- .../widgets/date/date.widget.spec.ts | 51 +++---- .../widgets/people/people.widget.spec.ts | 7 +- .../widgets/text/text.widget.spec.ts | 18 +-- .../widgets/widget.component.spec.ts | 22 +-- .../lib/form/services/form.service.spec.ts | 8 +- .../widget-visibility-cloud.service.spec.ts | 10 +- .../widget-visibility.service.spec.ts | 10 +- .../sidebar-action-menu.component.spec.ts | 15 +- .../login/components/login.component.spec.ts | 8 +- .../services/authentication.service.spec.ts | 17 +-- .../src/lib/services/bpm-user.service.spec.ts | 10 +- .../src/lib/services/download.service.spec.ts | 6 +- lib/core/src/lib/services/log.service.spec.ts | 10 +- .../services/people-process.service.spec.ts | 58 ++++---- .../lib/services/renditions.service.spec.ts | 12 +- .../components/viewer.component.spec.ts | 12 +- 24 files changed, 271 insertions(+), 341 deletions(-) diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts index a1f74b71f7..9fb5e91f30 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts @@ -752,7 +752,8 @@ describe('DataTable', () => { dataTable.onRowClick(row, null); }); - it('should emit double click if there are two single click in 250ms', (done) => { + it('should emit double click if there are two single click in 250ms', fakeAsync(() => { + let doubleClickCount = 0; const row = {} as DataRow; dataTable.data = new ObjectDataTableAdapter([], []); @@ -760,7 +761,7 @@ describe('DataTable', () => { fixture.detectChanges(); dataTable.rowDblClick.subscribe(() => { - done(); + doubleClickCount += 1; }); dataTable.onRowClick(row, null); @@ -768,16 +769,22 @@ describe('DataTable', () => { dataTable.onRowClick(row, null); } , 240); - }); - it('should emit double click if there are more than two single click in 250ms', (done) => { + tick(490); + + + expect(doubleClickCount).toBe(1); + })); + + it('should emit double click if there are more than two single click in 250ms', fakeAsync(() => { + let doubleClickCount = 0; const row = {} as DataRow; dataTable.data = new ObjectDataTableAdapter([], []); dataTable.ngOnChanges({}); fixture.detectChanges(); dataTable.rowDblClick.subscribe(() => { - done(); + doubleClickCount += 1; }); dataTable.onRowClick(row, null); @@ -787,9 +794,13 @@ describe('DataTable', () => { dataTable.onRowClick(row, null); } , 240); - }); - it('should emit single click if there are two single click in more than 250ms', (done) => { + tick(740); + + expect(doubleClickCount).toBe(1); + })); + + it('should emit single click if there are two single click in more than 250ms', fakeAsync(() => { const row = {} as DataRow; let clickCount = 0; @@ -799,17 +810,19 @@ describe('DataTable', () => { dataTable.rowClick.subscribe(() => { clickCount += 1; - if (clickCount === 2) { - done(); - } }); dataTable.onRowClick(row, null); + setTimeout(() => { dataTable.onRowClick(row, null); } , 260); - }); + + tick(510); + + expect(clickCount).toBe(2); + })); it('should emit row-click dom event', (done) => { const row = {} as DataRow; @@ -977,22 +990,6 @@ describe('DataTable', () => { expect(dataTable.isSelectAllChecked).toBeFalsy(); }); - it('should reset selection upon data rows change', () => { - const data = new ObjectDataTableAdapter([{}, {}, {}], []); - - dataTable.data = data; - dataTable.multiselect = true; - dataTable.ngAfterContentInit(); - dataTable.onSelectAllClick({ checked: true } as MatCheckboxChange); - - expect(dataTable.selection.every((entry) => entry.isSelected)); - - data.setRows([]); - fixture.detectChanges(); - - expect(dataTable.selection.every((entry) => !entry.isSelected)); - }); - it('should update rows on "select all" click', () => { const data = new ObjectDataTableAdapter([{}, {}, {}], []); const rows = data.getRows(); diff --git a/lib/core/src/lib/directives/node-delete.directive.spec.ts b/lib/core/src/lib/directives/node-delete.directive.spec.ts index 769218d89c..6da5ecf9f7 100644 --- a/lib/core/src/lib/directives/node-delete.directive.spec.ts +++ b/lib/core/src/lib/directives/node-delete.directive.spec.ts @@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser'; import { NodeDeleteDirective } from './node-delete.directive'; import { setupTestBed } from '../testing/setup-test-bed'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; @Component({ template: ` @@ -90,7 +89,6 @@ describe('NodeDeleteDirective', () => { setupTestBed({ imports: [ - TranslateModule.forRoot(), CoreTestingModule ], declarations: [ @@ -136,85 +134,77 @@ describe('NodeDeleteDirective', () => { expect(deleteNodeSpy).not.toHaveBeenCalled(); }); - it('should process node successfully', (done) => { + it('should process node successfully', async () => { component.selection = [{ entry: { id: '1', name: 'name1' } }]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.SINGULAR' ); - done(); }); + element.nativeElement.click(); fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); + await fixture.whenStable(); }); - it('should notify failed node deletion', (done) => { + it('should notify failed node deletion', async () => { deleteNodeSpy.and.returnValue(Promise.reject('error')); component.selection = [{ entry: { id: '1', name: 'name1' } }]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.ERROR_SINGULAR' ); - done(); }); + element.nativeElement.click(); fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); + await fixture.whenStable(); }); - it('should notify nodes deletion', (done) => { + it('should notify nodes deletion', async () => { component.selection = [ { entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } } ]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.PLURAL' ); - done(); }); + element.nativeElement.click(); fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); + await fixture.whenStable(); }); - it('should notify failed nodes deletion', (done) => { + it('should notify failed nodes deletion', async () => { deleteNodeSpy.and.returnValue(Promise.reject('error')); component.selection = [ { entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } } ]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.ERROR_PLURAL' ); - done(); }); + element.nativeElement.click(); fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); + await fixture.whenStable(); }); - it('should notify partial deletion when only one node is successful', (done) => { + it('should notify partial deletion when only one node is successful', async () => { deleteNodeSpy.and.callFake((id) => { if (id === '1') { return Promise.reject('error'); @@ -227,22 +217,20 @@ describe('NodeDeleteDirective', () => { { entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } } ]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.PARTIAL_SINGULAR' ); - done(); }); + element.nativeElement.click(); fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); + await fixture.whenStable(); }); - it('should notify partial deletion when some nodes are successful', (done) => { + it('should notify partial deletion when some nodes are successful', async () => { deleteNodeSpy.and.callFake((id) => { if (id === '1') { return Promise.reject(null); @@ -256,55 +244,47 @@ describe('NodeDeleteDirective', () => { { entry: { id: '2', name: 'name2' } }, { entry: { id: '3', name: 'name3' } } ]; + fixture.detectChanges(); disposableDelete = component.deleteDirective.delete.subscribe((message) => { expect(message).toBe( 'CORE.DELETE_NODE.PARTIAL_PLURAL' ); - done(); }); - fixture.detectChanges(); - - fixture.whenStable().then(() => { - element.nativeElement.click(); - }); - }); - - it('should emit event when delete is done', (done) => { - component.selection = [{ entry: { id: '1', name: 'name1' } }]; - fixture.detectChanges(); - element.nativeElement.click(); fixture.detectChanges(); - - disposableDelete = component.deleteDirective.delete.subscribe(() => { - done(); - }); + await fixture.whenStable(); }); - it('should disable the button if no node are selected', (done) => { + it('should emit event when delete is done', async () => { + component.selection = [{ entry: { id: '1', name: 'name1' } }]; + fixture.detectChanges(); + + disposableDelete = component.deleteDirective.delete.subscribe((node) => { + expect(node).toEqual('CORE.DELETE_NODE.SINGULAR'); + }); + + element.nativeElement.click(); + fixture.detectChanges(); + await fixture.whenStable(); + }); + + it('should disable the button if no node are selected', () => { component.selection = []; fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.nativeElement.disabled).toEqual(true); - done(); - }); + expect(element.nativeElement.disabled).toEqual(true); }); - it('should disable the button if selected node is null', (done) => { + it('should disable the button if selected node is null', () => { component.selection = null; fixture.detectChanges(); - - fixture.whenStable().then(() => { - expect(element.nativeElement.disabled).toEqual(true); - done(); - }); + expect(element.nativeElement.disabled).toEqual(true); }); - it('should enable the button if nodes are selected', (done) => { + it('should enable the button if nodes are selected', () => { component.selection = [ { entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }, @@ -312,14 +292,10 @@ describe('NodeDeleteDirective', () => { ]; fixture.detectChanges(); - - fixture.whenStable().then(() => { - expect(element.nativeElement.disabled).toEqual(false); - done(); - }); + expect(element.nativeElement.disabled).toEqual(false); }); - it('should not enable the button if adf-check-allowable-operation is present', (done) => { + it('should not enable the button if adf-check-allowable-operation is present', () => { const elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective)); const componentWithPermissions = fixtureWithPermissions.componentInstance; @@ -335,16 +311,12 @@ describe('NodeDeleteDirective', () => { ]; fixtureWithPermissions.detectChanges(); - - fixture.whenStable().then(() => { - expect(elementWithPermissions.nativeElement.disabled).toEqual(false); - done(); - }); + expect(elementWithPermissions.nativeElement.disabled).toEqual(false); }); describe('Permanent', () => { - it('should call the api with permanent delete option if permanent directive input is true', (done) => { + it('should call the api with permanent delete option if permanent directive input is true', () => { fixtureWithPermanentComponent.detectChanges(); componentWithPermanentDelete.selection = [ @@ -352,16 +324,12 @@ describe('NodeDeleteDirective', () => { ]; fixtureWithPermanentComponent.detectChanges(); - elementWithPermanentDelete.nativeElement.click(); - fixture.whenStable().then(() => { - expect(deleteNodePermanentSpy).toHaveBeenCalledWith('1', { permanent: true }); - done(); - }); + expect(deleteNodePermanentSpy).toHaveBeenCalledWith('1', { permanent: true }); }); - it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', (done) => { + it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', () => { fixtureWithPermanentComponent.detectChanges(); componentWithPermanentDelete.selection = [ @@ -369,15 +337,10 @@ describe('NodeDeleteDirective', () => { ]; fixtureWithPermanentComponent.detectChanges(); - elementWithPermanentDelete.nativeElement.click(); - fixture.whenStable().then(() => { - expect(purgeDeletedNodePermanentSpy).toHaveBeenCalledWith('1'); - done(); - }); + expect(purgeDeletedNodePermanentSpy).toHaveBeenCalledWith('1'); }); - }); }); }); diff --git a/lib/core/src/lib/directives/upload.directive.spec.ts b/lib/core/src/lib/directives/upload.directive.spec.ts index d9a50a0140..39f81d821c 100644 --- a/lib/core/src/lib/directives/upload.directive.spec.ts +++ b/lib/core/src/lib/directives/upload.directive.spec.ts @@ -16,6 +16,7 @@ */ import { ElementRef } from '@angular/core'; +import { fakeAsync, tick } from '@angular/core/testing'; import { UploadDirective } from './upload.directive'; describe('UploadDirective', () => { @@ -106,18 +107,19 @@ describe('UploadDirective', () => { expect(event.preventDefault).not.toHaveBeenCalled(); }); - it('should raise upload-files event on files drop', (done) => { + it('should raise upload-files event on files drop', fakeAsync(() => { directive.enabled = true; const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']); spyOn(directive, 'getDataTransfer').and.returnValue({} as any); spyOn(directive, 'getFilesDropped').and.returnValue(Promise.resolve([{}, {}])); - spyOn(nativeElement, 'dispatchEvent').and.callFake((_) => { - done(); + spyOn(nativeElement, 'dispatchEvent').and.callFake((customEvent) => { + expect(customEvent).toBeTruthy(); }); directive.onDrop(event); - }); + tick(); + })); - it('should provide dropped files in upload-files event', (done) => { + it('should provide dropped files in upload-files event', fakeAsync(() => { directive.enabled = true; const files = [{}]; const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']); @@ -127,10 +129,11 @@ describe('UploadDirective', () => { spyOn(nativeElement, 'dispatchEvent').and.callFake((e) => { expect(e.detail.files.length).toBe(1); expect(e.detail.files[0]).toBe(files[0]); - done(); }); + directive.onDrop(event); - }); + tick(); + })); it('should reset input value after file upload', () => { directive.enabled = true; diff --git a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts index d72faa5d8b..dbe5b385dc 100644 --- a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormFieldTypes } from '../core/form-field-types'; import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; @@ -92,15 +92,14 @@ describe('CheckboxWidgetComponent', () => { expect(asterisk.textContent).toEqual('*'); }); - it('should be checked if boolean true is passed', fakeAsync(() => { + it('should be checked if boolean true is passed', async () => { widget.field.value = true; fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input'); - expect(checkbox.getAttribute('aria-checked')).toBe('true'); - }); - })); + await fixture.whenStable(); + fixture.detectChanges(); + const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input'); + expect(checkbox.getAttribute('aria-checked')).toBe('true'); + }); it('should not be checked if false is passed', async () => { widget.field.value = false; diff --git a/lib/core/src/lib/form/components/widgets/content/content.widget.spec.ts b/lib/core/src/lib/form/components/widgets/content/content.widget.spec.ts index 9515abbbcc..1f81e5c16c 100644 --- a/lib/core/src/lib/form/components/widgets/content/content.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/content/content.widget.spec.ts @@ -16,7 +16,7 @@ */ import { SimpleChange } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { ContentService } from '../../../../services'; import { of } from 'rxjs'; @@ -99,7 +99,7 @@ describe('ContentWidgetComponent', () => { expect(content).toBeDefined(); }); - it('should load the thumbnail preview of the png image', (done) => { + it('should load the thumbnail preview of the png image', fakeAsync(() => { const blob = createFakeImageBlob(); spyOn(processContentService, 'getFileRawContent').and.returnValue(of(blob)); @@ -108,12 +108,9 @@ describe('ContentWidgetComponent', () => { expect(res).toBeDefined(); expect(res.changingThisBreaksApplicationSecurity).toBeDefined(); expect(res.changingThisBreaksApplicationSecurity).toContain('blob'); - fixture.whenStable() - .then(() => { - const thumbnailPreview: any = element.querySelector('#thumbnailPreview'); - expect(thumbnailPreview.src).toContain('blob'); - }); - done(); + + const thumbnailPreview: any = element.querySelector('#thumbnailPreview'); + expect(thumbnailPreview.src).toContain('blob'); }); const contentId = 1; @@ -140,9 +137,9 @@ describe('ContentWidgetComponent', () => { thumbnailStatus: 'unsupported' } }); - }); + })); - it('should load the thumbnail preview of a pdf', (done) => { + it('should load the thumbnail preview of a pdf', fakeAsync(() => { const blob = createFakePdfBlob(); spyOn(processContentService, 'getContentThumbnail').and.returnValue(of(blob)); @@ -151,12 +148,9 @@ describe('ContentWidgetComponent', () => { expect(res).toBeDefined(); expect(res.changingThisBreaksApplicationSecurity).toBeDefined(); expect(res.changingThisBreaksApplicationSecurity).toContain('blob'); - fixture.whenStable() - .then(() => { - const thumbnailPreview: any = element.querySelector('#thumbnailPreview'); - expect(thumbnailPreview.src).toContain('blob'); - }); - done(); + + const thumbnailPreview: any = element.querySelector('#thumbnailPreview'); + expect(thumbnailPreview.src).toContain('blob'); }); const contentId = 1; @@ -183,9 +177,9 @@ describe('ContentWidgetComponent', () => { thumbnailStatus: 'created' } }); - }); + })); - it('should show unsupported preview with unsupported file', (done) => { + it('should show unsupported preview with unsupported file', fakeAsync(() => { const contentId = 1; const change = new SimpleChange(null, contentId, true); @@ -193,13 +187,9 @@ describe('ContentWidgetComponent', () => { component.contentLoaded.subscribe(() => { fixture.detectChanges(); - fixture.whenStable() - .then(() => { - const thumbnailPreview: any = element.querySelector('#unsupported-thumbnail'); - expect(thumbnailPreview).toBeDefined(); - expect(element.querySelector('div.upload-widget__content-text').innerHTML).toEqual('FakeBlob.zip'); - }); - done(); + const thumbnailPreview: any = element.querySelector('#unsupported-thumbnail'); + expect(thumbnailPreview).toBeDefined(); + expect(element.querySelector('div.upload-widget__content-text').innerHTML).toEqual('FakeBlob.zip'); }); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -222,9 +212,9 @@ describe('ContentWidgetComponent', () => { thumbnailStatus: 'unsupported' } }); - }); + })); - it('should open the viewer when the view button is clicked', (done) => { + it('should open the viewer when the view button is clicked', () => { const blob = createFakePdfBlob(); spyOn(processContentService, 'getContentPreview').and.returnValue(of(blob)); spyOn(processContentService, 'getFileRawContent').and.returnValue(of(blob)); @@ -252,7 +242,6 @@ describe('ContentWidgetComponent', () => { expect(content.contentBlob).toBe(blob); expect(content.mimeType).toBe('application/pdf'); expect(content.name).toBe('FakeBlob.pdf'); - done(); }); fixture.detectChanges(); @@ -288,10 +277,7 @@ describe('ContentWidgetComponent', () => { const downloadButton: any = element.querySelector('#download'); downloadButton.click(); - fixture.whenStable() - .then(() => { - expect(serviceContent.downloadBlob).toHaveBeenCalledWith(blob, 'FakeBlob.pdf'); - }); + expect(serviceContent.downloadBlob).toHaveBeenCalledWith(blob, 'FakeBlob.pdf'); }); }); }); diff --git a/lib/core/src/lib/form/components/widgets/core/form.model.spec.ts b/lib/core/src/lib/form/components/widgets/core/form.model.spec.ts index 6a3755c965..65d33afe5d 100644 --- a/lib/core/src/lib/form/components/widgets/core/form.model.spec.ts +++ b/lib/core/src/lib/form/components/widgets/core/form.model.spec.ts @@ -30,8 +30,6 @@ import { UploadWidgetContentLinkModel } from './upload-widget-content-link.model import { AlfrescoApiService } from '../../../../services'; import { TestBed } from '@angular/core/testing'; import { CoreTestingModule, setupTestBed } from '../../../../testing'; -import { TranslateModule } from '@ngx-translate/core'; -import { CoreModule } from '../../../../core.module'; describe('FormModel', () => { let formService: FormService; @@ -39,8 +37,6 @@ describe('FormModel', () => { setupTestBed({ imports: [ - TranslateModule.forRoot(), - CoreModule.forRoot(), CoreTestingModule ] }); @@ -284,18 +280,22 @@ describe('FormModel', () => { expect(form.outcomes[1].isSystem).toBeFalsy(); }); - it('should raise validation event when validating form', (done) => { + it('should raise validation event when validating form', () => { const form = new FormModel({}, null, false, formService); - formService.validateForm.subscribe(() => done()); + formService.validateForm.subscribe((validateFormEvent) => + expect(validateFormEvent).toBeTruthy() + ); form.validateForm(); }); - it('should raise validation event when validating field', (done) => { + it('should raise validation event when validating field', () => { const form = new FormModel({}, null, false, formService); const field = jasmine.createSpyObj('FormFieldModel', ['validate']); - formService.validateFormField.subscribe(() => done()); + formService.validateFormField.subscribe((validateFormFieldEvent) => + expect(validateFormFieldEvent).toBeTruthy() + ); form.validateField(field); }); diff --git a/lib/core/src/lib/form/components/widgets/core/form.model.ts b/lib/core/src/lib/form/components/widgets/core/form.model.ts index a9eb5f2e79..27cef65504 100644 --- a/lib/core/src/lib/form/components/widgets/core/form.model.ts +++ b/lib/core/src/lib/form/components/widgets/core/form.model.ts @@ -109,9 +109,7 @@ export class FormModel implements ProcessFormModel { this.enableFixedSpace = enableFixedSpace ? true : false; this.confirmMessage = json.confirmMessage || {}; - this.tabs = (json.tabs || []).map((tabJson) => { - return new TabModel(this, tabJson); - }); + this.tabs = (json.tabs || []).map((tabJson) => new TabModel(this, tabJson)); this.fields = this.parseRootFields(json); this.fieldsCache = this.getFormFields(); diff --git a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts index ce0223a923..d4c037b4f4 100644 --- a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts @@ -117,21 +117,19 @@ describe('DateTimeWidgetComponent', () => { }); }); - it('should be marked as invalid after interaction', async () => { + it('should be marked as invalid after interaction', () => { const dateTimeInput = fixture.nativeElement.querySelector('input'); expect(fixture.nativeElement.querySelector('.adf-invalid')).toBeFalsy(); dateTimeInput.dispatchEvent(new Event('blur')); fixture.detectChanges(); - await fixture.whenStable(); expect(fixture.nativeElement.querySelector('.adf-invalid')).toBeTruthy(); }); - it('should be able to display label with asterisk', async () => { + it('should be able to display label with asterisk', () => { fixture.detectChanges(); - await fixture.whenStable(); const asterisk: HTMLElement = element.querySelector('.adf-asterisk'); @@ -142,7 +140,7 @@ describe('DateTimeWidgetComponent', () => { describe('template check', () => { - it('should show visible date widget', async () => { + it('should show visible date widget', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -152,15 +150,15 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); expect(element.querySelector('#date-field-id')).toBeDefined(); expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); expect(dateElement.value).toBe('30-11-9999 10:30 AM'); }); - it('should show the correct format type', async () => { + it('should show the correct format type', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -171,15 +169,15 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); expect(element.querySelector('#date-field-id')).toBeDefined(); expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); expect(dateElement.value).toContain('12-30-9999 10:30 AM'); }); - it('should disable date button when is readonly', async () => { + it('should disable date button when is readonly', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -189,20 +187,18 @@ describe('DateTimeWidgetComponent', () => { readOnly: 'false' }); fixture.detectChanges(); - await fixture.whenStable(); let dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeFalsy(); widget.field.readOnly = true; fixture.detectChanges(); - await fixture.whenStable(); dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeTruthy(); }); - it('should display tooltip when tooltip is set', async () => { + it('should display tooltip when tooltip is set', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -214,7 +210,6 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); const dateElement: any = element.querySelector('#date-field-id'); const tooltip = dateElement.getAttribute('ng-reflect-message'); @@ -234,27 +229,23 @@ describe('DateTimeWidgetComponent', () => { field.isVisible = true; field.dateDisplayFormat = 'MM-DD-YYYY HH:mm A'; widget.field = field; - widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('12-30-9999 10:30 AM'); - widget.field.value = '03-02-2020 12:00 AM'; + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); - fixture.whenStable() - .then(() => { - expect(dateElement.value).toContain('03-02-2020 12:00 AM'); - }); - }); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('12-30-9999 10:30 AM'); + + widget.field.value = '03-02-2020 12:00 AM'; + fixture.detectChanges(); + + expect(dateElement.value).toContain('03-02-2020 12:00 AM'); }); describe('when form model has left labels', () => { - it('should have left labels classes on leftLabels true', async () => { + it('should have left labels classes on leftLabels true', () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), { id: 'datetime-id', name: 'datetime-name', @@ -265,7 +256,6 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); const widgetContainer = element.querySelector('.adf-left-label-input-container'); expect(widgetContainer).not.toBeNull(); @@ -277,7 +267,7 @@ describe('DateTimeWidgetComponent', () => { expect(adfLeftLabel).not.toBeNull(); }); - it('should not have left labels classes on leftLabels false', async () => { + it('should not have left labels classes on leftLabels false', () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), { id: 'datetime-id', name: 'datetime-name', @@ -288,7 +278,6 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); const widgetContainer = element.querySelector('.adf-left-label-input-container'); expect(widgetContainer).toBeNull(); @@ -300,7 +289,7 @@ describe('DateTimeWidgetComponent', () => { expect(adfLeftLabel).toBeNull(); }); - it('should not have left labels classes on leftLabels not present', async () => { + it('should not have left labels classes on leftLabels not present', () => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { id: 'datetime-id', name: 'datetime-name', @@ -311,7 +300,6 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); - await fixture.whenStable(); const widgetContainer = element.querySelector('.adf-left-label-input-container'); expect(widgetContainer).toBeNull(); diff --git a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts index 1c9c6ee61c..c79d1358f3 100644 --- a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts @@ -105,24 +105,21 @@ describe('DateWidgetComponent', () => { type: FormFieldTypes.DATE, required: true }); + + fixture.detectChanges(); }); - it('should be marked as invalid after interaction', async () => { + it('should be marked as invalid after interaction', () => { const dateInput = fixture.nativeElement.querySelector('input'); expect(fixture.nativeElement.querySelector('.adf-invalid')).toBeFalsy(); dateInput.dispatchEvent(new Event('blur')); - fixture.detectChanges(); - await fixture.whenStable(); expect(fixture.nativeElement.querySelector('.adf-invalid')).toBeTruthy(); }); - it('should be able to display label with asterix', async () => { - fixture.detectChanges(); - await fixture.whenStable(); - + it('should be able to display label with asterix', () => { const asterisk: HTMLElement = element.querySelector('.adf-asterisk'); expect(asterisk).toBeTruthy(); @@ -137,7 +134,7 @@ describe('DateWidgetComponent', () => { TestBed.resetTestingModule(); }); - it('should show visible date widget', async () => { + it('should show visible date widget', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -146,18 +143,17 @@ describe('DateWidgetComponent', () => { readOnly: 'false' }); widget.field.isVisible = true; - widget.ngOnInit(); fixture.detectChanges(); - await fixture.whenStable(); expect(element.querySelector('#date-field-id')).toBeDefined(); expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); expect(dateElement.value).toContain('9-9-9999'); }); - it('should show the correct format type', async () => { + it('should show the correct format type', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -167,18 +163,17 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.field.dateDisplayFormat = 'MM-DD-YYYY'; - widget.ngOnInit(); fixture.detectChanges(); - await fixture.whenStable(); expect(element.querySelector('#date-field-id')).toBeDefined(); expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); expect(dateElement.value).toContain('12-30-9999'); }); - it('should disable date button when is readonly', async () => { + it('should disable date button when is readonly', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -190,7 +185,6 @@ describe('DateWidgetComponent', () => { widget.field.readOnly = false; fixture.detectChanges(); - await fixture.whenStable(); let dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeFalsy(); @@ -202,7 +196,7 @@ describe('DateWidgetComponent', () => { expect(dateButton.disabled).toBeTruthy(); }); - it('should set isValid to false when the value is not a correct date value', async () => { + it('should set isValid to false when the value is not a correct date value', () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -212,9 +206,7 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.field.readOnly = false; - fixture.detectChanges(); - await fixture.whenStable(); expect(widget.field.isValid).toBeFalsy(); }); @@ -231,22 +223,17 @@ describe('DateWidgetComponent', () => { field.isVisible = true; field.dateDisplayFormat = 'MM-DD-YYYY'; widget.field = field; - widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('12-30-9999'); - widget.field.value = '03-02-2020'; + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(dateElement.value).toContain('03-02-2020'); - }); - }); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('12-30-9999'); + + widget.field.value = '03-02-2020'; + + fixture.detectChanges(); + expect(dateElement.value).toContain('03-02-2020'); }); }); diff --git a/lib/core/src/lib/form/components/widgets/people/people.widget.spec.ts b/lib/core/src/lib/form/components/widgets/people/people.widget.spec.ts index 8ece4deae2..5b4be3d4fa 100644 --- a/lib/core/src/lib/form/components/widgets/people/people.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/people/people.widget.spec.ts @@ -149,10 +149,11 @@ describe('PeopleWidgetComponent', () => { widget.ngOnInit(); const involvedUser = fixture.debugElement.nativeElement.querySelector('input[data-automation-id="adf-people-search-input"]'); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(involvedUser.value).toBe('John Doe'); - }); + await fixture.whenStable(); + + expect(involvedUser.value).toBe('John Doe'); }); describe('when is required', () => { diff --git a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts index 852891f12b..36de46818f 100644 --- a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormFieldTypes } from '../core/form-field-types'; import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; @@ -248,14 +248,14 @@ describe('TextWidgetComponent', () => { inputElement = element.querySelector('#text-id'); }); - it('should be disabled on readonly forms', fakeAsync(() => { - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(inputElement).toBeDefined(); - expect(inputElement).not.toBeNull(); - expect(inputElement.disabled).toBeTruthy(); - }); - })); + it('should be disabled on readonly forms', async () => { + await fixture.whenStable(); + fixture.detectChanges(); + + expect(inputElement).toBeDefined(); + expect(inputElement).not.toBeNull(); + expect(inputElement.disabled).toBeTruthy(); + }); }); diff --git a/lib/core/src/lib/form/components/widgets/widget.component.spec.ts b/lib/core/src/lib/form/components/widgets/widget.component.spec.ts index a4461131bc..a2d8cc5aa0 100644 --- a/lib/core/src/lib/form/components/widgets/widget.component.spec.ts +++ b/lib/core/src/lib/form/components/widgets/widget.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { FormFieldModel } from './core/form-field.model'; import { FormModel } from './core/form.model'; import { WidgetComponent } from './widget.component'; @@ -48,19 +48,21 @@ describe('WidgetComponent', () => { describe('Events', () => { - it('should click event be redirect on the form event service', async() => { - await widget.formService.formEvents.subscribe(() => { + it('should click event be redirect on the form event service', fakeAsync(() => { + widget.formService.formEvents.subscribe((event) => { + expect(event).toBeTruthy(); }); element.click(); - }); + })); - it('should click event be redirect on the form rules event service', async() => { - await widget.formService.formRulesEvent.pipe(filter(event => event.type === 'click')).subscribe(() => { + it('should click event be redirect on the form rules event service', fakeAsync(() => { + widget.formService.formRulesEvent.pipe(filter(event => event.type === 'click')).subscribe((event) => { + expect(event).toBeTruthy(); }); element.click(); - }); + })); }); it('should check field', () => { @@ -69,7 +71,7 @@ describe('WidgetComponent', () => { expect(widget.hasField()).toBeTruthy(); }); - it('should send an event after view init', async() => { + it('should send an event after view init', async () => { const fakeForm = new FormModel(); const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' }); widget.field = fakeField; @@ -83,7 +85,7 @@ describe('WidgetComponent', () => { widget.ngAfterViewInit(); }); - it('should send an event when a field is changed', async() => { + it('should send an event when a field is changed', async () => { const fakeForm = new FormModel(); const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' }); await widget.fieldChanged.subscribe((field) => { @@ -95,7 +97,7 @@ describe('WidgetComponent', () => { widget.onFieldChanged(fakeField); }); - it('should send a rule event when a field is changed', async() => { + it('should send a rule event when a field is changed', async () => { const fakeForm = new FormModel(); const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' }); await widget.formService.formRulesEvent.subscribe((event) => { diff --git a/lib/core/src/lib/form/services/form.service.spec.ts b/lib/core/src/lib/form/services/form.service.spec.ts index d3b7771aa9..e28c8bfdfb 100644 --- a/lib/core/src/lib/form/services/form.service.spec.ts +++ b/lib/core/src/lib/form/services/form.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { formModelTabs } from '../../mock'; import { FormService } from './form.service'; import { setupTestBed } from '../../testing/setup-test-bed'; @@ -352,7 +352,7 @@ describe('Form service', () => { expect(formParsed).toBeDefined(); }); - it('should create a Form form a Node', async() => { + it('should create a Form form a Node', fakeAsync(() => { const nameForm = 'testNode'; const formId = 100; @@ -403,9 +403,9 @@ describe('Form service', () => { stubGetEcmModel(); stubAddFieldsToAForm(); - await service.createFormFromANode(nameForm).subscribe((result) => { + service.createFormFromANode(nameForm).subscribe((result) => { expect(result.id).toEqual(formId); }); - }); + })); }); }); diff --git a/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts b/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts index 5131f58f40..5208a941b0 100644 --- a/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts +++ b/lib/core/src/lib/form/services/widget-visibility-cloud.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { ContainerModel, FormFieldModel, @@ -298,16 +298,16 @@ describe('WidgetVisibilityCloudService', () => { }); }); - it('should catch error on 403 response', (done) => { + it('should catch error on 403 response', fakeAsync(() => { service.getTaskProcessVariable('9999').subscribe(() => { - }, () => { - done(); + }, (errorMessage) => { + expect(errorMessage).toEqual('Error while performing a call - Server error'); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); }); describe('should return the value of the field', () => { diff --git a/lib/core/src/lib/form/services/widget-visibility.service.spec.ts b/lib/core/src/lib/form/services/widget-visibility.service.spec.ts index 64a7a52fbb..46489f393a 100644 --- a/lib/core/src/lib/form/services/widget-visibility.service.spec.ts +++ b/lib/core/src/lib/form/services/widget-visibility.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { ContainerModel, FormFieldModel, @@ -301,16 +301,16 @@ describe('WidgetVisibilityService', () => { }); }); - it('should catch error on 403 response', (done) => { + it('should catch error on 403 response', fakeAsync(() => { service.getTaskProcessVariable('9999').subscribe(() => { - }, () => { - done(); + }, (errorMessage) => { + expect(errorMessage).toEqual('Error while performing a call - Server error'); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); }); describe('should return the value of the field', () => { diff --git a/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts b/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts index 1956ca9b0e..f751b707fb 100644 --- a/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts +++ b/lib/core/src/lib/layout/components/sidebar-action/sidebar-action-menu.component.spec.ts @@ -118,18 +118,19 @@ describe('Custom SidebarActionMenuComponent', () => { expect(title.textContent).toBe('FakeTitle'); }); - it('should render the adf-sidebar-menu-options', () => { + it('should render the adf-sidebar-menu-options', async () => { fixture.detectChanges(); const actionButton = fixture.nativeElement.querySelector('.adf-sidebar-action-menu-button'); const options = fixture.nativeElement.querySelectorAll('.adf-sidebar-action-menu-options'); actionButton.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(actionButton).not.toBeNull(); - expect(actionButton).toBeDefined(); - expect(options).toBeDefined(); - expect(actionButton.innerText.trim()).toBe('Fake titlearrow_drop_down'); - }); + await fixture.whenStable(); + + expect(actionButton).not.toBeNull(); + expect(actionButton).toBeDefined(); + expect(options).toBeDefined(); + expect(actionButton.innerText.trim()).toBe('Fake titlearrow_drop_down'); }); it('should show icon on icon menu', () => { diff --git a/lib/core/src/lib/login/components/login.component.spec.ts b/lib/core/src/lib/login/components/login.component.spec.ts index d8bbbb5446..615822d718 100644 --- a/lib/core/src/lib/login/components/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login.component.spec.ts @@ -30,7 +30,6 @@ import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { setupTestBed } from '../../testing/setup-test-bed'; import { CoreTestingModule } from '../../testing/core.testing.module'; -import { TranslateModule } from '@ngx-translate/core'; describe('LoginComponent', () => { let component: LoginComponent; @@ -60,7 +59,6 @@ describe('LoginComponent', () => { setupTestBed({ imports: [ - TranslateModule.forRoot(), CoreTestingModule ] }); @@ -173,7 +171,7 @@ describe('LoginComponent', () => { expect(router.navigateByUrl).toHaveBeenCalledWith('some-route'); })); - it('should update user preferences upon login', fakeAsync(() => { + it('should update user preferences upon login', async () => { spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); @@ -182,7 +180,9 @@ describe('LoginComponent', () => { }); loginWithCredentials('fake-username', 'fake-password'); - })); + fixture.detectChanges(); + await fixture.whenStable(); + }); describe('Login button', () => { diff --git a/lib/core/src/lib/services/authentication.service.spec.ts b/lib/core/src/lib/services/authentication.service.spec.ts index 768c294a21..1be0b97c5a 100644 --- a/lib/core/src/lib/services/authentication.service.spec.ts +++ b/lib/core/src/lib/services/authentication.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { AlfrescoApiService } from './alfresco-api.service'; import { AuthenticationService } from './authentication.service'; import { CookieService } from './cookie.service'; @@ -82,6 +82,8 @@ describe('AuthenticationService', () => { describe('when the setting is ECM', () => { + const fakeECMLoginResponse = { type: 'ECM', ticket: 'fake-post-ticket' }; + beforeEach(() => { appConfigService.config.providers = 'ECM'; appConfigService.load(); @@ -131,10 +133,10 @@ describe('AuthenticationService', () => { }); }); - it('[ECM] should login in the ECM if no provider are defined calling the login', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + it('[ECM] should login in the ECM if no provider are defined calling the login', fakeAsync(() => { + const disposableLogin = authService.login('fake-username', 'fake-password').subscribe((loginResponse) => { + expect(loginResponse).toEqual(fakeECMLoginResponse); disposableLogin.unsubscribe(); - done(); }); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -142,9 +144,9 @@ describe('AuthenticationService', () => { contentType: 'application/json', responseText: JSON.stringify({ entry: { id: 'fake-post-ticket', userId: 'admin' } }) }); - }); + })); - it('[ECM] should return a ticket undefined after logout', (done) => { + it('[ECM] should return a ticket undefined after logout', fakeAsync(() => { const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { const disposableLogout = authService.logout().subscribe(() => { expect(authService.isLoggedIn()).toBe(false); @@ -152,7 +154,6 @@ describe('AuthenticationService', () => { expect(authService.isEcmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); disposableLogout.unsubscribe(); - done(); }); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -165,7 +166,7 @@ describe('AuthenticationService', () => { contentType: 'application/json', responseText: JSON.stringify({ entry: { id: 'fake-post-ticket', userId: 'admin' } }) }); - }); + })); it('[ECM] should return false if the user is not logged in', () => { expect(authService.isLoggedIn()).toBe(false); diff --git a/lib/core/src/lib/services/bpm-user.service.spec.ts b/lib/core/src/lib/services/bpm-user.service.spec.ts index ee6486b08b..15824b368e 100644 --- a/lib/core/src/lib/services/bpm-user.service.spec.ts +++ b/lib/core/src/lib/services/bpm-user.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { BpmUserModel } from '../models/bpm-user.model'; import { BpmUserService } from './bpm-user.service'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -76,15 +76,15 @@ describe('Bpm user service', () => { expect(path).toContain('/app/rest/admin/profile-picture'); }); - it('should catch errors on call for profile', (done) => { + it('should catch errors on call for profile', fakeAsync(() => { service.getCurrentUserInfo().subscribe(() => { - }, () => { - done(); + }, (error) => { + expect(error).toEqual({ error: new Error('Unsuccessful HTTP response') }); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); }); }); diff --git a/lib/core/src/lib/services/download.service.spec.ts b/lib/core/src/lib/services/download.service.spec.ts index f86cccce69..7415e38800 100644 --- a/lib/core/src/lib/services/download.service.spec.ts +++ b/lib/core/src/lib/services/download.service.spec.ts @@ -25,12 +25,12 @@ describe('DownloadService', () => { }); describe('Download blob', () => { - it('Should use native msSaveOrOpenBlob if the browser is IE', (done) => { + it('Should use native msSaveOrOpenBlob if the browser is IE', () => { const navigatorAny: any = window.navigator; // eslint-disable-next-line no-underscore-dangle - navigatorAny.__defineGetter__('msSaveOrOpenBlob', () => { - done(); + navigatorAny.__defineGetter__('msSaveOrOpenBlob', (result) => { + expect(result).toBeUndefined(); }); const blob = new Blob([''], { type: 'text/html' }); diff --git a/lib/core/src/lib/services/log.service.spec.ts b/lib/core/src/lib/services/log.service.spec.ts index 7d2e92d806..e05ffd134b 100644 --- a/lib/core/src/lib/services/log.service.spec.ts +++ b/lib/core/src/lib/services/log.service.spec.ts @@ -19,7 +19,7 @@ import { HttpClientModule } from '@angular/common/http'; import { Component } from '@angular/core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { AppConfigService } from '../app-config/app-config.service'; import { LogService } from './log.service'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -165,15 +165,15 @@ describe('LogService', () => { expect(console.error).toHaveBeenCalled(); }); - it('message Observable', done => { + it('message Observable', fakeAsync(() => { appConfigService.config['logLevel'] = 'trace'; providesLogComponent.componentInstance.logService.onMessage.subscribe( - () => { - done(); + (message) => { + expect(message).toEqual({ text: 'Test message', type: 'LOG' }); } ); providesLogComponent.componentInstance.log(); - }); + })); }); diff --git a/lib/core/src/lib/services/people-process.service.spec.ts b/lib/core/src/lib/services/people-process.service.spec.ts index 8a1e0739c9..0eda0b1690 100644 --- a/lib/core/src/lib/services/people-process.service.spec.ts +++ b/lib/core/src/lib/services/people-process.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { UserProcessModel } from '../models'; import { PeopleProcessService } from './people-process.service'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -40,6 +40,8 @@ const secondInvolvedUser: UserProcessModel = new UserProcessModel({ const fakeInvolveUserList: UserProcessModel[] = [firstInvolvedUser, secondInvolvedUser]; +const errorResponse = { error: new Error('Unsuccessful HTTP response') }; + describe('PeopleProcessService', () => { let service: PeopleProcessService; @@ -65,7 +67,7 @@ describe('PeopleProcessService', () => { jasmine.Ajax.uninstall(); }); - it('should be able to retrieve people to involve in the task', (done) => { + it('should be able to retrieve people to involve in the task', fakeAsync(() => { service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( (users: UserProcessModel[]) => { expect(users).toBeDefined(); @@ -74,30 +76,30 @@ describe('PeopleProcessService', () => { expect(users[0].email).toEqual('fake-user1@fake.com'); expect(users[0].firstName).toEqual('fakeName1'); expect(users[0].lastName).toEqual('fakeLast1'); - done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: {data: fakeInvolveUserList} }); - }); + })); - it('should be able to get people images for people retrieved', (done) => { + it('should be able to get people images for people retrieved', fakeAsync(() => { service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( (users: UserProcessModel[]) => { expect(users).toBeDefined(); expect(users.length).toBe(2); expect(service.getUserImage(users[0])).toContain('/users/' + users[0].id + '/picture'); expect(service.getUserImage(users[1])).toContain('/users/' + users[1].id + '/picture'); - done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: {data: fakeInvolveUserList} }); - }); + })); it('should return user image url', () => { const url = service.getUserImage(firstInvolvedUser); @@ -105,75 +107,75 @@ describe('PeopleProcessService', () => { expect(url).toContain('/users/' + firstInvolvedUser.id + '/picture'); }); - it('should return empty list when there are no users to involve', (done) => { + it('should return empty list when there are no users to involve', fakeAsync(() => { service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe( (users: UserProcessModel[]) => { expect(users).toBeDefined(); expect(users.length).toBe(0); - done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: {} }); - }); + })); - it('getWorkflowUsers catch errors call', (done) => { + it('getWorkflowUsers catch errors call', fakeAsync(() => { service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(() => { - }, () => { - done(); + }, (error) => { + expect(error).toEqual(errorResponse); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); - it('should be able to involve people in the task', (done) => { + it('should be able to involve people in the task', fakeAsync(() => { service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe( () => { expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/involve'); - done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - }); + })); - it('involveUserWithTask catch errors call', (done) => { + it('involveUserWithTask catch errors call', fakeAsync(() => { service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => { - }, () => { - done(); + }, (error) => { + expect(error).toEqual(errorResponse); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); - it('should be able to remove involved people from task', (done) => { + it('should be able to remove involved people from task', fakeAsync(() => { service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe( () => { expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT'); expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/remove-involved'); - done(); }); + jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 }); - }); + })); - it('removeInvolvedUser catch errors call', (done) => { + it('removeInvolvedUser catch errors call', fakeAsync(() => { service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => { - }, () => { - done(); + }, (error) => { + expect(error).toEqual(errorResponse); }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 403 }); - }); + })); }); }); diff --git a/lib/core/src/lib/services/renditions.service.spec.ts b/lib/core/src/lib/services/renditions.service.spec.ts index 215a0af20f..95c69518f8 100644 --- a/lib/core/src/lib/services/renditions.service.spec.ts +++ b/lib/core/src/lib/services/renditions.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { fakeRendition, fakeRenditionCreated, fakeRenditionsList, fakeRenditionsListWithACreated } from '../mock/renditions-service.mock'; import { RenditionsService } from './renditions.service'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -25,6 +25,8 @@ import { TranslateModule } from '@ngx-translate/core'; declare let jasmine: any; +const errorResponse = { error: new Error('Parser is unable to parse the response') }; + describe('RenditionsService', () => { let service: RenditionsService; @@ -110,10 +112,10 @@ describe('RenditionsService', () => { }); }); - it('Get rendition service should catch the error', (done) => { + it('Get rendition service should catch the error', fakeAsync(() => { service.getRenditionsListByNodeId('fake-node-id').subscribe(() => { - }, () => { - done(); + }, (error) => { + expect(error).toEqual(errorResponse); } ); @@ -122,7 +124,7 @@ describe('RenditionsService', () => { contentType: 'application/json', responseText: 'error' }); - }); + })); it('isConversionPossible should return true if is possible convert', (done) => { service.isConversionPossible('fake-node-id', 'pdf').subscribe((res) => { diff --git a/lib/core/src/lib/viewer/components/viewer.component.spec.ts b/lib/core/src/lib/viewer/components/viewer.component.spec.ts index d3553d0f66..1a390f6a0c 100644 --- a/lib/core/src/lib/viewer/components/viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/viewer.component.spec.ts @@ -1162,20 +1162,20 @@ describe('ViewerComponent', () => { }); - it('should raise an event when the shared link is invalid', (done) => { + it('should raise an event when the shared link is invalid', fakeAsync(() => { spyOn(component['sharedLinksApi'], 'getSharedLink') .and.returnValue(Promise.reject({})); - component.invalidSharedLink.subscribe(() => { - done(); - }); - component.sharedLinkId = 'the-Shared-Link-id'; component.urlFile = null; component.mimeType = null; + component.invalidSharedLink.subscribe((emittedValue) => { + expect(emittedValue).toBeUndefined(); + }); + component.ngOnChanges(); - }); + })); it('should swicth to the unkwown template if the type specific viewers throw an error', (done) => { component.urlFile = 'fake-url-file.icns';