Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
FatemehAskari committed Nov 30, 2023
2 parents de6147a + 98764d8 commit 16146b8
Show file tree
Hide file tree
Showing 6 changed files with 331 additions and 72 deletions.
73 changes: 68 additions & 5 deletions vakilpors-front/src/App.test.js
Original file line number Diff line number Diff line change
@@ -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(<App />);
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(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

it('renders the App component with lawyer information and advertising', async () => {
render(
<Router>
<App />
</Router>
);

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(
<Router>
<App />
</Router>
);

userEvent.click(getByText('جست و جوی وکلا'));

await waitFor(() => expect(window.location.pathname).toBe('/Lawyer-search-page'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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%)',
},
},
}));
Expand All @@ -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];
}

Expand All @@ -90,7 +79,7 @@ const MovingBarComponent = ({ fullText }) => {
<Card>
<CardContent style={{ backgroundColor }}>
<div className={classes.textContainer}>
<Typography variant="h5" className={classes.text}>
<Typography variant="h5">
{initialText}
</Typography>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,79 @@
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(
<Router>
<Advertising lawyers={[]} />
</Router>
);

expect(screen.getByRole('progressbar')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: /بیشتر/i })).not.toBeInTheDocument();
});

it('displays lawyer information when data is loaded', async () => {
render(
<Router>
<Advertising lawyers={mockLawyers} />
</Router>
);

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(
<Router>
<Advertising lawyers={mockLawyers} />
</Router>
);

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();
});
});
Original file line number Diff line number Diff line change
@@ -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(<MovingBarComponent fullText="This is a test" />);

// 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(<MovingBarComponent fullText="This is a test" />);

// 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(<MovingBarComponent fullText="This is a test" />);

// 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(<MovingBarComponent fullText="Test Text" />);
// });

// it('changes background color every 2 seconds', () => {
// jest.useFakeTimers();

// const wrapper = shallow(<MovingBarComponent fullText="Test Text" />);
// 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(<MovingBarComponent fullText="Test Text" />);

// wrapper.find('.container').simulate('click');
// expect(mockLocationHref).toHaveBeenCalledWith('/PremiumLawyers');
// });
// });
Original file line number Diff line number Diff line change
@@ -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(<PremiumLawyers />);

// 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(<PremiumLawyers />);

// 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();
});
});
Loading

0 comments on commit 16146b8

Please # to comment.