-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
331 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 63 additions & 8 deletions
71
vakilpors-front/src/components/premium-page/test/Avertising.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
105 changes: 105 additions & 0 deletions
105
vakilpors-front/src/components/premium-page/test/MovingBarComponent.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
// }); | ||
// }); |
45 changes: 45 additions & 0 deletions
45
vakilpors-front/src/components/premium-page/test/PremiumLawyers.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.