From 6bf63fab7f3d2ef0f6b89ce7d3cf1728731ab701 Mon Sep 17 00:00:00 2001 From: Ryan Furrer Date: Thu, 3 Oct 2024 20:30:20 -0400 Subject: [PATCH] cherry pick previous commits after bad attempt at fixing merge conflicts --- app/(admin)/admin/notifications/page.test.tsx | 37 +++--- app/(admin)/admin/notifications/page.tsx | 113 +----------------- components/Input/Input.tsx | 3 +- components/LabelText/LabelText.tsx | 2 +- 4 files changed, 22 insertions(+), 133 deletions(-) diff --git a/app/(admin)/admin/notifications/page.test.tsx b/app/(admin)/admin/notifications/page.test.tsx index 2af213ef..52737df0 100644 --- a/app/(admin)/admin/notifications/page.test.tsx +++ b/app/(admin)/admin/notifications/page.test.tsx @@ -1,13 +1,14 @@ +// /Users/ryanfurrer/Developer/GitHub/gridiron-survivor/app/(admin)/admin/notifications/page.test.tsx + +import AdminNotifications from './page'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { getCurrentLeague } from '@/api/apiFunctions'; -import { sendEmailNotifications } from './actions/sendEmailNotification'; -import AdminNotifications from './page'; import React from 'react'; +import { sendEmailNotifications } from './actions/sendEmailNotification'; let contentInput: HTMLInputElement, - selectAllUsersRadioOption: HTMLElement, - selectRecipientsRadioGroup: HTMLElement, - sendEmailButton: HTMLElement, + emailButton: HTMLElement, + emailTestersButton: HTMLElement, subjectInput: HTMLInputElement; jest.mock('@/api/apiFunctions', () => ({ @@ -19,23 +20,16 @@ jest.mock('./actions/sendEmailNotification', () => ({ })); describe('Admin notifications page', () => { - beforeEach(async () => { + beforeEach(() => { jest.clearAllMocks(); - (getCurrentLeague as jest.Mock).mockResolvedValue({ - participants: ['12345', '1234', '123'], - leagueName: 'Test League', - }); - render(); contentInput = screen.getByTestId('content-text'); - selectAllUsersRadioOption = screen.getByTestId('all-users-option'); - selectRecipientsRadioGroup = screen.getByTestId('radio-group-default'); - sendEmailButton = screen.getByTestId('send-email'); + emailButton = screen.getByTestId('send-email'); + emailTestersButton = screen.getByTestId('email-testers'); subjectInput = screen.getByTestId('subject-text'); }); - it(`should render it's content`, () => { (sendEmailNotifications as jest.Mock).mockResolvedValue({}); @@ -44,24 +38,27 @@ describe('Admin notifications page', () => { ); expect(adminNotificationsContent).toBeInTheDocument(); }); - it('should call the sendEmailNotifications function with the provided inputs', async () => { - fireEvent.click(selectAllUsersRadioOption); + const dummyParticipants = ['12345', '1234', '123']; + (getCurrentLeague as jest.Mock).mockResolvedValue({ + participants: dummyParticipants, + }); + + fireEvent.click(emailTestersButton); fireEvent.change(subjectInput, { target: { value: 'Test Title' } }); fireEvent.change(contentInput, { target: { value: 'Test message section.' }, }); await waitFor(() => { - expect(sendEmailButton).toBeInTheDocument(); + expect(emailButton).toBeInTheDocument(); }); - fireEvent.submit(sendEmailButton); + fireEvent.submit(emailButton); await waitFor(() => { expect(sendEmailNotifications as jest.Mock).toHaveBeenCalledWith({ content: 'Test message section.', - groupUsers: ['12345', '1234', '123'], sendEmailUsers: dummyParticipants, subject: 'Test Title', testBCC: expect.any(Array), diff --git a/app/(admin)/admin/notifications/page.tsx b/app/(admin)/admin/notifications/page.tsx index 40b80520..b465cc77 100644 --- a/app/(admin)/admin/notifications/page.tsx +++ b/app/(admin)/admin/notifications/page.tsx @@ -6,14 +6,9 @@ import { Button } from '@/components/Button/Button'; import { getCurrentLeague } from '@/api/apiFunctions'; import { Input } from '@/components/Input/Input'; import { JSX, useState } from 'react'; -import { LabelText } from '@/components/LabelText/LabelText'; -import { - RadioGroupDefault, - RadioGroupDefaultItem, -} from '@/components/RadioGroupDefault/RadioGroupDefault'; +import { Label } from '@/components/Label/Label'; import { sendEmailNotifications } from './actions/sendEmailNotification'; -import { Textarea } from '@/components/Textarea/Textarea'; -import React, { useEffect } from 'react'; +import React from 'react'; /** * The admin home page. @@ -21,23 +16,16 @@ import React, { useEffect } from 'react'; */ const AdminNotifications = (): JSX.Element => { const [content, setContent] = useState(''); - const [groupUsers, setGroupUsers] = useState([]); - const [leagueName, setLeagueName] = useState(''); const [sendEmailUsers, setSendEmailUsers] = useState([]); const [subject, setSubject] = useState(''); - const [emailRecipients, setEmailRecipients] = useState(''); /** - * To grab all users from the league. - * @returns The league data. * To grab all participant's userIDs from the league to be passed into the backend email function. */ const participantsEmail = async (): Promise => { try { const leagueId = '66f1a8e300102bff03ff'; const leagueData = await getCurrentLeague(leagueId); - setGroupUsers(leagueData.participants); - setLeagueName(leagueData.leagueName); setSendEmailUsers(leagueData.participants); } catch (error) { throw new Error('Error Sending Email'); @@ -53,103 +41,7 @@ const AdminNotifications = (): JSX.Element => { await sendEmailNotifications({ content, sendEmailUsers, subject }); }; - /** - * Function to handle radio selection logic. - * @param value - Value of the radio buttons. - */ - const handleRadioChange = (value: string): void => { - setEmailRecipients(value); - }; - - useEffect(() => { - /** - * Fetches the league data. - * @returns The league data. - */ - const fetchData = async (): Promise => { - await getLeagueData(); - }; - fetchData(); - }, []); - return ( -
-

- Choose the users you would like to email in{' '} - {leagueName}. -

- -
- - All users -
-
- - Only the survivors -
-
- - Only the losers -
-
-
-
- - Subject: - - setSubject(e.target.value)} - type="text" - /> -
-
- - Message: - -