From 089da178fe17c9628e70f69aa2685e5e50f02cad Mon Sep 17 00:00:00 2001 From: Dmitriy Myakotin <75628188+MDI74@users.noreply.github.com> Date: Sat, 20 Dec 2025 10:01:07 +0500 Subject: [PATCH 1/3] feat: #20: add error handling from the backend to the workEntryModal --- .../WorkEntryModalContainer.cy.tsx | 41 +++++++++++++++++++ .../WorkEntryModalContainer.tsx | 10 +++++ 2 files changed, 51 insertions(+) diff --git a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx index 159aa73..9533b37 100644 --- a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx +++ b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx @@ -308,6 +308,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({ diff --git a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.tsx b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.tsx index 24cf902..1580879 100644 --- a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.tsx +++ b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.tsx @@ -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, @@ -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() From 05de95daa9856c4bd4b38401ed0464bbb3581787 Mon Sep 17 00:00:00 2001 From: Dmitriy Myakotin <75628188+MDI74@users.noreply.github.com> Date: Sat, 20 Dec 2025 10:08:05 +0500 Subject: [PATCH 2/3] refactor: #20: remove duplication setup date and time to WorkEntryModalContainer tests --- .../WorkEntryModalContainer.cy.tsx | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx index 9533b37..12de174 100644 --- a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx +++ b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx @@ -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`), + setupDefaultDateAndTimeState({ + workEntryModalState, }) }) @@ -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`), + setupDefaultDateAndTimeState({ + workEntryModalState, }) }) @@ -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`), + + setupDefaultDateAndTimeState({ + workEntryModalState, }) }) @@ -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`), + setupDefaultDateAndTimeState({ + workEntryModalState, }) }) @@ -374,3 +351,19 @@ function mountComponent({ , ) } + +function setupDefaultDateAndTimeState({ + 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`), + }) +} From 5356bb117d053ac3c27407d3a99d569347338b5b Mon Sep 17 00:00:00 2001 From: Dmitriy Myakotin <75628188+MDI74@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:18:39 +0500 Subject: [PATCH 3/3] refactor: #20: rename func setupDefaultDateAndTimeState to setDateAndTime --- .../work-entry-modal/WorkEntryModalContainer.cy.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx index 12de174..b3030e0 100644 --- a/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx +++ b/src/pages/time-tracker/sections/work-entry-modal/WorkEntryModalContainer.cy.tsx @@ -31,7 +31,7 @@ function addWorkEntryTests() { beforeEach(() => { workEntryModalState = new WorkEntryModalState() - setupDefaultDateAndTimeState({ + setDateAndTime({ workEntryModalState, }) }) @@ -119,7 +119,7 @@ function updateWorkEntryTests() { description: `Task description`, }) - setupDefaultDateAndTimeState({ + setDateAndTime({ workEntryModalState, }) }) @@ -199,7 +199,7 @@ function onCloseModalTests() { description: `Description`, }) - setupDefaultDateAndTimeState({ + setDateAndTime({ workEntryModalState, }) }) @@ -264,7 +264,7 @@ function setErrorTests() { beforeEach(() => { workEntryModalState = new WorkEntryModalState() - setupDefaultDateAndTimeState({ + setDateAndTime({ workEntryModalState, }) }) @@ -352,7 +352,7 @@ function mountComponent({ ) } -function setupDefaultDateAndTimeState({ +function setDateAndTime({ workEntryModalState, }: { workEntryModalState: WorkEntryModalState,