CFE-26 add skeleton and related test

This commit is contained in:
2023-10-17 10:44:27 +03:30
parent 6b367aeb8c
commit eba943b845
5 changed files with 29 additions and 11 deletions

View File

@@ -104,6 +104,7 @@ export const handler = [
) )
) )
} }
return res(ctx.status(404))
}) })
] ]

View File

@@ -188,5 +188,8 @@
"button-cancel": "انصراف", "button-cancel": "انصراف",
"typography": "آیا از حدف این مورد اطمینان دارید ؟", "typography": "آیا از حدف این مورد اطمینان دارید ؟",
"button-delete": "حذف کردن" "button-delete": "حذف کردن"
},
"CallTabDetails": {
"error_use_answer" : "خطا در برقراری ارتباط"
} }
} }

View File

@@ -2,8 +2,10 @@ import {Skeleton, Stack, Typography} from "@mui/material";
import VisibilityIcon from '@mui/icons-material/Visibility'; import VisibilityIcon from '@mui/icons-material/Visibility';
import useAnswer from "@/lib/callWidget/hooks/useAnswer"; import useAnswer from "@/lib/callWidget/hooks/useAnswer";
import moment from "jalali-moment"; import moment from "jalali-moment";
import {useTranslations} from "next-intl";
const CallTabDetails = ({tab}) => { const CallTabDetails = ({tab}) => {
const t = useTranslations();
const {data, isLoading, error} = useAnswer(tab.id) const {data, isLoading, error} = useAnswer(tab.id)
const dateChange = (date) => { const dateChange = (date) => {
moment.relativeTimeThreshold('s', 60); moment.relativeTimeThreshold('s', 60);
@@ -15,17 +17,15 @@ const CallTabDetails = ({tab}) => {
<Stack alignItems={"start"}> <Stack alignItems={"start"}>
<Typography>{tab.phone_number}</Typography> <Typography>{tab.phone_number}</Typography>
{ {
error ? ( isLoading ? (
<Typography variant="body1" color="error">errror</Typography> <Skeleton width={100} animation="wave"/>
): ):(
( error ? (
isLoading ? ( <Typography variant="caption" color="error">{t("CallTabDetails.error_use_answer")}</Typography>
<Skeleton variant="text" animation="wave"/> ): (
) <Typography variant="caption" color="gray">5 روز پیش</Typography> //dateChange(data.date)
:(
<Typography variant="caption" color="gray">5 روز پیش</Typography> //dateChange(data.date)
)
) )
)
} }
</Stack> </Stack>
</Stack> </Stack>

View File

@@ -31,5 +31,20 @@ describe("Call Tab Details from Call Tan List", ()=>{
expect(dateElement).toHaveTextContent("5 روز پیش") expect(dateElement).toHaveTextContent("5 روز پیش")
}) })
}); });
it('Should see the error message if error happen', async () => {
const tab1 = {
phone_number : "09134849737",
id : 2
}
render(
<MockAppWithProviders>
<CallTabDetails tab={tab1}/>
</MockAppWithProviders>
)
const errorElement = await screen.findByText("خطا در برقراری ارتباط")
await waitFor(()=>{
expect(errorElement).toBeInTheDocument()
})
});
}) })
}) })

View File

@@ -7,7 +7,6 @@ const useAnswer = (id) => {
const fetcher = (...args) => { const fetcher = (...args) => {
return requestServer(args, 'get').then((response) => { return requestServer(args, 'get').then((response) => {
return response.data.data; return response.data.data;
}).catch(() => {
}) })
}; };