From ab2995494153c672fa301aa1f6480ea341784ed3 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 15 Oct 2023 14:17:10 +0330 Subject: [PATCH 01/10] CFE-26 rendering test and some change in callTabsList --- mocks/handler.js | 23 +++++++++++- .../dashboard/role-management/index.jsx | 2 +- .../CallTabs/callTabsList/CallTabDetails.jsx | 34 ++++++++++++++++++ .../CallTabs/callTabsList/CallTabLabel.jsx | 6 ++-- .../__test__/CallTabDetails.test.js | 35 +++++++++++++++++++ .../__test__/CallTableLabel.test.js | 0 .../CallTabs/callTabsList/index.jsx | 2 +- src/core/data/apiRoutes.js | 7 +++- src/lib/callWidget/contexts/answers.jsx | 14 +++++++- src/lib/callWidget/hooks/useAnswer.jsx | 25 +++++++++++++ 10 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js create mode 100644 src/lib/callWidget/hooks/useAnswer.jsx diff --git a/mocks/handler.js b/mocks/handler.js index 8d22664..1f4a712 100644 --- a/mocks/handler.js +++ b/mocks/handler.js @@ -1,4 +1,10 @@ -import {GET_PERMISSIONS_LIST, GET_ROLE_MANAGEMENT, GET_USER_ROUTE, SET_USER_PASSWORD} from "@/core/data/apiRoutes"; +import { + GET_PERMISSIONS_LIST, + GET_ROLE_MANAGEMENT, + GET_TAB_DETAILS, + GET_USER_ROUTE, + SET_USER_PASSWORD +} from "@/core/data/apiRoutes"; import {rest} from "msw"; export const handler = [ @@ -84,5 +90,20 @@ export const handler = [ ), ); }), + rest.get(`${GET_TAB_DETAILS}/:id`, (req,res, ctx) =>{ + const {id} = req.params + if(id == 1){ + return res( + ctx.json( + { + data : { + phone_number : "09134849737", + date : "2023-10-10T13:03:18.000000Z" + } + } + ) + ) + } + }) ] \ No newline at end of file diff --git a/src/components/dashboard/role-management/index.jsx b/src/components/dashboard/role-management/index.jsx index 5251c8b..6376b30 100644 --- a/src/components/dashboard/role-management/index.jsx +++ b/src/components/dashboard/role-management/index.jsx @@ -1,8 +1,8 @@ import RoleManagementComponent from "@/components/dashboard/role-management/RoleManagementComponent"; import DashboardLayout from "@/layouts/DashboardLayout"; +import moment from "jalali-moment"; function DashboardRoleManagementComponent() { - return ( diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx new file mode 100644 index 0000000..6856eec --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx @@ -0,0 +1,34 @@ +import {Skeleton, Stack, Typography} from "@mui/material"; +import VisibilityIcon from '@mui/icons-material/Visibility'; +import useAnswer from "@/lib/callWidget/hooks/useAnswer"; +import moment from "jalali-moment"; + +const CallTabDetails = ({tab}) => { + const {data, isLoading, error} = useAnswer(tab.id) + const dateChange = (date) => { + moment.relativeTimeThreshold('s', 60); + return moment(date).locale("fa").fromNow() + } + return ( + + + + {tab.phone_number} + { + error ? ( + errror + ): + ( + isLoading ? ( + + ) + :( + 5 روز پیش + ) + ) + } + + + ) +} +export default CallTabDetails \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx index 0137265..dc1811a 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx @@ -1,6 +1,8 @@ -import {IconButton, Stack, Typography, Zoom} from "@mui/material"; +import {IconButton, Stack, Zoom} from "@mui/material"; import CloseIcon from '@mui/icons-material/Close'; import useAnswers from "@/lib/callWidget/hooks/useAnswers"; +import CallTabDetails + from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; const CallTabLabel = ({tab}) => { const {closeAnswerTab} = useAnswers() @@ -10,7 +12,7 @@ const CallTabLabel = ({tab}) => { return ( - {tab.phone_number} - {tab.id} + handleCloseClick(tab.id)}> diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js new file mode 100644 index 0000000..9714201 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js @@ -0,0 +1,35 @@ +import {render, screen, waitFor} from "@testing-library/react"; +import MockAppWithProviders from "../../../../../../../../../mocks/AppWithProvider"; +import CallTabDetails + from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; +const tab = { + phone_number : "09134849737", + id : 1 +} + +describe("Call Tab Details from Call Tan List", ()=>{ + describe("Rendering", ()=>{ + it('Should see the phone number on tab detail', async () => { + render( + + + + ) + const phoneNumberElement = screen.getByRole("heading", {level : 6}) + await waitFor(()=>{ + expect(phoneNumberElement).toHaveTextContent("09134849737") + }) + }); + it('Should see the date on tab detail', async () => { + render( + + + + ) + const dateElement = screen.queryByText("5 روز پیش") + await waitFor(()=>{ + expect(dateElement).toHaveTextContent("5 روز پیش") + }) + }); + }) +}) \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx index 249d005..6a9c5ef 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx @@ -17,7 +17,7 @@ const CallTabsList = () => { variant={'fullWidth'} > {answersList.map((answer) => ( - } key={answer.id}/> + } key={answer.id}/> ))} diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 4d0231f..3fc0300 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -24,4 +24,9 @@ export const DELETE_ROLE_MANAGEMENT = export const GET_PERMISSIONS_LIST = BASE_URL + "/api/permissions/list" -//role management \ No newline at end of file +//role management + +//tabs details +export const GET_TAB_DETAILS = + BASE_URL + "/details" +//tabs details \ No newline at end of file diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index a9f7ae2..3e49bce 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -17,7 +17,19 @@ export const AnswersContext = createContext() export const AnswersProvider = ({children}) => { const [openCallDialog, setOpenCallDialog] = useState(false) const [activeTab, setActiveTab] = useState(0) - const [state, dispatch] = useReducer(reducer, []); + const [state, dispatch] = useReducer(reducer, [{ + id:45, + phone_number:'09120630676', + active:true + }, { + id:50, + phone_number:'09120630675', + active:true + }, { + id:55, + phone_number:'09120630672', + active:true + }]); return { + const requestServer = useRequest({auth: true, notification: false}) + const fetcher = (...args) => { + return requestServer(args, 'get').then((response) => { + return response.data.data; + }).catch(() => { + }) + }; + + const {data, error, isLoading} = useSWR(`${GET_TAB_DETAILS}/${id}`, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + keepPreviousData : true + }) + //swr config + + // render data + return {data, isLoading, error} +} +export default useAnswer; \ No newline at end of file From 6b367aeb8c488ec37beec240f8a937b6bc0144b2 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 15 Oct 2023 16:45:36 +0330 Subject: [PATCH 02/10] CFE-26 styling tabs and active --- .../CallTabs/callTabsList/CallTabDetails.jsx | 10 +++++----- .../CallTabs/callTabsList/CallTabLabel.jsx | 17 ++++++++++------ .../__test__/CallTabDetails.test.js | 2 +- .../CallTabs/callTabsList/index.jsx | 11 +++++++--- src/lib/callWidget/contexts/answers.jsx | 20 +++++++++++++++++-- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx index 6856eec..574d4ca 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx @@ -11,19 +11,19 @@ const CallTabDetails = ({tab}) => { } return ( - - - {tab.phone_number} + + + {tab.phone_number} { error ? ( - errror + errror ): ( isLoading ? ( ) :( - 5 روز پیش + 5 روز پیش //dateChange(data.date) ) ) } diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx index dc1811a..877dfb2 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabLabel.jsx @@ -4,18 +4,23 @@ import useAnswers from "@/lib/callWidget/hooks/useAnswers"; import CallTabDetails from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; -const CallTabLabel = ({tab}) => { - const {closeAnswerTab} = useAnswers() +const CallTabLabel = ({tab, index}) => { + const {closeAnswerTab, activeTab} = useAnswers() const handleCloseClick = (id) => { closeAnswerTab(id) }; return ( - - + + - handleCloseClick(tab.id)}> - + handleCloseClick(tab.id)}> + diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js index 9714201..f81920a 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js @@ -15,7 +15,7 @@ describe("Call Tab Details from Call Tan List", ()=>{ ) - const phoneNumberElement = screen.getByRole("heading", {level : 6}) + const phoneNumberElement = screen.getByText("09134849737") await waitFor(()=>{ expect(phoneNumberElement).toHaveTextContent("09134849737") }) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx index 6a9c5ef..898e729 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx @@ -14,10 +14,15 @@ const CallTabsList = () => { - {answersList.map((answer) => ( - } key={answer.id}/> + {answersList.map((answer, index) => ( + } key={answer.id}/> ))} diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index 3e49bce..86033b2 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -20,14 +20,30 @@ export const AnswersProvider = ({children}) => { const [state, dispatch] = useReducer(reducer, [{ id:45, phone_number:'09120630676', - active:true + active:false }, { id:50, phone_number:'09120630675', - active:true + active:false }, { id:55, phone_number:'09120630672', + active:false + }, { + id:60, + phone_number:'09120630672', + active:false + }, { + id:65, + phone_number:'09120630672', + active:false + }, { + id:70, + phone_number:'09120630672', + active:false + }, { + id:75, + phone_number:'09120630672', active:true }]); From eba943b8457f4fa30bbd92e8371ac1ac8f023d8f Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 17 Oct 2023 10:44:27 +0330 Subject: [PATCH 03/10] CFE-26 add skeleton and related test --- mocks/handler.js | 1 + public/locales/fa/app.json | 3 +++ .../CallTabs/callTabsList/CallTabDetails.jsx | 20 +++++++++---------- .../__test__/CallTabDetails.test.js | 15 ++++++++++++++ src/lib/callWidget/hooks/useAnswer.jsx | 1 - 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/mocks/handler.js b/mocks/handler.js index 1f4a712..4610bec 100644 --- a/mocks/handler.js +++ b/mocks/handler.js @@ -104,6 +104,7 @@ export const handler = [ ) ) } + return res(ctx.status(404)) }) ] \ No newline at end of file diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 9e28007..aee579e 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -188,5 +188,8 @@ "button-cancel": "انصراف", "typography": "آیا از حدف این مورد اطمینان دارید ؟", "button-delete": "حذف کردن" + }, + "CallTabDetails": { + "error_use_answer" : "خطا در برقراری ارتباط" } } diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx index 574d4ca..dbd1e1d 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx @@ -2,8 +2,10 @@ import {Skeleton, Stack, Typography} from "@mui/material"; import VisibilityIcon from '@mui/icons-material/Visibility'; import useAnswer from "@/lib/callWidget/hooks/useAnswer"; import moment from "jalali-moment"; +import {useTranslations} from "next-intl"; const CallTabDetails = ({tab}) => { + const t = useTranslations(); const {data, isLoading, error} = useAnswer(tab.id) const dateChange = (date) => { moment.relativeTimeThreshold('s', 60); @@ -15,17 +17,15 @@ const CallTabDetails = ({tab}) => { {tab.phone_number} { - error ? ( - errror - ): - ( - isLoading ? ( - - ) - :( - 5 روز پیش //dateChange(data.date) - ) + isLoading ? ( + + ):( + error ? ( + {t("CallTabDetails.error_use_answer")} + ): ( + 5 روز پیش //dateChange(data.date) ) + ) } diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js index f81920a..707ae3f 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js @@ -31,5 +31,20 @@ describe("Call Tab Details from Call Tan List", ()=>{ expect(dateElement).toHaveTextContent("5 روز پیش") }) }); + it('Should see the error message if error happen', async () => { + const tab1 = { + phone_number : "09134849737", + id : 2 + } + render( + + + + ) + const errorElement = await screen.findByText("خطا در برقراری ارتباط") + await waitFor(()=>{ + expect(errorElement).toBeInTheDocument() + }) + }); }) }) \ No newline at end of file diff --git a/src/lib/callWidget/hooks/useAnswer.jsx b/src/lib/callWidget/hooks/useAnswer.jsx index d0cf0b2..eefecaa 100644 --- a/src/lib/callWidget/hooks/useAnswer.jsx +++ b/src/lib/callWidget/hooks/useAnswer.jsx @@ -7,7 +7,6 @@ const useAnswer = (id) => { const fetcher = (...args) => { return requestServer(args, 'get').then((response) => { return response.data.data; - }).catch(() => { }) }; From 9642f61c8d252c68992b5a90b20959a12ac4b73e Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 17 Oct 2023 16:54:34 +0330 Subject: [PATCH 04/10] CFE-26 finall change and set real time --- mocks/handler.js | 31 ++++---------- .../CallTabs/callTabsList/CallTabDetails.jsx | 33 ++++----------- .../CallTabs/callTabsList/CallTabTime.jsx | 29 +++++++++++++ .../__test__/CallTabDetails.test.js | 41 ++++--------------- .../callTabsList/__test__/CallTabTime.test.js | 25 +++++++++++ .../__test__/CallTableLabel.test.js | 0 .../CallTabs/callTabsList/index.jsx | 19 +++++---- .../CallWidget/CallWidgetDialog/index.jsx | 4 +- src/lib/callWidget/contexts/answers.jsx | 32 +-------------- src/lib/callWidget/hooks/useAnswer.jsx | 24 ----------- src/lib/callWidget/hooks/useAnswers.jsx | 1 + 11 files changed, 93 insertions(+), 146 deletions(-) create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime.jsx create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabTime.test.js delete mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js delete mode 100644 src/lib/callWidget/hooks/useAnswer.jsx diff --git a/mocks/handler.js b/mocks/handler.js index 4610bec..91215d2 100644 --- a/mocks/handler.js +++ b/mocks/handler.js @@ -10,9 +10,9 @@ import {rest} from "msw"; export const handler = [ rest.get(GET_USER_ROUTE, (req, res, ctx) => { return res(ctx.json({ - data:{ + data: { id: 10, - permissions:[ + permissions: [ "manage_users" ], } @@ -26,7 +26,7 @@ export const handler = [ rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => { return res(ctx.json( { - data:[ + data: [ { id: 1, name: "manage_passenger_office_navgan", @@ -35,7 +35,7 @@ export const handler = [ { id: 2, name: "manage_province_working_group_navgan", - name_fa:"مدیریت کارتابل کارگروه استانی" + name_fa: "مدیریت کارتابل کارگروه استانی" } ] } @@ -45,7 +45,7 @@ export const handler = [ return res( ctx.json( { - data : [ + data: [ { created_at: "2023-10-01T07:20:07.000000Z", guard_name: "api", @@ -83,28 +83,11 @@ export const handler = [ updated_at: "2023-10-10T07:38:12.000000Z" } ], - meta : { - totalRowCount : 2 + meta: { + totalRowCount: 2 } } ), ); }), - rest.get(`${GET_TAB_DETAILS}/:id`, (req,res, ctx) =>{ - const {id} = req.params - if(id == 1){ - return res( - ctx.json( - { - data : { - phone_number : "09134849737", - date : "2023-10-10T13:03:18.000000Z" - } - } - ) - ) - } - return res(ctx.status(404)) - - }) ] \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx index dbd1e1d..c92d2df 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails.jsx @@ -1,32 +1,15 @@ -import {Skeleton, Stack, Typography} from "@mui/material"; -import VisibilityIcon from '@mui/icons-material/Visibility'; -import useAnswer from "@/lib/callWidget/hooks/useAnswer"; -import moment from "jalali-moment"; -import {useTranslations} from "next-intl"; +import {Stack, Typography} from "@mui/material"; +import CallIcon from '@mui/icons-material/Call'; +import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime"; const CallTabDetails = ({tab}) => { - const t = useTranslations(); - const {data, isLoading, error} = useAnswer(tab.id) - const dateChange = (date) => { - moment.relativeTimeThreshold('s', 60); - return moment(date).locale("fa").fromNow() - } + return ( - - - + + + {tab.phone_number} - { - isLoading ? ( - - ):( - error ? ( - {t("CallTabDetails.error_use_answer")} - ): ( - 5 روز پیش //dateChange(data.date) - ) - ) - } + ) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime.jsx new file mode 100644 index 0000000..5d627e4 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime.jsx @@ -0,0 +1,29 @@ +import {Typography} from "@mui/material"; +import {useEffect, useState} from "react"; +import moment from "jalali-moment"; +import useLanguage from "@/lib/app/hooks/useLanguage"; + +const CallTabTime = ({realTimeDate}) => { + const {languageApp} = useLanguage() + const [date, setDate] = useState('...') + const changeTabTime = (tabTime) => { + moment.relativeTimeThreshold('ss', 1) + return moment(tabTime).locale(languageApp).fromNow() + } + + useEffect(() => { + const timer = setInterval(() => { + setDate(changeTabTime(realTimeDate)) + }, 1000) + + return () => { + clearInterval(timer) + } + }, [realTimeDate]); + + return ( + {date} + ) +} +export default CallTabTime \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js index 707ae3f..1cdf1fc 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabDetails.test.js @@ -2,49 +2,26 @@ import {render, screen, waitFor} from "@testing-library/react"; import MockAppWithProviders from "../../../../../../../../../mocks/AppWithProvider"; import CallTabDetails from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; + const tab = { - phone_number : "09134849737", - id : 1 + phone_number: "09134849737", + id: 1, + date: new Date() } -describe("Call Tab Details from Call Tan List", ()=>{ - describe("Rendering", ()=>{ +describe("Call Tab Details from Call Tan List", () => { + describe("Rendering", () => { it('Should see the phone number on tab detail', async () => { render( - + ) const phoneNumberElement = screen.getByText("09134849737") - await waitFor(()=>{ + await waitFor(() => { expect(phoneNumberElement).toHaveTextContent("09134849737") }) }); - it('Should see the date on tab detail', async () => { - render( - - - - ) - const dateElement = screen.queryByText("5 روز پیش") - await waitFor(()=>{ - expect(dateElement).toHaveTextContent("5 روز پیش") - }) - }); - it('Should see the error message if error happen', async () => { - const tab1 = { - phone_number : "09134849737", - id : 2 - } - render( - - - - ) - const errorElement = await screen.findByText("خطا در برقراری ارتباط") - await waitFor(()=>{ - expect(errorElement).toBeInTheDocument() - }) - }); + }) }) \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabTime.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabTime.test.js new file mode 100644 index 0000000..3a32640 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTabTime.test.js @@ -0,0 +1,25 @@ +import {render, screen, waitFor} from "@testing-library/react"; +import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime"; +import MockAppWithProviders from "../../../../../../../../../mocks/AppWithProvider"; + +const tab = { + phone_number: "09134849737", + id: 1, + date: new Date() +} + +describe("Call Tab Details from Call Tan List", () => { + describe("Rendering", () => { + it('Should see the date on tab detail', async () => { + render( + + + + ) + + await waitFor(() => { + expect(screen.getByText(/ثانیه پیش/i)).toBeInTheDocument() + }) + }); + }) +}) \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/__test__/CallTableLabel.test.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx index 898e729..ff26544 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/index.jsx @@ -10,19 +10,20 @@ const CallTabsList = () => { }; return ( - + {answersList.map((answer, index) => ( - } key={answer.id}/> + borderTopRightRadius: answer.active ? "16px" : 0, + borderTopLeftRadius: answer.active ? "16px" : 0, + }} label = {} key = {answer.id}/> ))} diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/index.jsx index 728f68d..e7d4278 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/index.jsx @@ -38,8 +38,8 @@ const CallWidgetDialog = () => { return ( diff --git a/src/lib/callWidget/contexts/answers.jsx b/src/lib/callWidget/contexts/answers.jsx index 86033b2..b5c9c0b 100644 --- a/src/lib/callWidget/contexts/answers.jsx +++ b/src/lib/callWidget/contexts/answers.jsx @@ -17,38 +17,10 @@ export const AnswersContext = createContext() export const AnswersProvider = ({children}) => { const [openCallDialog, setOpenCallDialog] = useState(false) const [activeTab, setActiveTab] = useState(0) - const [state, dispatch] = useReducer(reducer, [{ - id:45, - phone_number:'09120630676', - active:false - }, { - id:50, - phone_number:'09120630675', - active:false - }, { - id:55, - phone_number:'09120630672', - active:false - }, { - id:60, - phone_number:'09120630672', - active:false - }, { - id:65, - phone_number:'09120630672', - active:false - }, { - id:70, - phone_number:'09120630672', - active:false - }, { - id:75, - phone_number:'09120630672', - active:true - }]); + const [state, dispatch] = useReducer(reducer, []); return { - const requestServer = useRequest({auth: true, notification: false}) - const fetcher = (...args) => { - return requestServer(args, 'get').then((response) => { - return response.data.data; - }) - }; - - const {data, error, isLoading} = useSWR(`${GET_TAB_DETAILS}/${id}`, fetcher, { - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false, - keepPreviousData : true - }) - //swr config - - // render data - return {data, isLoading, error} -} -export default useAnswer; \ No newline at end of file diff --git a/src/lib/callWidget/hooks/useAnswers.jsx b/src/lib/callWidget/hooks/useAnswers.jsx index f530e36..68f8b46 100644 --- a/src/lib/callWidget/hooks/useAnswers.jsx +++ b/src/lib/callWidget/hooks/useAnswers.jsx @@ -12,6 +12,7 @@ const useAnswers = () => { const newAnswer = { id: data.id, phone_number: data.phone_number, + date: new Date(), active: true } const newList = [...state, newAnswer] From 64be82b292feaebee9003265e1185e72b44a3b22 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 21 Oct 2023 10:03:17 +0330 Subject: [PATCH 05/10] CFE-26 fixed bug --- .../CallTabs/CallTabsList/__test__/CallTabDetails.test.js | 3 ++- .../CallTabs/CallTabsList/__test__/CallTabTime.test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabDetails.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabDetails.test.js index 1cdf1fc..7d50bff 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabDetails.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabDetails.test.js @@ -1,7 +1,8 @@ import {render, screen, waitFor} from "@testing-library/react"; import MockAppWithProviders from "../../../../../../../../../mocks/AppWithProvider"; import CallTabDetails - from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; + from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails"; + const tab = { phone_number: "09134849737", diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabTime.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabTime.test.js index 3a32640..31b9a1b 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabTime.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/__test__/CallTabTime.test.js @@ -1,6 +1,6 @@ import {render, screen, waitFor} from "@testing-library/react"; -import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime"; import MockAppWithProviders from "../../../../../../../../../mocks/AppWithProvider"; +import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabTime"; const tab = { phone_number: "09134849737", From d7b4018b41a2ebe1d8823d2a16e48f2665578c63 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 21 Oct 2023 10:17:41 +0330 Subject: [PATCH 06/10] CFE-26 correct the Delete Form in Role Management --- .../DeleteForm/__test__/DeleteContent.test.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/dashboard/role-management/Form/DeleteForm/__test__/DeleteContent.test.js b/src/components/dashboard/role-management/Form/DeleteForm/__test__/DeleteContent.test.js index 580dcb9..7258e10 100644 --- a/src/components/dashboard/role-management/Form/DeleteForm/__test__/DeleteContent.test.js +++ b/src/components/dashboard/role-management/Form/DeleteForm/__test__/DeleteContent.test.js @@ -1,51 +1,51 @@ -import {act, render, screen} from "@testing-library/react"; +import {act, render, screen, waitFor} from "@testing-library/react"; import MockAppWithProviders from "../../../../../../../mocks/AppWithProvider"; import DeleteContent from "@/components/dashboard/role-management/Form/DeleteForm/DeleteContent"; import UpdateContent from "@/components/dashboard/role-management/Form/UpdateForm/UpdateContent"; -describe("Create Content component from Create Form Component in Role Management Component",()=> { +describe("Create Content component from Create Form Component in Role Management Component", () => { describe("Rendering", () => { it('should see DeleteDialog text in the top ', async () => { render( - + ) const textElement = screen.queryByText("حذف") - act(()=>{ + await waitFor(() => { expect(textElement).toBeInTheDocument() }) }) it('should see DeleteDialog text content ', async () => { render( - + ) const textElement = screen.queryByText("آیا از حدف این مورد اطمینان دارید ؟") - act(()=>{ + await waitFor(() => { expect(textElement).toBeInTheDocument() }) }) - it('should see delete text in the delete button ', () => { + it('should see delete text in the delete button ', async () => { render( - + ) const buttonElement = screen.queryByText("حذف کردن") - act(()=>{ + await waitFor(() => { expect(buttonElement).toBeInTheDocument() }) }); - it('should see cancel text in the cancel button ', () => { + it('should see cancel text in the cancel button ', async () => { render( - + ) const buttonElement = screen.queryByText("انصراف") - act(()=>{ + await waitFor(() => { expect(buttonElement).toBeInTheDocument() }) }); From d430b814b653bdd585933c26b6f826bd9841ece3 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 21 Oct 2023 10:30:10 +0330 Subject: [PATCH 07/10] CFE-26 correct Call Tab Details --- .../CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails.jsx index c92d2df..9427201 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails.jsx @@ -1,6 +1,6 @@ import {Stack, Typography} from "@mui/material"; import CallIcon from '@mui/icons-material/Call'; -import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabTime"; +import CallTabTime from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabTime"; const CallTabDetails = ({tab}) => { From b3b2a064d3c53accf8a5ca705c9773c7d3ed2047 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 21 Oct 2023 10:58:43 +0330 Subject: [PATCH 08/10] CFE-26 correct Call Tab label --- .../CallTabs/CallTabsList/CallTabLabel.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabLabel.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabLabel.jsx index 877dfb2..e49bcdc 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabLabel.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabLabel.jsx @@ -2,7 +2,7 @@ import {IconButton, Stack, Zoom} from "@mui/material"; import CloseIcon from '@mui/icons-material/Close'; import useAnswers from "@/lib/callWidget/hooks/useAnswers"; import CallTabDetails - from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/callTabsList/CallTabDetails"; + from "@/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabsList/CallTabDetails"; const CallTabLabel = ({tab, index}) => { const {closeAnswerTab, activeTab} = useAnswers() @@ -11,16 +11,16 @@ const CallTabLabel = ({tab, index}) => { }; return ( - - - - handleCloseClick(tab.id)}> - + }} direction = {'row'} alignItems = {'center'} justifyContent = {'space-between'}> + + + handleCloseClick(tab.id)}> + From 8b3415120defc98d24420745365d25725f1cd633 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 21 Oct 2023 11:18:43 +0330 Subject: [PATCH 09/10] CFE-26 change fontiran.scss to fontiran.css --- public/{fontiran.scss => fontiran.css} | 0 src/pages/_app.jsx | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) rename public/{fontiran.scss => fontiran.css} (100%) diff --git a/public/fontiran.scss b/public/fontiran.css similarity index 100% rename from public/fontiran.scss rename to public/fontiran.css diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index c5fad77..4cd2a1d 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -1,4 +1,4 @@ -import "&/fontiran.scss"; +import "&/fontiran.css"; import AppLayout from "@/layouts/AppLayout"; import MuiLayout from "@/layouts/MuiLayout"; import {LanguageProvider} from "@/lib/app/contexts/language"; @@ -14,11 +14,11 @@ const App = ({Component, pageProps}) => { return (<> - - - {pageProps.messages ? : ''} + + + {pageProps.messages ? : ''} - + From 5fc0f5df79be0bea631150444bc3ba39642c92a3 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Sat, 21 Oct 2023 12:41:35 +0330 Subject: [PATCH 10/10] CFE-26 remove stage test:build from .gitlab-ci.yml --- .gitlab-ci.yml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27bf1b1..fd06551 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,17 +44,17 @@ merge:test:lint: - .env.local - .env.test -merge:test:build: - stage: test:build - script: - - npm run build - only: - - merge_requests - artifacts: - paths: - - node_modules - - .env.local - - .env.test +#merge:test:build: +# stage: test:build +# script: +# - npm run build +# only: +# - merge_requests +# artifacts: +# paths: +# - node_modules +# - .env.local +# - .env.test build: stage: build @@ -97,18 +97,18 @@ test:lint: - .env.local - .env.test -test:build: - stage: test:build - script: - - npm run build - only: - - develop - - main - artifacts: - paths: - - node_modules - - .env.local - - .env.test +#test:build: +# stage: test:build +# script: +# - npm run build +# only: +# - develop +# - main +# artifacts: +# paths: +# - node_modules +# - .env.local +# - .env.test deploy: stage: deploy