Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ function addWorkEntryTests() {
beforeEach(() => {
workEntryModalState = new WorkEntryModalState()

workEntryModalState.setDate({
date: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setStartTime({
startTime: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setEndTime({
endTime: new Date(`2025-11-27T11:30:00`),
setDateAndTime({
workEntryModalState,
})
})

Expand Down Expand Up @@ -125,16 +119,8 @@ function updateWorkEntryTests() {
description: `Task description`,
})

workEntryModalState.setDate({
date: new Date(`2025-11-27T09:00:00`),
})

workEntryModalState.setStartTime({
startTime: new Date(`2025-11-27T09:00:00`),
})

workEntryModalState.setEndTime({
endTime: new Date(`2025-11-27T11:30:00`),
setDateAndTime({
workEntryModalState,
})
})

Expand Down Expand Up @@ -204,20 +190,17 @@ function onCloseModalTests() {
workEntryModalState.setTitle({
title: `Title`,
})

workEntryModalState.setTaskId({
taskId: `TaskId`,
})

workEntryModalState.setDescription({
description: `Description`,
})
workEntryModalState.setDate({
date: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setStartTime({
startTime: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setEndTime({
endTime: new Date(`2025-11-27T11:30:00`),

setDateAndTime({
workEntryModalState,
})
})

Expand Down Expand Up @@ -281,14 +264,8 @@ function setErrorTests() {
beforeEach(() => {
workEntryModalState = new WorkEntryModalState()

workEntryModalState.setDate({
date: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setStartTime({
startTime: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setEndTime({
endTime: new Date(`2025-11-27T11:30:00`),
setDateAndTime({
workEntryModalState,
})
})

Expand All @@ -308,6 +285,47 @@ function setErrorTests() {

cy.contains(`Fill in all the fields`)
})

it(`
GIVEN opened work entry modal
WHEN click on submit button
AND server validation error will be returned
SHOULD display error message
`, () => {
cy
.intercept(
`POST`,
`*/time/tracking/work-entries`,
{
statusCode: 400,
body: {
detail: `Error message`,
},
},
)

workEntryModalState.setTitle({
title: `Task name`,
})

workEntryModalState.setTaskId({
taskId: `1`,
})

workEntryModalState.setDescription({
description: `Task description`,
})

mountComponent({
workEntryModalState,
})

cy
.contains(`Add Task`)
.click()

cy.contains(`Error message`)
})
}

function mountComponent({
Expand All @@ -333,3 +351,19 @@ function mountComponent({
</WorkEntryModalStateContext.Provider>,
)
}

function setDateAndTime({
workEntryModalState,
}: {
workEntryModalState: WorkEntryModalState,
}) {
workEntryModalState.setDate({
date: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setStartTime({
startTime: new Date(`2025-11-27T09:00:00`),
})
workEntryModalState.setEndTime({
endTime: new Date(`2025-11-27T11:30:00`),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useContext } from "react"
import { WorkEntryModalStateContext } from "./state/WorkEntryModalStateContext"
import { concatDateAndTime } from "../../utils/date-and-time"
import { api } from "../../../../common/api/api"
import axios from "axios"

export const WorkEntryModalContainer = observer(({
onClose,
Expand Down Expand Up @@ -71,6 +72,15 @@ export const WorkEntryModalContainer = observer(({

workEntryModalState.resetError()
}
catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
workEntryModalState.setError({
error: error.response.data.detail,
})
}
}
}
finally {
workEntryModalState.resetIsSaving()
workEntryModalState.resetIsTriedToSubmit()
Expand Down
Loading