Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two tests to SettingsPage.test.js #134

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions app/src/tests/SettingsPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -77,4 +79,42 @@ describe('SettingsPage Component', () => {
});


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