Skip to content

Commit

Permalink
Añade pruebas para formateo de fechas en español y manejo de idiomas …
Browse files Browse the repository at this point in the history
…no soportados
  • Loading branch information
Yul1b3th committed Jun 17, 2024
1 parent 8ed4f46 commit f8a3d5c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
33 changes: 31 additions & 2 deletions src/app/services/date-formatter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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
})
})
2 changes: 1 addition & 1 deletion src/app/services/date-formatter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,26 @@
</li>
</ul>
</div>

<div class="d-flex gap-3">
<div class="stat d-flex align-items-center">
<div><img src="assets/img/icon/user.svg" alt="User"></div>
<div>IT-Academy</div>


</div>

<div class="stat d-flex align-items-center" ngbTooltip="Empezado y finalizado">
<div><img src="assets/img/icon/bullseye.svg" alt="Bullseye"></div>
<div>87%</div>


</div>

<div class="stat d-flex align-items-center" ngbTooltip="Veces guardado">
<div><img src="assets/img/icon/bookmark.svg" alt="Bookmark"></div>
<div>82</div>


</div>

<div class="stat d-flex align-items-center" ngbTooltip="Fecha creación">
<div><img src="assets/img/icon/clock.svg" alt="Date"></div>
<div>{{formattedDate}}</div>


</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit f8a3d5c

Please sign in to comment.