Skip to content

Commit

Permalink
Merge pull request #161 from wizelineacademy/data-test-fix
Browse files Browse the repository at this point in the history
fix: Fixed general data tests
  • Loading branch information
JulioEmmmanuel authored Jun 13, 2024
2 parents 6cd2cbe + d05d81f commit 11ed092
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
11 changes: 7 additions & 4 deletions cypress/e2e/GeneralData.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ describe('GeneralData E2E Test', () => {
currentDate.getMonth(),
currentDate.getDate(),
)
const formattedDate = recentDate.toISOString().split('T')[0]

cy.get('input[name="birthDate"]')
.clear({ force: true })
.type(formattedDate, { force: true })
const year = recentDate.getFullYear()
const month = (recentDate.getMonth() + 1).toString().padStart(2, '0')
const day = recentDate.getDate().toString().padStart(2, '0')
const formattedDate = `${year}-${month}-${day}`
console.log(formattedDate)

cy.get('input[name="birthDate"]').type(formattedDate, { force: true })

// Save the changes
cy.get('button').contains('Guardar Cambios').click()
Expand Down
21 changes: 11 additions & 10 deletions src/app/(pages)/(main)/home/generalData/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ const GeneralData = () => {
// Validar si se está editando la fecha de nacimiento
if (name === 'birthDate') {
const selectedDate = new Date(value)
// Validar si la fecha seleccionada es menor a 15 años antes de la fecha actual
if (selectedDate > minDate) {
Swal.fire({
title: 'Error',
text: 'La fecha de nacimiento no puede ser menor a 15 años antes de la fecha actual',
icon: 'error',
confirmButtonText: 'OK',
})
return // Salir de la función si la fecha no es válida
}
// Si la fecha es válida, actualizar los datos editados
const formattedDate = selectedDate.toISOString().split('T')[0]
setEditedData({ ...editedData, [name]: formattedDate })
Expand Down Expand Up @@ -73,6 +63,17 @@ const GeneralData = () => {
const handleSaveChanges = async () => {
try {
if (editedData) {
// Validar si la fecha seleccionada es menor a 15 años antes de la fecha actual
if (new Date(editedData.birthDate) > minDate) {
Swal.fire({
title: 'Error',
text: 'La fecha de nacimiento no puede ser menor a 15 años antes de la fecha actual',
icon: 'error',
confirmButtonText: 'OK',
})
return // Salir de la función si la fecha no es válida
}

await axios.post('/api/healthdata', editedData)

Swal.fire({
Expand Down

0 comments on commit 11ed092

Please sign in to comment.