Skip to content

Commit

Permalink
SMA-82: resolve test error
Browse files Browse the repository at this point in the history
  • Loading branch information
markpernia committed Apr 15, 2024
1 parent 5765839 commit e7c71ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sportsmatch.dtos;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.*;
Expand All @@ -16,8 +17,10 @@ public class EventDTO {
private Long id;

@NotNull
@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
private LocalDateTime dateStart;
@NotNull
@JsonFormat(pattern = "dd-MM-yyyy HH:mm")
private LocalDateTime dateEnd;
@NotNull
private Integer minElo;
Expand Down
27 changes: 4 additions & 23 deletions frontend/sportsmatch-app/src/components/SportEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('SportEvent', async () => {
id: 1,
maxElo: 2000,
minElo: 1800,
dateEnd: [2024, 9, 20, 17, 0],
dateStart: [2024, 9, 20, 15, 0],
dateEnd: '27-01-2024 17:00',
dateStart: '26-01-2024 15:00',
placeDTO: {
name: 'Test Location',
address: 'address',
Expand All @@ -20,35 +20,16 @@ describe('SportEvent', async () => {
player1Name: 'Player One',
player2Name: 'Player Two',
}

const formatDate = (dateArray: string) => {
const [year, month, day, hours, minutes] = dateArray
const formattedDate = `${day.toString().padStart(2, '0')}-${month
.toString()
.padStart(
2,
'0',
)}-${year} ${hours}:${minutes.toString().padStart(2, '0')}`
return formattedDate
}

it('renders the component with correct data', () => {
render(<SportEvent event={mockEvent} />)

// Convert dateStart and dateEnd arrays to formatted strings
const formattedDateStart = formatDate(mockEvent.dateStart)
const formattedDateEnd = formatDate(mockEvent.dateEnd)

console.log('formattedDateStart:', formattedDateStart)
console.log('formattedDateEnd:', formattedDateEnd)

// Assert that the rendered component contains the expected data
expect(screen.getByText(`Test Location`)).toBeInTheDocument()
expect(
screen.getByText(`${mockEvent.minElo} - ${mockEvent.maxElo}`),
).toBeInTheDocument()
expect(screen.getByText(formattedDateStart)).toBeInTheDocument()
expect(screen.getByText(formattedDateEnd)).toBeInTheDocument()
expect(screen.getByText(`${mockEvent.dateStart}`)).toBeInTheDocument()
expect(screen.getByText(`${mockEvent.dateEnd}`)).toBeInTheDocument()
expect(screen.getByText(mockEvent.title)).toBeInTheDocument()

// Check for the presence of react-icons
Expand Down
12 changes: 2 additions & 10 deletions frontend/sportsmatch-app/src/components/SportEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { EventDTO } from '../generated/api'
import '../styles/SportEvent.css'
import { LuMapPin, LuMedal, LuCalendarCheck, LuCalendarX } from 'react-icons/lu'

const formatDate = (dateArray: string) => {
const [year, month, day, hours, minutes] = dateArray
const formattedDate = `${day.toString().padStart(2, '0')}-${month
.toString()
.padStart(2, '0')}-${year} ${hours}:${minutes.toString().padStart(2, '0')}`
return formattedDate
}

function SportEvent({ event }: { event: EventDTO }) {
return (
<>
Expand All @@ -26,11 +18,11 @@ function SportEvent({ event }: { event: EventDTO }) {
</li>
<li data-testid="luCalendarCheck">
<LuCalendarCheck />
{formatDate(event.dateStart)}
{event.dateStart}
</li>
<li data-testid="luCalendarX">
<LuCalendarX />
{formatDate(event.dateEnd)}
{event.dateEnd}
</li>
</ul>
</div>
Expand Down

0 comments on commit e7c71ff

Please sign in to comment.