diff --git a/src/app/services/date-formatter.service.spec.ts b/src/app/services/date-formatter.service.spec.ts index 47b15369..c46e8609 100644 --- a/src/app/services/date-formatter.service.spec.ts +++ b/src/app/services/date-formatter.service.spec.ts @@ -1,16 +1,45 @@ import { TestBed } from '@angular/core/testing' - import { DateFormatterService } from './date-formatter.service' +import { TranslateService } from '@ngx-translate/core' describe('DateFormatterService', () => { let service: DateFormatterService + let translateService: TranslateService beforeEach(() => { - TestBed.configureTestingModule({}) + TestBed.configureTestingModule({ + providers: [ + { + provide: TranslateService, + useValue: { + currentLang: 'en' + } + } + ] + }) service = TestBed.inject(DateFormatterService) + translateService = TestBed.inject(TranslateService) }) it('should be created', () => { expect(service).toBeTruthy() }) + + it('should format date correctly in English', () => { + translateService.currentLang = 'en' + const date = new Date('2023-04-01') + expect(service.format(date)).toEqual('April 01, 2023') + }) + + it('should format date correctly in Spanish', () => { + translateService.currentLang = 'es' + const date = new Date('2023-04-01') + expect(service.format(date)).toEqual('01 abril 2023') + }) + + it('should use default pattern if language is not supported', () => { + translateService.currentLang = 'fr' // French is not supported, so it should fall back to default + const date = new Date('2023-04-01') + expect(service.format(date)).toEqual('01 abril 2023') // Assuming default is Spanish for demonstration + }) }) diff --git a/src/app/services/date-formatter.service.ts b/src/app/services/date-formatter.service.ts index cb908b76..efde0ea3 100644 --- a/src/app/services/date-formatter.service.ts +++ b/src/app/services/date-formatter.service.ts @@ -33,7 +33,7 @@ export class DateFormatterService { } } - // Seleccionar el patrón de formato basado en el idioma + // Selecciona el patrón de formato basado en el idioma private getFormatPattern (lang: string, defaultPattern: string): string { if (lang === 'en') { // Patrón de formato para inglés diff --git a/src/app/shared/components/challenge-card/challenge-card.component.html b/src/app/shared/components/challenge-card/challenge-card.component.html index b39ac081..5a0c2e2e 100755 --- a/src/app/shared/components/challenge-card/challenge-card.component.html +++ b/src/app/shared/components/challenge-card/challenge-card.component.html @@ -28,30 +28,26 @@ +
User
IT-Academy
- -
+
Bullseye
87%
- -
+
Bookmark
82
- -
+
Date
{{formattedDate}}
- -
diff --git a/src/app/shared/components/challenge-card/challenge-card.component.ts b/src/app/shared/components/challenge-card/challenge-card.component.ts index 677daa5a..456dcedf 100755 --- a/src/app/shared/components/challenge-card/challenge-card.component.ts +++ b/src/app/shared/components/challenge-card/challenge-card.component.ts @@ -1,15 +1,13 @@ import { Component, Input, type OnInit, type OnDestroy, inject } from '@angular/core' -import { Subscription } from 'rxjs' +import { type Subscription } from 'rxjs' import { StarterService } from '../../../services/starter.service' import { DateFormatterService } from '../../../services/date-formatter.service' -// Cambia la importación de tipo solamente a una importación normal aquí import { TranslateService } from '@ngx-translate/core' @Component({ selector: 'app-challenge-card', templateUrl: './challenge-card.component.html', - styleUrls: ['./challenge-card.component.scss'], - providers: [] + styleUrls: ['./challenge-card.component.scss'] }) export class ChallengeCardComponent implements OnInit, OnDestroy { private readonly starterService = inject(StarterService) @@ -33,9 +31,7 @@ export class ChallengeCardComponent implements OnInit, OnDestroy { } ngOnDestroy (): void { - if (this.translateSubscription instanceof Subscription) { - this.translateSubscription.unsubscribe() - } + this.translateSubscription.unsubscribe() } private updateFormattedDate (): void {