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 @@ +