diff --git a/src/main/webapp/app/shared/pipes/artemis-translate.pipe.ts b/src/main/webapp/app/shared/pipes/artemis-translate.pipe.ts index 25683a331f79..09ad55705b29 100644 --- a/src/main/webapp/app/shared/pipes/artemis-translate.pipe.ts +++ b/src/main/webapp/app/shared/pipes/artemis-translate.pipe.ts @@ -4,16 +4,16 @@ import { TranslatePipe, TranslateService } from '@ngx-translate/core'; @Pipe({ name: 'artemisTranslate', pure: false, + standalone: true, }) /** * a simple wrapper to prevent compile errors in IntelliJ */ export class ArtemisTranslatePipe implements PipeTransform, OnDestroy { private translatePipe: TranslatePipe; - constructor( - private translateService: TranslateService, - private changeDetectorRef: ChangeDetectorRef, - ) { + + // We cannot inject() ChangeDetectorRef here + constructor(translateService: TranslateService, changeDetectorRef: ChangeDetectorRef) { this.translatePipe = new TranslatePipe(translateService, changeDetectorRef); } diff --git a/src/main/webapp/app/shared/shared-common.module.ts b/src/main/webapp/app/shared/shared-common.module.ts index b87350bce6bd..f4125cd1e04c 100644 --- a/src/main/webapp/app/shared/shared-common.module.ts +++ b/src/main/webapp/app/shared/shared-common.module.ts @@ -15,7 +15,7 @@ import { CloseCircleComponent } from 'app/shared/close-circle/close-circle.compo import { ArtemisDateRangePipe } from 'app/shared/pipes/artemis-date-range.pipe'; @NgModule({ - imports: [ArtemisSharedLibsModule, TranslateDirective], + imports: [ArtemisSharedLibsModule, TranslateDirective, ArtemisTranslatePipe], declarations: [ ArtemisDatePipe, ArtemisDateRangePipe, @@ -27,7 +27,6 @@ import { ArtemisDateRangePipe } from 'app/shared/pipes/artemis-date-range.pipe'; ArtemisDurationFromSecondsPipe, DurationPipe, CloseCircleComponent, - ArtemisTranslatePipe, ], exports: [ ArtemisSharedLibsModule, diff --git a/src/test/javascript/spec/component/assessment-shared/assessment-header.component.spec.ts b/src/test/javascript/spec/component/assessment-shared/assessment-header.component.spec.ts index 77579a21df71..24821a4f3adb 100644 --- a/src/test/javascript/spec/component/assessment-shared/assessment-header.component.spec.ts +++ b/src/test/javascript/spec/component/assessment-shared/assessment-header.component.spec.ts @@ -7,7 +7,7 @@ import { ArtemisTestModule } from '../../test.module'; import { Result } from 'app/entities/result.model'; import { AlertOverlayComponent } from 'app/shared/alert/alert-overlay.component'; import { AssessmentWarningComponent } from 'app/assessment/assessment-warning/assessment-warning.component'; -import { MockProvider } from 'ng-mocks'; +import { MockPipe, MockProvider } from 'ng-mocks'; import { Exercise, ExerciseType } from 'app/entities/exercise.model'; import { MockSyncStorage } from '../../helpers/mocks/service/mock-sync-storage.service'; import { LocalStorageService, SessionStorageService } from 'ngx-webstorage'; @@ -49,8 +49,8 @@ describe('AssessmentHeaderComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ArtemisTestModule, NgbTooltipMocksModule, NgbAlertsMocksModule, RouterModule.forRoot([])], - declarations: [AssessmentHeaderComponent, AssessmentWarningComponent, AlertOverlayComponent, ArtemisTranslatePipe, MockTranslateValuesDirective], + imports: [ArtemisTestModule, NgbTooltipMocksModule, NgbAlertsMocksModule, RouterModule.forRoot([]), MockPipe(ArtemisTranslatePipe)], + declarations: [AssessmentHeaderComponent, AssessmentWarningComponent, AlertOverlayComponent, MockTranslateValuesDirective], providers: [ { provide: AlertService, diff --git a/src/test/javascript/spec/component/shared/metis/posting-content/posting-content-part.component.spec.ts b/src/test/javascript/spec/component/shared/metis/posting-content/posting-content-part.component.spec.ts index 424567dd6518..245f54d59a62 100644 --- a/src/test/javascript/spec/component/shared/metis/posting-content/posting-content-part.component.spec.ts +++ b/src/test/javascript/spec/component/shared/metis/posting-content/posting-content-part.component.spec.ts @@ -29,33 +29,39 @@ describe('PostingContentPartComponent', () => { let contentBeforeReference: string; let contentAfterReference: string; - beforeEach(() => { - return TestBed.configureTestingModule({ - imports: [ArtemisTestModule, MatDialogModule, MatMenuModule], + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ + ArtemisTestModule, + MatDialogModule, + MatMenuModule, + HtmlForPostingMarkdownPipe, // we want to test against the rendered string, therefore we cannot mock the pipe + ], declarations: [ PostingContentPartComponent, - HtmlForPostingMarkdownPipe, // we want to test against the rendered string, therefore we cannot mock the pipe // FaIconComponent, // we want to test the type of rendered icons, therefore we cannot mock the component MockRouterLinkDirective, MockQueryParamsDirective, ], - providers: [{ provide: FileService, useClass: MockFileService }, { provide: Router, useClass: MockRouter }, MockProvider(AccountService)], - }) - .compileComponents() - .then(() => { - fixture = TestBed.createComponent(PostingContentPartComponent); - component = fixture.componentInstance; - debugElement = fixture.debugElement; - router = TestBed.inject(Router); - fileService = TestBed.inject(FileService); - - navigateByUrlSpy = jest.spyOn(router, 'navigateByUrl'); - openAttachmentSpy = jest.spyOn(fileService, 'downloadFile'); - enlargeImageSpy = jest.spyOn(component, 'enlargeImage'); - - contentBeforeReference = '**Be aware**\n\n I want to reference the following Post '; - contentAfterReference = 'in my content,\n\n does it *actually* work?'; - }); + providers: [ + { provide: FileService, useClass: MockFileService }, + { + provide: Router, + useClass: MockRouter, + }, + MockProvider(AccountService), + ], + }).compileComponents(); + fixture = TestBed.createComponent(PostingContentPartComponent); + component = fixture.componentInstance; + debugElement = fixture.debugElement; + router = TestBed.inject(Router); + fileService = TestBed.inject(FileService); + navigateByUrlSpy = jest.spyOn(router, 'navigateByUrl'); + openAttachmentSpy = jest.spyOn(fileService, 'downloadFile'); + enlargeImageSpy = jest.spyOn(component, 'enlargeImage'); + contentBeforeReference = '**Be aware**\n\n I want to reference the following Post '; + contentAfterReference = 'in my content,\n\n does it *actually* work?'; }); describe('For posting without reference', () => { diff --git a/src/test/javascript/spec/pipe/reacting-users-on-posting.pipe.spec.ts b/src/test/javascript/spec/pipe/reacting-users-on-posting.pipe.spec.ts index de9df276eb53..5bafc94be616 100644 --- a/src/test/javascript/spec/pipe/reacting-users-on-posting.pipe.spec.ts +++ b/src/test/javascript/spec/pipe/reacting-users-on-posting.pipe.spec.ts @@ -4,6 +4,7 @@ import { MockTranslateService } from '../helpers/mocks/service/mock-translate.se import { PLACEHOLDER_USER_REACTED, ReactingUsersOnPostingPipe } from 'app/shared/pipes/reacting-users-on-posting.pipe'; import { TranslateService } from '@ngx-translate/core'; import { metisTutor, metisUser1, metisUser2 } from '../helpers/sample/metis-sample-data'; +import { MockPipe } from 'ng-mocks'; describe('ReactingUsersOnPostingsPipe', () => { let reactingUsersPipe: ReactingUsersOnPostingPipe; @@ -11,9 +12,9 @@ describe('ReactingUsersOnPostingsPipe', () => { let updateReactingUsersStringSpy: jest.SpyInstance; let transformedStringWithReactingUsers: string; - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [HtmlForPostingMarkdownPipe], + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [MockPipe(HtmlForPostingMarkdownPipe)], providers: [{ provide: TranslateService, useClass: MockTranslateService }], }) .compileComponents()