diff --git a/vakilpors-front/src/App.test.js b/vakilpors-front/src/App.test.js
index 4de7037e0..9c15a15f7 100644
--- a/vakilpors-front/src/App.test.js
+++ b/vakilpors-front/src/App.test.js
@@ -1,8 +1,71 @@
-import { render, screen } from '@testing-library/react';
+import React from 'react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import axios from 'axios';
+import MockAdapter from 'axios-mock-adapter';
+import { BrowserRouter as Router } from 'react-router-dom';
import App from './App';
-test('renders learn react link', () => {
- render();
- const linkElement = screen.getByText(/learn react/i);
- expect(linkElement).toBeInTheDocument();
+const mockAxios = new MockAdapter(axios);
+
+const mockLawyers = [
+ {
+ id: 134,
+ user: {
+ id: 13,
+ name: "ترانه",
+ },
+ title: null,
+ city: null,
+ },
+ {
+ id: 1,
+ user: {
+ id: 100,
+ name: "شادی هراتی",
+ },
+ title: "معاضدتی",
+ city: "گلستان",
+ },
+];
+
+mockAxios.onGet(`${BASE_API_ROUTE}Lawyer/GetAll`).reply(200, {
+ data: mockLawyers,
+});
+
+describe('App component', () => {
+ it('renders learn react link', () => {
+ render();
+ const linkElement = screen.getByText(/learn react/i);
+ expect(linkElement).toBeInTheDocument();
+ });
+
+ it('renders the App component with lawyer information and advertising', async () => {
+ render(
+
+
+
+ );
+
+ await waitFor(() => expect(screen.getByText(mockLawyers[0].user.name)).toBeInTheDocument());
+
+ expect(screen.getByText(`عنوان: ${mockLawyers[0].title ? mockLawyers[0].title : "وکیل"}`)).toBeInTheDocument();
+ expect(screen.getByText(`شهر: ${mockLawyers[0].city ? mockLawyers[0].city : "نامشخص"}`)).toBeInTheDocument();
+
+ expect(screen.getByText(mockLawyers[1].user.name)).toBeInTheDocument();
+ expect(screen.getByText(`عنوان: ${mockLawyers[1].title ? mockLawyers[1].title : "وکیل"}`)).toBeInTheDocument();
+ expect(screen.getByText(`شهر: ${mockLawyers[1].city ? mockLawyers[1].city : "نامشخص"}`)).toBeInTheDocument();
+ });
+
+ it('navigates to Lawyer-search-page when "جست و جوی وکلا" button is clicked', async () => {
+ const { getByText } = render(
+
+
+
+ );
+
+ userEvent.click(getByText('جست و جوی وکلا'));
+
+ await waitFor(() => expect(window.location.pathname).toBe('/Lawyer-search-page'));
+ });
});
diff --git a/vakilpors-front/src/components/premium-page/MovingBarComponent;.jsx b/vakilpors-front/src/components/premium-page/MovingBarComponent;.jsx
index 2a42620a7..70b832ec6 100644
--- a/vakilpors-front/src/components/premium-page/MovingBarComponent;.jsx
+++ b/vakilpors-front/src/components/premium-page/MovingBarComponent;.jsx
@@ -26,25 +26,20 @@ const useStyles = makeStyles((theme) => ({
},
textContainer: {
whiteSpace: 'nowrap',
- animation: '$marquee 20s linear infinite',
color: '#ffffff',
textAlign: 'center',
- width: '200%',
fontFamily: 'Vazir, sans-serif', // Use 'Vazir' font
fontSize: '20px',
textShadow: '2px 2px 4px rgba(0, 0, 0, 0.2)',
- },
- text: {
- display: 'inline-block',
- color: 'black',
- padding: '0 10px',
+ animation: '$marquee 50s linear infinite', // Adjusted duration to slow down
+ width: 'fit-content', // Adjust width for better readability
},
'@keyframes marquee': {
'0%': {
- transform: 'translateX(100%)',
+ transform: 'translateX(-100%)',
},
'100%': {
- transform: 'translateX(-100%)',
+ transform: 'translateX(100%)',
},
},
}));
@@ -57,20 +52,14 @@ const MovingBarComponent = ({ fullText }) => {
// Change background color every 3 seconds for a more dynamic effect
const interval = setInterval(() => {
setBackgroundColor(getRandomColor());
- }, 2000);
+ }, 2000); // Adjusted interval between appearances
return () => clearInterval(interval);
}, []);
function getRandomColor() {
- const colors = [
- // Base color (gray)
- '#42A5F5', // Blue
- '#66BB6A', // Green
- '#8E24AA', // Purple
- ];
-
- const randomIndex = Math.floor(Math.random() * (colors.length - 1));
+ const colors = ['#42A5F5', '#66BB6A', '#8E24AA'];
+ const randomIndex = Math.floor(Math.random() * colors.length);
return colors[randomIndex];
}
@@ -90,7 +79,7 @@ const MovingBarComponent = ({ fullText }) => {
-
+
{initialText}
diff --git a/vakilpors-front/src/components/premium-page/test/Avertising.test.jsx b/vakilpors-front/src/components/premium-page/test/Avertising.test.jsx
index fcfc1ddf5..a2c925e38 100644
--- a/vakilpors-front/src/components/premium-page/test/Avertising.test.jsx
+++ b/vakilpors-front/src/components/premium-page/test/Avertising.test.jsx
@@ -1,15 +1,33 @@
import React from 'react';
-import { render, screen } from '@testing-library/react';
+import { render, screen, act, fireEvent } from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import Advertising from '../Avertising';
-const mockLawyer = {
- // your mock lawyer data here
-};
-
-const mockLawyers = [mockLawyer];
+const mockLawyers = [
+ {
+ id: 1,
+ user: { name: 'John Doe' },
+ title: 'Senior Lawyer',
+ licenseNumber: 'ABC123',
+ aboutMe: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
+ profileImageUrl: 'mock_image_url',
+ rating: 4,
+ },
+ // Add more mock lawyers as needed
+];
describe('Advertising component', () => {
+ it('displays loading state initially', async () => {
+ render(
+
+
+
+ );
+
+ expect(screen.getByRole('progressbar')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: /بیشتر/i })).not.toBeInTheDocument();
+ });
+
it('displays lawyer information when data is loaded', async () => {
render(
@@ -17,8 +35,45 @@ describe('Advertising component', () => {
);
+ await screen.findByText(mockLawyers[0].user.name); // Wait for the data to be loaded
+
+ // Assertions for LawyerCard component
+ expect(screen.getByAltText(mockLawyers[0].user.name)).toBeInTheDocument();
+ expect(screen.getByText(mockLawyers[0].user.name)).toBeInTheDocument();
+ expect(screen.getByText(`عنوان: ${mockLawyers[0].title}`)).toBeInTheDocument();
+ expect(screen.getByText(`شماره پرونده وکالت: ${mockLawyers[0].licenseNumber}`)).toBeInTheDocument();
+ expect(screen.getByText(`توضیحات: ${mockLawyers[0].aboutMe.split(' ').slice(0, 30).join(' ')}...`)).toBeInTheDocument();
+ expect(screen.getByRole('link', { name: /بیشتر/i })).toHaveAttribute('href', `/LawyerPage/${mockLawyers[0].id}`);
+ expect(screen.getByLabelText('Rated')).toHaveValue(mockLawyers[0].rating);
+ });
+
+ it('cycles through lawyers with button clicks', async () => {
+ render(
+
+
+
+ );
+
+ await screen.findByText(mockLawyers[0].user.name); // Wait for the data to be loaded
+
+ // Initial display
+ expect(screen.getByText(mockLawyers[0].user.name)).toBeInTheDocument();
+ expect(screen.getByText(mockLawyers[0].title)).toBeInTheDocument();
+
+ // Click next button
+ fireEvent.click(screen.getByRole('button', { name: /•/ }));
+ await screen.findByText(mockLawyers[1].user.name);
+
+ // Check if the next lawyer is displayed
+ expect(screen.getByText(mockLawyers[1].user.name)).toBeInTheDocument();
+ expect(screen.getByText(mockLawyers[1].title)).toBeInTheDocument();
+
+ // Click previous button
+ fireEvent.click(screen.getByRole('button', { name: /•/ }));
+ await screen.findByText(mockLawyers[0].user.name);
+
+ // Check if it cycles back to the initial lawyer
expect(screen.getByText(mockLawyers[0].user.name)).toBeInTheDocument();
- expect(screen.getByText(`عنوان: ${mockLawyers[0].title ? mockLawyers[0].title : "وکیل"}`)).toBeInTheDocument();
- expect(screen.getByText(`شهر: ${mockLawyers[0].city ? mockLawyers[0].city : "نامشخص"}`)).toBeInTheDocument();
+ expect(screen.getByText(mockLawyers[0].title)).toBeInTheDocument();
});
});
diff --git a/vakilpors-front/src/components/premium-page/test/MovingBarComponent.test.jsx b/vakilpors-front/src/components/premium-page/test/MovingBarComponent.test.jsx
new file mode 100644
index 000000000..c7455a39f
--- /dev/null
+++ b/vakilpors-front/src/components/premium-page/test/MovingBarComponent.test.jsx
@@ -0,0 +1,105 @@
+// Import Enzyme and Jest
+import { shallow, mount } from 'enzyme';
+import React from 'react';
+import '@testing-library/jest-dom/extend-expect';
+
+// Import the component to be tested
+import MovingBarComponent from '../MovingBarComponent;';
+
+// Write a test suite for the component
+describe('MovingBarComponent', () => {
+ // Write a test case for rendering the component
+ test('renders the component with the given text', () => {
+ // Render the component with shallow rendering
+ const wrapper = shallow();
+
+ // Assert that the text is present in the component
+ expect(wrapper.find('.custom-text').text()).toBe('This is a test ');
+ });
+
+ // Write a test case for changing the background color
+ test('changes the background color every 2 seconds', () => {
+ // Render the component with full DOM rendering
+ const wrapper = mount();
+
+ // Get the initial background color
+ const initialColor = wrapper.find('.custom-price').prop('style').backgroundColor;
+
+ // Wait for 2 seconds
+ jest.advanceTimersByTime(2000);
+
+ // Get the updated background color
+ const updatedColor = wrapper.find('.custom-price').prop('style').backgroundColor;
+
+ // Assert that the background color has changed
+ expect(updatedColor).not.toBe(initialColor);
+ });
+
+ // Write a test case for navigating to another page
+ test('navigates to the PremiumLawyers page when clicked', () => {
+ // Render the component with shallow rendering
+ const wrapper = shallow();
+
+ // Mock the window.location.href property
+ Object.defineProperty(window, 'location', {
+ value: {
+ href: '',
+ },
+ writable: true,
+ });
+
+ // Simulate a click on the component
+ wrapper.find('.custom-container').simulate('click');
+
+ // Assert that the window.location.href has changed to the PremiumLawyers page
+ expect(window.location.href).toBe('/PremiumLawyers');
+ });
+});
+
+
+
+
+
+
+
+
+
+
+// import React from 'react';
+// import { shallow } from 'enzyme';
+// import MovingBarComponent from '../MovingBarComponent;';
+
+// describe('MovingBarComponent', () => {
+// it('renders without crashing', () => {
+// shallow();
+// });
+
+// it('changes background color every 2 seconds', () => {
+// jest.useFakeTimers();
+
+// const wrapper = shallow();
+// const instance = wrapper.instance();
+
+// // Initial background color
+// const initialBackgroundColor = wrapper.find('.movingBar').prop('style').backgroundColor;
+
+// // Trigger the useEffect function
+// jest.runOnlyPendingTimers();
+
+// // Check if the background color changes after 2 seconds
+// jest.advanceTimersByTime(2000);
+// const updatedBackgroundColor = wrapper.find('.movingBar').prop('style').backgroundColor;
+
+// expect(updatedBackgroundColor).not.toBe(initialBackgroundColor);
+
+// jest.useRealTimers();
+// });
+
+// it('navigates to the specified page when clicked', () => {
+// const mockLocationHref = jest.spyOn(window.location, 'href', 'set');
+// const wrapper = shallow();
+
+// wrapper.find('.container').simulate('click');
+// expect(mockLocationHref).toHaveBeenCalledWith('/PremiumLawyers');
+// });
+// });
diff --git a/vakilpors-front/src/components/premium-page/test/PremiumLawyers.test.jsx b/vakilpors-front/src/components/premium-page/test/PremiumLawyers.test.jsx
new file mode 100644
index 000000000..17bbb140e
--- /dev/null
+++ b/vakilpors-front/src/components/premium-page/test/PremiumLawyers.test.jsx
@@ -0,0 +1,45 @@
+// Import React Testing Library and Jest
+import { render, screen, fireEvent } from '@testing-library/react';
+import '@testing-library/jest-dom/extend-expect';
+import React from 'react';
+
+// Import the component to be tested
+import PremiumLawyers from '../PremiumLawyers';
+
+// Write a test suite for the component
+describe('PremiumLawyers component', () => {
+ // Write a test case for rendering the component
+ test('renders the component with header and plans', () => {
+ // Render the component
+ render();
+
+ // Assert that the header elements are present
+ expect(screen.getByText('رشد کسب و کار خود را با تبلیغات هدفمند آنلاین افزایش دهید')).toBeInTheDocument();
+ expect(screen.getByText('بین برنامه های روزانه یا هفتگی انتخاب کنید تا با مشتریان جدید ارتباط برقرار کنید.')).toBeInTheDocument();
+
+ // Assert that the plan cards are present
+ expect(screen.getByText('برنامه روزانه')).toBeInTheDocument();
+ expect(screen.getByText('برنامه هفتگی')).toBeInTheDocument();
+
+ // Assert that the plan features are present
+ expect(screen.getByText('قرار دادن لیست ویژه')).toBeInTheDocument();
+ expect(screen.getByText('نمایش تبلیغات در صفحات با ترافیک بالا')).toBeInTheDocument();
+ expect(screen.getByText('گزارش تحلیلی از کلیک ها و تاثیرات')).toBeInTheDocument();
+ expect(screen.getByText('خلاقیت های سفارشی برای تبلیغات موثر')).toBeInTheDocument();
+ });
+
+ // Write a test case for selecting a plan
+ test('selects a plan and shows a confirmation message', () => {
+ // Render the component
+ render();
+
+ // Find the button for the daily plan
+ const dailyPlanButton = screen.getByText('انتخاب', { selector: 'button' });
+
+ // Click the button
+ fireEvent.click(dailyPlanButton);
+
+ // Assert that a confirmation message is shown
+ expect(screen.getByText('شما برنامه روزانه را انتخاب کرده اید. لطفا اطلاعات پرداخت خود را وارد کنید.')).toBeInTheDocument();
+ });
+});
diff --git a/vakilpors-front/src/components/profile/Lawyer_Jobinfo.jsx b/vakilpors-front/src/components/profile/Lawyer_Jobinfo.jsx
index ccc2477b8..28fe42cf7 100644
--- a/vakilpors-front/src/components/profile/Lawyer_Jobinfo.jsx
+++ b/vakilpors-front/src/components/profile/Lawyer_Jobinfo.jsx
@@ -64,8 +64,9 @@ const Lawyer_Jobinfo = () => {
const [specialties, setSpecialties] = useState([]);
const fileInputRef = useRef(null);
const [loading, setloading] = useState(false);
-
const [open, setOpen] = useState(false);
+ const [loadingocr, setloadingocr] = useState(false);
+ const [code, setcode] = useState("");
const handleClickOpen = () => {
setOpen(true);
@@ -171,7 +172,7 @@ const Lawyer_Jobinfo = () => {
reader.onloadend = () => {
const fileString = reader.result;
- console.log(fileString);
+ // console.log(fileString);
setdetail({
...refdetail.current,
["nationalCardImage"]: file,
@@ -285,7 +286,6 @@ const Lawyer_Jobinfo = () => {
src={refdetail.current.nationalCardImageUrl}
variant="square"
/>
-
{
type="submit"
onClick={HandleOcr}
>
- {/* {!loading && ارسال}
- {loading && (
+ {!loadingocr && ارسال}
+ {loadingocr && (
{
>
- )} */}
- ارسال
+ )}
+ کد ملی شما:
+ {code}
@@ -425,56 +426,57 @@ const Lawyer_Jobinfo = () => {
}
}
};
- function convertImageUrlToFile(url, fileName) {
- return fetch(url)
- .then((response) => response.blob())
- .then((blob) => {
- const file = new File([blob], fileName, {
- lastModified: new Date().getTime(),
- lastModifiedDate: new Date(),
- type: blob.type,
- });
- return file;
+ async function convertImageUrlToFile(url, fileName) {
+ try {
+ const response = await fetch(url);
+ const blob = await response.blob();
+ const file = new File([blob], fileName, {
+ lastModified: new Date().getTime(),
+ lastModifiedDate: new Date(),
+ type: blob.type,
});
+ return file;
+ } catch (error) {
+ console.error("خطا:", error);
+ throw error;
+ }
}
const HandleOcr = async (event) => {
+ setcode("")
console.log(refdetail.current.nationalCardImage);
-
+ const img1 = await convertImageUrlToFile(
+ refdetail.current.nationalCardImageUrl,
+ "ocr.jpeg"
+ );
+ console.log(img1);
const url = BASE_API_ROUTE + `Ocr`;
const file = refdetail.current.nationalCardImage;
- console.log(file); // اضافه کردن این خط
-
- if (file && file instanceof Blob) {
- const reader = new FileReader();
-
- reader.onloadend = () => {
- const fileString = reader.result;
- console.log(fileString);
- setdetail({
- ...refdetail.current,
- ["nationalCardImage"]: file,
- });
- };
-
- reader.readAsDataURL(file);
+ const formData1 = new FormData();
+ if (refdetail.current.nationalCardImage === null) {
+ console.log("dfdf");
+ formData1.append("imageFile", img1);
+ } else {
+ console.log("sdfdsf");
+ formData1.append("imageFile", file);
}
-
- const formData = new FormData();
- formData.append("imageFile", refdetail.current.nationalCardImage);
- console.log(formData);
-
+ console.log(formData1);
+ setloadingocr(true);
axios
- .post(url, formData, {
+ .post(url, formData1, {
headers: {
- "Content-Type": "multipart/form-data"
+ "Content-Type": "multipart/form-data",
},
})
.then((response) => {
console.log(response);
+ setcode(response.data.data.nationalCode);
+ console.log(response.data.data.nationalCode);
+ setloadingocr(false);
})
.catch((error) => {
console.log(error);
+ setloadingocr(false);
});
};