From b0a75b9cf5e734940dd98c110baf889b3acad622 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Wed, 3 Apr 2024 02:33:48 +0100 Subject: [PATCH] [affected:*][ci:force] - REBASED --- .../aspect-list-dialog.component.scss | 2 +- ...d-view-keyvaluepairsitem.component.spec.ts | 16 +++--- .../card-view-mapitem.component.spec.ts | 6 +-- .../card-view-selectitem.component.spec.ts | 6 ++- .../select-filter-input.component.spec.ts | 6 +-- .../card-view-textitem.component.spec.ts | 14 +++-- .../card-view/card-view.component.spec.ts | 22 +++++++- .../lib/clipboard/clipboard.directive.spec.ts | 54 ++++++++----------- .../lib/clipboard/clipboard.service.spec.ts | 14 +++-- .../comment-list.component.spec.ts | 34 +++++------- .../lib/comments/comments.component.spec.ts | 27 +++++----- .../directionality-config.service.spec.ts | 19 ++++--- .../common/services/storage.service.spec.ts | 29 ++++------ .../services/user-preferences.service.spec.ts | 16 +++--- .../src/lib/testing/core.testing.module.ts | 11 ++-- 15 files changed, 136 insertions(+), 140 deletions(-) diff --git a/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.scss b/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.scss index f000042386..80fe1d91cb 100644 --- a/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.scss +++ b/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.scss @@ -2,7 +2,7 @@ adf-aspect-list-dialog { display: block; - padding: 24px 24px 8px 24px; + padding: 24px 24px 8px; } .adf { diff --git a/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts index 7ef53d3bdc..f85cdf0716 100644 --- a/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts @@ -19,12 +19,14 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluepairs.model'; import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component'; -import { CoreTestingModule } from '../../../testing/core.testing.module'; import { CardViewUpdateService } from '../../services/card-view-update.service'; import { TranslateModule } from '@ngx-translate/core'; +import { MatIconModule } from '@angular/material/icon'; +import { MatTableModule } from '@angular/material/table'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { FormsModule } from '@angular/forms'; describe('CardViewKeyValuePairsItemComponent', () => { - let fixture: ComponentFixture; let component: CardViewKeyValuePairsItemComponent; let cardViewUpdateService: CardViewUpdateService; @@ -33,10 +35,9 @@ describe('CardViewKeyValuePairsItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [NoopAnimationsModule, TranslateModule.forRoot(), MatIconModule, MatTableModule, FormsModule], + providers: [CardViewUpdateService], + declarations: [CardViewKeyValuePairsItemComponent] }); fixture = TestBed.createComponent(CardViewKeyValuePairsItemComponent); cardViewUpdateService = TestBed.inject(CardViewUpdateService); @@ -55,7 +56,6 @@ describe('CardViewKeyValuePairsItemComponent', () => { }); describe('Component', () => { - it('should render the label', () => { fixture.detectChanges(); @@ -122,5 +122,5 @@ describe('CardViewKeyValuePairsItemComponent', () => { expect(cardViewUpdateService.update).toHaveBeenCalled(); expect(component.property.value.length).toBe(0); }); - }); + }); }); diff --git a/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts index ab1111ce37..bf130cbbda 100644 --- a/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-mapitem/card-view-mapitem.component.spec.ts @@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser'; import { CardViewMapItemModel } from '../../models/card-view-mapitem.model'; import { CardViewUpdateService } from '../../services/card-view-update.service'; import { CardViewMapItemComponent } from './card-view-mapitem.component'; -import { CoreTestingModule } from '../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; describe('CardViewMapItemComponent', () => { @@ -34,10 +33,7 @@ describe('CardViewMapItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [TranslateModule.forRoot()] }); fixture = TestBed.createComponent(CardViewMapItemComponent); service = TestBed.inject(CardViewUpdateService); diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts index 4c5521aee5..fc575dc912 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/card-view-selectitem.component.spec.ts @@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model'; import { CardViewSelectItemComponent } from './card-view-selectitem.component'; -import { CoreTestingModule } from '../../../testing/core.testing.module'; import { of } from 'rxjs'; import { TranslateModule } from '@ngx-translate/core'; import { AppConfigService } from '../../../app-config/app-config.service'; @@ -27,6 +26,9 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatSelectHarness } from '@angular/material/select/testing'; import { MatFormFieldHarness } from '@angular/material/form-field/testing'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { MatSelectModule } from '@angular/material/select'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; describe('CardViewSelectItemComponent', () => { let loader: HarnessLoader; @@ -60,7 +62,7 @@ describe('CardViewSelectItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [NoopAnimationsModule, TranslateModule.forRoot(), HttpClientTestingModule, MatSelectModule] }); fixture = TestBed.createComponent(CardViewSelectItemComponent); component = fixture.componentInstance; diff --git a/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts index be3d2fcc10..1b7ae8c04e 100644 --- a/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts @@ -16,10 +16,10 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { CoreTestingModule } from '../../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { SelectFilterInputComponent } from './select-filter-input.component'; -import { MatSelect } from '@angular/material/select'; +import { MatSelect, MatSelectModule } from '@angular/material/select'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; describe('SelectFilterInputComponent', () => { let fixture: ComponentFixture; @@ -28,7 +28,7 @@ describe('SelectFilterInputComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule], + imports: [NoopAnimationsModule, TranslateModule.forRoot(), MatSelectModule], providers: [MatSelect] }); diff --git a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts index bd21473c8f..901bc39322 100644 --- a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts @@ -20,7 +20,6 @@ import { By } from '@angular/platform-browser'; import { CardViewTextItemModel } from '../../models/card-view-textitem.model'; import { CardViewUpdateService } from '../../services/card-view-update.service'; import { CardViewTextItemComponent } from './card-view-textitem.component'; -import { CoreTestingModule } from '../../../testing/core.testing.module'; import { CardViewItemFloatValidator } from '../../validators/card-view-item-float.validator'; import { CardViewItemIntValidator } from '../../validators/card-view-item-int.validator'; import { CardViewIntItemModel } from '../../models/card-view-intitem.model'; @@ -34,6 +33,12 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatChipGridHarness, MatChipHarness } from '@angular/material/chips/testing'; import { MatInputHarness } from '@angular/material/input/testing'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; +import { TranslationService } from '../../../translation'; +import { TranslationMock } from '../../../mock'; +import { MatTooltipModule } from '@angular/material/tooltip'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; describe('CardViewTextItemComponent', () => { let loader: HarnessLoader; @@ -111,7 +116,8 @@ describe('CardViewTextItemComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule, MatChipsModule] + imports: [HttpClientTestingModule, NoopAnimationsModule, TranslateModule.forRoot(), MatSnackBarModule, MatTooltipModule, MatChipsModule], + providers: [{ provide: TranslationService, useClass: TranslationMock }] }); fixture = TestBed.createComponent(CardViewTextItemComponent); component = fixture.componentInstance; @@ -534,7 +540,9 @@ describe('CardViewTextItemComponent', () => { component.ngOnChanges({}); loader = TestbedHarnessEnvironment.loader(fixture); - const inputHarness = await loader.getHarness(MatInputHarness.with({selector: `[data-automation-id="card-textitem-value-${component.property.key}"]`})); + const inputHarness = await loader.getHarness( + MatInputHarness.with({ selector: `[data-automation-id="card-textitem-value-${component.property.key}"]` }) + ); expect(component.isEditable).toBe(false); expect(await inputHarness.isReadonly()).toBe(true); diff --git a/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts b/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts index 4b6e81b81b..74ae8839c2 100644 --- a/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view/card-view.component.spec.ts @@ -20,7 +20,6 @@ import { By } from '@angular/platform-browser'; import { CardViewDateItemModel } from '../../models/card-view-dateitem.model'; import { CardViewTextItemModel } from '../../models/card-view-textitem.model'; import { CardViewComponent } from './card-view.component'; -import { CoreTestingModule } from '../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model'; import { of } from 'rxjs'; @@ -30,6 +29,15 @@ import { CardViewItemDispatcherComponent } from '../card-view-item-dispatcher/ca import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatSelectHarness } from '@angular/material/select/testing'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; +import { TranslationService } from '../../../translation'; +import { TranslationMock } from '../../../mock'; +import { MatTooltipModule } from '@angular/material/tooltip'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { MatDialogModule } from '@angular/material/dialog'; +import { MatDatepickerModule } from '@angular/material/datepicker'; +import { MatSelectModule } from '@angular/material/select'; describe('CardViewComponent', () => { let loader: HarnessLoader; @@ -38,7 +46,17 @@ describe('CardViewComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [TranslateModule.forRoot(), CoreTestingModule] + imports: [ + TranslateModule.forRoot(), + NoopAnimationsModule, + MatSnackBarModule, + MatTooltipModule, + MatDialogModule, + MatDatepickerModule, + MatSelectModule, + HttpClientTestingModule + ], + providers: [{ provide: TranslationService, useClass: TranslationMock }] }).compileComponents(); fixture = TestBed.createComponent(CardViewComponent); diff --git a/lib/core/src/lib/clipboard/clipboard.directive.spec.ts b/lib/core/src/lib/clipboard/clipboard.directive.spec.ts index 1dd1666264..b1adb13441 100644 --- a/lib/core/src/lib/clipboard/clipboard.directive.spec.ts +++ b/lib/core/src/lib/clipboard/clipboard.directive.spec.ts @@ -19,20 +19,20 @@ import { Component, ViewChild } from '@angular/core'; import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'; import { ClipboardService } from './clipboard.service'; import { ClipboardDirective } from './clipboard.directive'; -import { CoreTestingModule } from '../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; +import { TranslationService } from '../translation'; +import { TranslationMock } from '../mock'; +import { MatButtonModule } from '@angular/material/button'; @Component({ - selector: 'adf-test-component', - template: ` - + selector: 'adf-test-component', + template: ` + - ` + ` }) class TestTargetClipboardComponent {} @@ -42,13 +42,9 @@ describe('ClipboardDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestTargetClipboardComponent - ] + imports: [TranslateModule.forRoot(), HttpClientTestingModule, MatSnackBarModule, MatButtonModule], + providers: [ClipboardService, { provide: TranslationService, useClass: TranslationMock }], + declarations: [TestTargetClipboardComponent, ClipboardDirective] }); fixture = TestBed.createComponent(TestTargetClipboardComponent); clipboardService = TestBed.inject(ClipboardService); @@ -66,20 +62,18 @@ describe('ClipboardDirective', () => { it('should notify copy target value on keydown event', () => { spyOn(clipboardService, 'copyToClipboard'); fixture.nativeElement.querySelector('input').value = 'some value'; - fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'})); + fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' })); expect(clipboardService.copyToClipboard).toHaveBeenCalled(); }); }); describe('CopyClipboardDirective', () => { - @Component({ - selector: 'adf-copy-conent-test-component', + selector: 'adf-copy-conent-test-component', template: `{{ mockText }}` }) class TestCopyClipboardComponent { - mockText = 'text to copy'; placeholder = 'copy text'; @@ -92,27 +86,23 @@ describe('CopyClipboardDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], - declarations: [ - TestCopyClipboardComponent - ] + imports: [TranslateModule.forRoot(), HttpClientTestingModule, MatSnackBarModule], + providers: [ClipboardService, { provide: TranslationService, useClass: TranslationMock }], + declarations: [TestCopyClipboardComponent, ClipboardDirective] }); fixture = TestBed.createComponent(TestCopyClipboardComponent); element = fixture.debugElement.nativeElement; fixture.detectChanges(); }); - it('should show tooltip when hover element', (() => { + it('should show tooltip when hover element', () => { const spanHTMLElement = element.querySelector('span'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).not.toBeNull(); - })); + }); - it('should not show tooltip when element it is not hovered', (() => { + it('should not show tooltip when element it is not hovered', () => { const spanHTMLElement = element.querySelector('span'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); @@ -121,7 +111,7 @@ describe('CopyClipboardDirective', () => { spanHTMLElement.dispatchEvent(new Event('mouseleave')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).toBeNull(); - })); + }); it('should copy the content of element when click it', fakeAsync(() => { const spanHTMLElement = element.querySelector('span'); @@ -137,7 +127,7 @@ describe('CopyClipboardDirective', () => { const spanHTMLElement = element.querySelector('span'); fixture.detectChanges(); spyOn(navigator.clipboard, 'writeText'); - spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'})); + spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' })); tick(); fixture.detectChanges(); expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy'); diff --git a/lib/core/src/lib/clipboard/clipboard.service.spec.ts b/lib/core/src/lib/clipboard/clipboard.service.spec.ts index cd5ee501f9..dcd04ea4b0 100644 --- a/lib/core/src/lib/clipboard/clipboard.service.spec.ts +++ b/lib/core/src/lib/clipboard/clipboard.service.spec.ts @@ -19,8 +19,10 @@ import { NotificationService } from '../notifications/services/notification.serv import { TestBed } from '@angular/core/testing'; import { ClipboardService } from './clipboard.service'; import { MatSnackBarModule } from '@angular/material/snack-bar'; -import { CoreTestingModule } from '../testing'; import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { TranslationService } from '../translation'; +import { TranslationMock } from '../mock'; describe('ClipboardService', () => { let clipboardService: ClipboardService; @@ -29,11 +31,8 @@ describe('ClipboardService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule, - MatSnackBarModule - ] + imports: [TranslateModule.forRoot(), HttpClientTestingModule, MatSnackBarModule], + providers: [ClipboardService, { provide: TranslationService, useClass: TranslationMock }] }); clipboardService = TestBed.inject(ClipboardService); notificationService = TestBed.inject(NotificationService); @@ -61,8 +60,7 @@ describe('ClipboardService', () => { clipboardService.copyToClipboard(inputElement); expect(inputElement.select).toHaveBeenCalledWith(); - expect(inputElement.setSelectionRange) - .toHaveBeenCalledWith(0, inputElement.value.length); + expect(inputElement.setSelectionRange).toHaveBeenCalledWith(0, inputElement.value.length); expect(navigator.clipboard.writeText).toHaveBeenCalledWith('some text'); }); diff --git a/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts b/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts index 207278046b..05d0a66311 100644 --- a/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts +++ b/lib/core/src/lib/comments/comment-list/comment-list.component.spec.ts @@ -15,33 +15,24 @@ * limitations under the License. */ -import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CommentModel } from '../../models/comment.model'; import { CommentListComponent } from './comment-list.component'; import { By } from '@angular/platform-browser'; -import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; -import { - commentUserNoPictureDefined, - commentUserPictureDefined, - mockCommentOne, - testUser -} from './mocks/comment-list.mock'; +import { commentUserNoPictureDefined, commentUserPictureDefined, mockCommentOne, testUser } from './mocks/comment-list.mock'; import { CommentListServiceMock } from './mocks/comment-list.service.mock'; import { ADF_COMMENTS_SERVICE } from '../interfaces/comments.token'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; describe('CommentListComponent', () => { - let commentList: CommentListComponent; let fixture: ComponentFixture; let element: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [TranslateModule.forRoot(), HttpClientTestingModule], providers: [ { provide: ADF_COMMENTS_SERVICE, @@ -60,22 +51,21 @@ describe('CommentListComponent', () => { fixture.destroy(); }); - it('should emit row click event', fakeAsync(() => { + it('should emit row click event', (done) => { commentList.comments = [mockCommentOne]; commentList.clickRow.subscribe((selectedComment: CommentModel) => { expect(selectedComment.id).toEqual(1); expect(selectedComment.message).toEqual('Test Comment'); expect(selectedComment.createdBy).toEqual(testUser); - expect(selectedComment.isSelected).toBeTruthy(); + done(); }); fixture.detectChanges(); - fixture.whenStable().then(() => { - const comment = fixture.debugElement.query(By.css('.adf-comment-list:first-child')); - comment.triggerEventHandler('click', null); - }); - })); + + const comment = fixture.debugElement.query(By.css('.adf-comment-list-item')); + comment.triggerEventHandler('click', null); + }); it('should not show comment list if no input is given', async () => { fixture.detectChanges(); @@ -123,7 +113,7 @@ describe('CommentListComponent', () => { it('comment date time should start with Yesterday when comment date is yesterday', async () => { const commentOld = new CommentModel(mockCommentOne); - commentOld.created = new Date((Date.now() - 24 * 3600 * 1000)); + commentOld.created = new Date(Date.now() - 24 * 3600 * 1000); commentList.comments = [commentOld]; fixture.detectChanges(); @@ -135,7 +125,7 @@ describe('CommentListComponent', () => { it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => { const commentOld = new CommentModel(mockCommentOne); - commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2)); + commentOld.created = new Date(Date.now() - 24 * 3600 * 1000 * 2); commentList.comments = [commentOld]; fixture.detectChanges(); diff --git a/lib/core/src/lib/comments/comments.component.spec.ts b/lib/core/src/lib/comments/comments.component.spec.ts index f75416afad..13ff300018 100644 --- a/lib/core/src/lib/comments/comments.component.spec.ts +++ b/lib/core/src/lib/comments/comments.component.spec.ts @@ -18,12 +18,13 @@ import { SimpleChange } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CommentsComponent } from './comments.component'; -import { CoreTestingModule } from '../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { CommentsServiceMock, commentsResponseMock } from './mocks/comments.service.mock'; import { of, throwError } from 'rxjs'; import { ADF_COMMENTS_SERVICE } from './interfaces/comments.token'; import { CommentsService } from './interfaces/comments-service.interface'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; describe('CommentsComponent', () => { let component: CommentsComponent; @@ -34,10 +35,7 @@ describe('CommentsComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ], + imports: [NoopAnimationsModule, HttpClientTestingModule, TranslateModule.forRoot()], providers: [ { provide: ADF_COMMENTS_SERVICE, @@ -60,7 +58,7 @@ describe('CommentsComponent', () => { it('should load comments when id specified', () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(getCommentSpy).toHaveBeenCalled(); }); @@ -70,7 +68,7 @@ describe('CommentsComponent', () => { getCommentSpy.and.returnValue(throwError({})); const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(emitSpy).toHaveBeenCalled(); }); @@ -82,7 +80,7 @@ describe('CommentsComponent', () => { it('should display comments when the entity has comments', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -93,7 +91,7 @@ describe('CommentsComponent', () => { it('should display comments count when the entity has comments', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -114,7 +112,7 @@ describe('CommentsComponent', () => { it('should display comments input by default', async () => { const change = new SimpleChange(null, '123', true); - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); fixture.detectChanges(); await fixture.whenStable(); @@ -141,7 +139,7 @@ describe('CommentsComponent', () => { }); it('should fetch new comments when id changed', () => { - component.ngOnChanges({id: change}); + component.ngOnChanges({ id: change }); expect(getCommentSpy).toHaveBeenCalledWith('456'); }); @@ -151,13 +149,12 @@ describe('CommentsComponent', () => { }); it('should not fetch new comments when id changed to null', () => { - component.ngOnChanges({id: nullChange}); + component.ngOnChanges({ id: nullChange }); expect(getCommentSpy).not.toHaveBeenCalled(); }); }); describe('Add comment', () => { - beforeEach(() => { component.id = '123'; fixture.detectChanges(); @@ -229,7 +226,7 @@ describe('CommentsComponent', () => { }); it('should clear comment when escape key is pressed', async () => { - const event = new KeyboardEvent('keydown', {key: 'Escape'}); + const event = new KeyboardEvent('keydown', { key: 'Escape' }); let element = fixture.nativeElement.querySelector('#comment-input'); element.dispatchEvent(event); @@ -271,5 +268,5 @@ describe('CommentsComponent', () => { component.addComment(); expect(addCommentSpy).not.toHaveBeenCalled(); }); - }); + }); }); diff --git a/lib/core/src/lib/common/services/directionality-config.service.spec.ts b/lib/core/src/lib/common/services/directionality-config.service.spec.ts index 91a7ca0cb2..d19c4182fe 100644 --- a/lib/core/src/lib/common/services/directionality-config.service.spec.ts +++ b/lib/core/src/lib/common/services/directionality-config.service.spec.ts @@ -16,20 +16,27 @@ */ import { TestBed } from '@angular/core/testing'; -import { CoreTestingModule } from '../../testing/core.testing.module'; import { UserPreferencesService } from './user-preferences.service'; import { TranslateModule } from '@ngx-translate/core'; -import { CoreModule } from '../../core.module'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { DirectionalityConfigService } from './directionality-config.service'; +import { directionalityConfigFactory } from './directionality-config-factory'; +import { APP_INITIALIZER } from '@angular/core'; describe('DirectionalityConfigService', () => { let userPreferencesService: UserPreferencesService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreModule.forRoot(), - CoreTestingModule + imports: [TranslateModule.forRoot(), HttpClientTestingModule], + providers: [ + UserPreferencesService, + { + provide: APP_INITIALIZER, + useFactory: directionalityConfigFactory, + deps: [DirectionalityConfigService], + multi: true + } ] }); userPreferencesService = TestBed.inject(UserPreferencesService); diff --git a/lib/core/src/lib/common/services/storage.service.spec.ts b/lib/core/src/lib/common/services/storage.service.spec.ts index 755c8f1d56..006a97bf82 100644 --- a/lib/core/src/lib/common/services/storage.service.spec.ts +++ b/lib/core/src/lib/common/services/storage.service.spec.ts @@ -18,30 +18,23 @@ import { TestBed } from '@angular/core/testing'; import { AppConfigService } from '../../app-config/app-config.service'; import { StorageService } from '../../common/services/storage.service'; -import { CoreTestingModule } from '../../testing/core.testing.module'; -import { AppConfigServiceMock } from '../mock/app-config.service.mock'; -import { TranslateModule } from '@ngx-translate/core'; +import { CoreTestingModule } from '../../testing'; +import { RedirectAuthService } from '../../auth'; +import { EMPTY } from 'rxjs'; describe('StorageService', () => { - let storage: StorageService; - let appConfig: AppConfigServiceMock; + let appConfig: AppConfigService; const key = 'test_key'; const value = 'test_value'; - describe('StorageService', () => { + describe('with prefix', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - CoreTestingModule - ] + imports: [CoreTestingModule], + providers: [{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => [] } }] }); appConfig = TestBed.inject(AppConfigService); - appConfig.config = { - application: { - storagePrefix: 'ADF_APP' - } - }; storage = TestBed.inject(StorageService); }); @@ -75,13 +68,11 @@ describe('StorageService', () => { }); }); - describe('StorageService', () => { + describe('without prefix', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule - ] + imports: [CoreTestingModule], + providers: [{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => [] } }] }); appConfig = TestBed.inject(AppConfigService); diff --git a/lib/core/src/lib/common/services/user-preferences.service.spec.ts b/lib/core/src/lib/common/services/user-preferences.service.spec.ts index 0e7a3964ea..0ac9ece9bb 100644 --- a/lib/core/src/lib/common/services/user-preferences.service.spec.ts +++ b/lib/core/src/lib/common/services/user-preferences.service.spec.ts @@ -20,13 +20,13 @@ import { TranslateService, TranslateModule } from '@ngx-translate/core'; import { AppConfigService } from '../../app-config/app-config.service'; import { StorageService } from '../../common/services/storage.service'; import { UserPreferencesService, UserPreferenceValues } from '../../common/services/user-preferences.service'; -import { CoreTestingModule } from '../../testing/core.testing.module'; import { AppConfigServiceMock } from '../mock/app-config.service.mock'; import { AlfrescoApiService } from '../../services/alfresco-api.service'; -import { AlfrescoApiServiceMock } from '../../mock'; +import { AlfrescoApiServiceMock, TranslationMock } from '../../mock'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { TranslationService } from '../../translation'; describe('UserPreferencesService', () => { - const supportedPaginationSize = [5, 10, 15, 20]; let preferences: UserPreferencesService; let storage: StorageService; @@ -36,9 +36,13 @@ describe('UserPreferencesService', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot(), - CoreTestingModule + imports: [TranslateModule.forRoot(), HttpClientTestingModule], + providers: [ + UserPreferencesService, + StorageService, + { provide: TranslationService, useClass: TranslationMock }, + { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }, + { provide: AppConfigService, useClass: AppConfigServiceMock } ] }); appConfig = TestBed.inject(AppConfigService); diff --git a/lib/core/src/lib/testing/core.testing.module.ts b/lib/core/src/lib/testing/core.testing.module.ts index 317b3699b0..80aa5cdef0 100644 --- a/lib/core/src/lib/testing/core.testing.module.ts +++ b/lib/core/src/lib/testing/core.testing.module.ts @@ -53,16 +53,11 @@ import { EMPTY } from 'rxjs'; { provide: APP_INITIALIZER, useFactory: directionalityConfigFactory, - deps: [ DirectionalityConfigService ], + deps: [DirectionalityConfigService], multi: true }, - { provide: RedirectAuthService, useValue: { onLogin: EMPTY } } + { provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => {} } } ], - exports: [ - NoopAnimationsModule, - CoreModule, - TranslateModule, - RouterTestingModule - ] + exports: [NoopAnimationsModule, CoreModule, TranslateModule, RouterTestingModule] }) export class CoreTestingModule {}