Skip to content

Commit

Permalink
Merge branch 'develop' into dominick/alert-title-test
Browse files Browse the repository at this point in the history
  • Loading branch information
HoldUpFjord committed Oct 30, 2024
2 parents 0a40566 + 0ac4e38 commit 0ea23ea
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 269 deletions.
10 changes: 10 additions & 0 deletions api/apiFunctions.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export interface IAccountData {
}
export interface IUser {
documentId: string;
// for the appwrite auth collection
id: string;
email: string;
leagues: string[];
labels: string[];
}

export interface ICollectionUser {
documentId: string;
// for the custom user collection
id: string;
email: string;
leagues: string[];
Expand Down
5 changes: 4 additions & 1 deletion api/apiFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ILeague,
IGameWeek,
IUser,
ICollectionUser,
IWeeklyPicks,
INFLTeam,
IRecoveryToken,
Expand Down Expand Up @@ -149,7 +150,9 @@ export async function updateUserEmail({
* @param userId - The user ID
* @returns {Models.DocumentList<Models.Document> | Error} - The user object or an error
*/
export async function getCurrentUser(userId: IUser['id']): Promise<IUser> {
export async function getCurrentUser(
userId: IUser['id'],
): Promise<ICollectionUser> {
try {
const user = await databases.listDocuments(
appwriteConfig.databaseId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ describe('League Week Picks', () => {
// Wait for the main content to be displayed
await waitFor(() => {
expect(screen.getByTestId('weekly-picks')).toBeInTheDocument();
expect(screen.getByTestId('week__week-number')).toHaveTextContent('Week 1');
expect(screen.getByTestId('week__entry-name')).toHaveTextContent('Entry 1');
});

expect(screen.queryByTestId('global-spinner')).not.toBeInTheDocument();
Expand Down
21 changes: 16 additions & 5 deletions app/(main)/league/[leagueId]/entry/[entryId]/week/Week.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Image from 'next/image';
import { useRouter } from 'next/navigation';
import LinkCustom from '@/components/LinkCustom/LinkCustom';
import { ChevronLeft } from 'lucide-react';
import Heading from '@/components/Heading/Heading';

/**
* Renders the weekly picks page.
Expand All @@ -43,6 +44,7 @@ import { ChevronLeft } from 'lucide-react';
// eslint-disable-next-line no-unused-vars
const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
const [pickHistory, setPickHistory] = useState<string[]>([]);
const [entryName, setEntryName] = useState<string>('');
const [error, setError] = useState<string | null>(null);
const [schedule, setSchedule] = useState<ISchedule[]>([]);
const [selectedLeague, setSelectedLeague] = useState<ILeague | undefined>();
Expand Down Expand Up @@ -156,7 +158,8 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
if (!currentEntry) {
throw new Error('Entry not found');
}


setEntryName(currentEntry.name);
let entryHistory = currentEntry?.selectedTeams || [];

if (currentEntry?.selectedTeams.length > 0) {
Expand Down Expand Up @@ -271,10 +274,18 @@ const Week = ({ entry, league, NFLTeams, week }: IWeekProps): JSX.Element => {
className="flex flex-col items-center w-full pt-8"
data-testid="weekly-picks"
>
<h1 className="pb-8 text-center text-[2rem] font-bold text-foreground">
Week {week} pick
</h1>

<Heading
as='h1'
className='pb-8'
data-testid='week__week-number'
>{`Week ${week} pick`}
</Heading>
<Heading
as='h2'
className='pb-8 text-muted-foreground'
data-testid='week__entry-name'
>{entryName}
</Heading>
{pickHistory.length > 0 && (
<section
className="flex flex-wrap w-[90%] gap-4 overflow-x-scroll justify-center pb-10 items-center"
Expand Down
7 changes: 7 additions & 0 deletions app/(main)/league/all/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jest.mock('@/store/dataStore', () => ({
id: '1234',
email: '[email protected]',
leagues: ['league1'],
labels: [],
},
allLeagues: [
{
Expand Down Expand Up @@ -82,6 +83,7 @@ describe('Leagues Component', () => {
leagues: [],
},
allLeagues: [],
labels: [],
});

render(<Leagues />);
Expand All @@ -105,6 +107,7 @@ describe('Leagues Component', () => {
leagues: [],
},
allLeagues: [],
labels: [],
});

render(<Leagues />);
Expand All @@ -121,6 +124,7 @@ describe('Leagues Component', () => {
email: '[email protected]',
id: '123',
leagues: [],
labels: [],
},
allLeagues: [
{
Expand Down Expand Up @@ -150,6 +154,7 @@ describe('Leagues Component', () => {
email: '[email protected]',
id: '123',
leagues: [],
labels: [],
};

const league = {
Expand Down Expand Up @@ -202,6 +207,7 @@ describe('Leagues Component', () => {
user.id,
user.email,
[...user.leagues, league.leagueId],
user.labels,
);
expect(toast.custom).toHaveBeenCalledWith(
<Alert
Expand All @@ -220,6 +226,7 @@ describe('Leagues Component', () => {
email: '[email protected]',
id: '123',
leagues: [],
labels: [],
};

const league = {
Expand Down
11 changes: 7 additions & 4 deletions app/(main)/league/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ const Leagues = (): JSX.Element => {
});

setLeagues([...leagues, league]);
updateUser(user.documentId, user.id, user.email, [
...user.leagues,
league.leagueId,
]);
updateUser(
user.documentId,
user.id,
user.email,
[...user.leagues, league.leagueId],
user.labels,
);
toast.custom(
<Alert
variant={AlertVariants.Success}
Expand Down
Loading

0 comments on commit 0ea23ea

Please sign in to comment.