Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { PolicyDashboard } from './PolicyDashboard';
import { useMsal } from '@azure/msal-react';
import PaymentService from '../../Services/AnHPortalService';
import { mocked } from 'ts-jest/utils';
// Mocking necessary modules
jest.mock('@azure/msal-react');
jest.mock('../../Services/AnHPortalService');
const mockAccounts = [{ idTokenClaims: { given_name: 'John' } }];
useMsal.mockReturnValue({ accounts: mockAccounts });
describe('PolicyDashboard', () => {
beforeEach(() => {
jest.clearAllMocks();
PaymentService.getAccessToken.mockResolvedValue({ data: { data: { accessToken: 'mocked_token' } } });
PaymentService.getPolicyDashboardData.mockResolvedValue({ data: 'mocked_jwt_token' });
});
test('renders without crashing', () => {
render(<PolicyDashboard />);
expect(screen.getByText(/Hello, John/i)).toBeInTheDocument();
});
test('displays the correct logged-in user', () => {
render(<PolicyDashboard />);
expect(screen.getByText(/Hello, John/i)).toBeInTheDocument();
});
test('opens add policy modal on button click', () => {
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Add a Policy'));
expect(screen.getByText(/Add Policy/i)).toBeInTheDocument();
});
test('closes add policy modal', () => {
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Add a Policy'));
fireEvent.click(screen.getByText(/close/i)); // Assuming there's a close button
expect(screen.queryByText(/Add Policy/i)).not.toBeInTheDocument();
});
test('opens add policy success modal', async () => {
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Add a Policy'));
// Simulate successful add policy action
await waitFor(() => {
expect(screen.getByText(/Add Another Policy/i)).toBeInTheDocument();
});
});
test('opens remove policy modal on clicking three dots', () => {
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Add a Policy'));
// Assuming there's a way to expand a policy card, we click it
fireEvent.click(screen.getByLabelText('Expand Three Dots')); // Adjust according to your markup
expect(screen.getByText(/Remove Policy/i)).toBeInTheDocument();
});
test('shows empty view when there are no policies', () => {
render(<PolicyDashboard />);
// Override dummy data to simulate no policies
expect(screen.getByText(/No Policies Available/i)).toBeInTheDocument(); // Adjust based on your empty state text
});
test('renders policy cards when data is present', () => {
render(<PolicyDashboard />);
expect(screen.getByText(/Performance Services/i)).toBeInTheDocument();
expect(screen.getByText(/Company name 2/i)).toBeInTheDocument();
});
test('proceeds with payment', async () => {
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Make Payment'));
await waitFor(() => {
expect(PaymentService.getPolicyDashboardData).toHaveBeenCalled();
});
});
test('handles API errors gracefully', async () => {
PaymentService.getAccessToken.mockRejectedValueOnce(new Error('Failed to fetch'));
render(<PolicyDashboard />);
fireEvent.click(screen.getByLabelText('Make Payment'));
await waitFor(() => {
expect(screen.getByText(/Error/i)).toBeInTheDocument(); // Adjust based on your error handling
});
});
});
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team