From fafc61b320179b46eef5dddf6a597785af301d31 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sun, 29 Oct 2023 10:38:50 +0330 Subject: [PATCH] CFE-2 write tests --- .../ActionHeader/__test__/index.test.js | 43 +++++++++++++++++++ .../CallActions/ActionHeader/index.jsx | 4 +- .../CallActionCategoriesButton.jsx | 1 + .../CallActionCategoriesButton.test.js | 24 ++++++++++- .../__test__/index.test.js | 29 +++++++++++++ .../CallActionCategories/index.jsx | 4 +- .../CallActionSubcategoriesButton.jsx | 2 +- .../CallActionSubcategoriesButton.test.js | 42 ++++++++---------- .../__test__/index.test.js | 29 +++++++++++++ .../CallActionSubcategories/index.jsx | 4 +- src/lib/callWidget/hooks/useCallerHistory.jsx | 4 +- 11 files changed, 152 insertions(+), 34 deletions(-) create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/__test__/index.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionCategories/__test__/index.test.js create mode 100644 src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/index.test.js diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/__test__/index.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/__test__/index.test.js new file mode 100644 index 0000000..69f9b52 --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/__test__/index.test.js @@ -0,0 +1,43 @@ +import {render, screen, waitFor} from "@testing-library/react"; +import MockAppWithProviders from "../../../../../../../../../../../mocks/AppWithProvider"; +import {AnswersProvider} from "@/lib/callWidget/contexts/answers"; +import ActionHeader from ".."; + +const tab = { + active: true, + active_category_id: 1, + phone_number : "09134849737" +} + +describe('Action Header Button from Call Actions Categories', () => { + describe('Rendering', () => { + it('should see header text', async () => { + render( + + + + + + ) + const headingElement = screen.getByRole('heading', { + name: /\.\.\.\. عملیات های مربوط به تماس:/i + }) + await waitFor(() => { + expect(headingElement).toBeInTheDocument() + }) + }); + it('should see phone number', async () => { + render( + + + + + + ) + const phone_numberElement = screen.queryByText(/09134849737/i) + await waitFor(() => { + expect(phone_numberElement).toBeInTheDocument() + }) + }); + }); +}); \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/index.jsx index 9ae87c0..97b4297 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/ActionHeader/index.jsx @@ -15,11 +15,11 @@ const ActionHeader = ({tab}) => { .... {t("CallAction.call_history_of")}: - + {tab.phone_number} .... ) } -export default ActionHeader +export default ActionHeader \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionCategories/CallActionCategoriesButton.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionCategories/CallActionCategoriesButton.jsx index f568732..40c2b18 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionCategories/CallActionCategoriesButton.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionCategories/CallActionCategoriesButton.jsx @@ -8,6 +8,7 @@ const CallActionCategoriesButton = ({ category, tab }) => { diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/CallActionSubcategoriesButton.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/CallActionSubcategoriesButton.test.js index 55e69e0..718f7cd 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/CallActionSubcategoriesButton.test.js +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/CallActionSubcategoriesButton.test.js @@ -3,39 +3,35 @@ import MockAppWithProviders from "../../../../../../../../../../../mocks/AppWith import {AnswersProvider} from "@/lib/callWidget/contexts/answers"; import CallActionSubcategoriesButton from "../CallActionSubcategoriesButton"; -const sub_category = [ - { - category_id: 1, - category_name: "اطلاعات راه", - subcategory_id: 1, - subcategory_name:"اطلاعات باز و بسته" - } -] +const sub_category = { + category_id: 1, + category_name: "اطلاعات راه", + subcategory_id: 1, + subcategory_name: "اطلاعات باز و بسته" +}; -const tab = [ - { - active: true, - active_category_id: 1, - date: new Date(), - id: 1, - phone_number: "09134849737" - } -] +const tab = { + active: true, + active_category_id: 1, + date: new Date(), + id: 1, + phone_number: "09134849737" +}; describe('Call Action Subcategories Button from Call Actions Categories', () => { describe('Rendering', () => { - it('should categories names', async () => { + it('should render subcategory name', async () => { render( - ) - const subCategoryElement = screen.queryByText("اطلاعات باز و بسته") - await waitFor(()=>{ - expect(subCategoryElement).toBeInTheDocument() - }) + ); + const subCategoryElement = screen.queryByText(/اطلاعات باز و بسته/i); + await waitFor(() => { + expect(subCategoryElement).toBeInTheDocument(); + }); }); }); }); \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/index.test.js b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/index.test.js new file mode 100644 index 0000000..2195bde --- /dev/null +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/__test__/index.test.js @@ -0,0 +1,29 @@ +import { AnswersProvider } from "@/lib/callWidget/contexts/answers"; +import CallActionsSubcategories from ".."; +import MockAppWithProviders from "../../../../../../../../../../../mocks/AppWithProvider"; +import { render, screen, waitFor } from "@testing-library/react"; + +const tab = { + active: true, + active_category_id: 1, + id : 1, + phone_number : "09134849737" +} + +describe('Call Action Categories Button from Call Actions Categories', () => { + describe('Rendering', () => { + it('should see divider text', async () => { + render( + + + + + + ) + const divider_textElement = screen.queryByText("زیر موضوع ها") + await waitFor(() => { + expect(divider_textElement).toBeInTheDocument() + }) + }); + }); +}) \ No newline at end of file diff --git a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/index.jsx b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/index.jsx index dba6fc1..0978e4d 100644 --- a/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/index.jsx +++ b/src/components/layouts/Dashboard/CallWidget/CallWidgetDialog/CallTabs/CallTabPanel/CallActions/CallActionSubcategories/index.jsx @@ -9,8 +9,8 @@ const CallActionsSubcategories = ({ tab }) => { return ( <> - - + + {subCategoryLists.map((sub_category, index) => { return ; })} diff --git a/src/lib/callWidget/hooks/useCallerHistory.jsx b/src/lib/callWidget/hooks/useCallerHistory.jsx index 68ee6d0..810209d 100644 --- a/src/lib/callWidget/hooks/useCallerHistory.jsx +++ b/src/lib/callWidget/hooks/useCallerHistory.jsx @@ -29,8 +29,8 @@ const useCallerHistory = (call_id, phone_number, max_size) => { return { firstItemOfHistory: validData.length === 0 ? false : validData[0], historyList: validData.length < 2 ? false : validData.slice(1), - isLoadingHistoryList: true, - errorHistoryList: false + isLoadingHistoryList: isLoading, + errorHistoryList: !data } };