diff --git a/app/src/tests/SettingsPage.test.js b/app/src/tests/SettingsPage.test.js index e87d5d3..129257d 100755 --- a/app/src/tests/SettingsPage.test.js +++ b/app/src/tests/SettingsPage.test.js @@ -2,11 +2,13 @@ // Converstaion Link: https://chat.openai.com/share/c8cda0b5-99fb-444d-998a-f630a96a52af import React from 'react'; -import { render, fireEvent } from '@testing-library/react'; +import { render, fireEvent, waitFor } from '@testing-library/react'; +import axios from 'axios'; import SettingsPage from '../pages/settings/SettingsPage'; import '@testing-library/jest-dom/extend-expect'; import styles from '../pages/settings/SettingsPage.module.css'; +jest.mock('axios'); jest.mock('../contexts/FontSizeContext', () => ({ useFontSize: () => ({ fontSize: 16, @@ -77,4 +79,42 @@ describe('SettingsPage Component', () => { }); -}); \ No newline at end of file +// Start of ChatGPT code (Antonio Tessier) +// Conversation link -> https://chat.openai.com/share/4bea6d17-2817-454e-94ad-04bd2e9f0c8d + + it('runs delete account temporary function when delete account button is clicked', async () => { + const { getByText } = render(); + const deleteAccountButton = getByText('Delete Account'); + + fireEvent.click(deleteAccountButton); + + // Ensure that handleDeleteAccountClick is called + await waitFor(() => { + expect(axios.post).toHaveBeenCalled(); + }); + }); + + it('handles unauthorized error correctly', async () => { + // Mock axios post function to return an error + axios.post.mockRejectedValue({ response: { status: 401 } }); + + const { getByText } = render(); + const deleteAccountButton = getByText('Delete Account'); + + const url = "http://localhost:3000.com"; // <- Fernando's code + + Object.defineProperty(window, 'location', { // <- Fernando's code + value: { + href: url + } + }); + + fireEvent.click(deleteAccountButton); + + // Ensure user is redirected to login page on unauthorized error + await waitFor(() => { + expect(window.location.href).toBe('/'); + }); + }); +// End of ChatGPT code. +});