Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mock does not necessarily need TranslationModule to be provided #119

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'
import { Injectable, Optional } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { combineLatest, of } from 'rxjs'
// eslint-disable-next-line
Expand All @@ -15,7 +15,7 @@ export function providePortalMessageServiceMock() {

@Injectable()
export class PortalMessageServiceMock {
constructor(private translateService: TranslateService) {}
constructor(@Optional() private translateService?: TranslateService) {}
lastMessages: { type: 'success' | 'info' | 'error' | 'warning'; value: Message }[] = []
message$ = new FakeTopic<TopicMessage>()

Expand All @@ -40,16 +40,20 @@ export class PortalMessageServiceMock {
}

private addTranslated(severity: string, msg: Message) {
combineLatest([
msg.summaryKey ? this.translateService.get(msg.summaryKey || '', msg.summaryParameters) : of(undefined),
msg.detailKey ? this.translateService.get(msg.detailKey, msg.detailParameters) : of(undefined),
]).subscribe(([summaryTranslation, detailTranslation]: string[]) => {
this.message$.publish({
...msg,
severity: severity,
summary: summaryTranslation,
detail: detailTranslation,
if (this.translateService) {
combineLatest([
msg.summaryKey ? this.translateService.get(msg.summaryKey || '', msg.summaryParameters) : of(undefined),
msg.detailKey ? this.translateService.get(msg.detailKey, msg.detailParameters) : of(undefined),
]).subscribe(([summaryTranslation, detailTranslation]: string[]) => {
this.message$.publish({
...msg,
severity: severity,
summary: summaryTranslation,
detail: detailTranslation,
})
})
})
} else {
console.log('TranslationModule not imported in TestBed. Therefore message$ is not updated.')
}
}
}
Loading