Skip to content

Commit

Permalink
Merge branch 'develop' into michaellarocca/docs-audit-storybook-compo…
Browse files Browse the repository at this point in the history
…nents-new
  • Loading branch information
shashilo authored Nov 19, 2024
2 parents bb94ecb + f92114f commit 43e89a4
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 368 deletions.
2 changes: 0 additions & 2 deletions app/(main)/account/recovery/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const ResetPassword = (): React.JSX.Element => {
const password: string = useWatch({
control: form.control,
name: 'password',
defaultValue: '',
});

/**
Expand All @@ -116,7 +115,6 @@ const ResetPassword = (): React.JSX.Element => {
const confirmPassword: string = useWatch({
control: form.control,
name: 'confirmPassword',
defaultValue: '',
});

/**
Expand Down
144 changes: 0 additions & 144 deletions app/(main)/league/[leagueId]/entry/all/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,148 +344,4 @@ describe('League entries page (Entry Component)', () => {
);
});
});
it('should not display the user pick history if the current week is 1', async () => {
mockUseDataStore.mockReturnValue({
...mockUseDataStore(),
currentWeek: 1,
NFLTeams: [
{
teamId: 'packers',
teamLogo: '/packers-logo.png',
teamName: 'Packers',
},
],
});
mockGetCurrentUserEntries.mockResolvedValueOnce([
{
$id: '123',
name: 'Test Entry',
week: 1,
selectedTeams: ['Packers', 'Bears'],
},
]);
mockGetGameWeek.mockResolvedValueOnce({ week: 1 });
mockGetCurrentLeague.mockResolvedValue({
leagueName: 'Test League',
participants: 10,
survivors: 8,
});
mockGetNFLTeams.mockResolvedValue([
{ teamId: 'packers', teamLogo: '/packers-logo.png', teamName: 'Packers' },
{ teamId: 'bears', teamLogo: '/bears-logo.png', teamName: 'Bears' },
]);

render(<Entry params={{ leagueId: '123' }} />);

await waitFor(() => {
expect(mockGetGameWeek).toHaveBeenCalled();
expect(mockGetCurrentUserEntries).toHaveBeenCalled();
expect(mockGetCurrentLeague).toHaveBeenCalled();
expect(mockGetNFLTeams).toHaveBeenCalled();
});

expect(screen.queryByTestId('user-pick-history')).not.toBeInTheDocument();
});

it('should display the user pick history if the current week is greater than 1', async () => {
mockUseDataStore.mockReturnValue({
...mockUseDataStore(),
currentWeek: 2,
NFLTeams: [
{
teamId: 'packers',
teamLogo: '/packers-logo.png',
teamName: 'Packers',
},
{
teamId: 'bears',
teamLogo: '/bears-logo.png',
teamName: 'Bears',
},
],
});
mockGetCurrentUserEntries.mockResolvedValueOnce([
{
$id: '123',
name: 'Test Entry',
week: 2,
selectedTeams: ['Packers', 'Bears'],
},
]);
mockGetGameWeek.mockResolvedValueOnce({ week: 2 });
mockGetCurrentLeague.mockResolvedValue({
leagueName: 'Test League',
participants: ['123', '456'],
survivors: ['123', '456'],
});
mockGetNFLTeams.mockResolvedValue([
{ teamId: 'packers', teamLogo: '/packers-logo.png', teamName: 'Packers' },
{ teamId: 'bears', teamLogo: '/bears-logo.png', teamName: 'Bears' },
]);

render(<Entry params={{ leagueId: '123' }} />);

await waitFor(() => {
expect(mockGetGameWeek).toHaveBeenCalled();
expect(mockGetCurrentUserEntries).toHaveBeenCalled();
expect(mockGetCurrentLeague).toHaveBeenCalled();
expect(mockGetNFLTeams).toHaveBeenCalled();
});
// Add a delay to allow for any asynchronous rendering
await new Promise((resolve) => setTimeout(resolve, 0));

expect(screen.queryByTestId('user-pick-history')).toBeInTheDocument();
expect(screen.getByTestId('league-history-logo')).toHaveAttribute(
'src',
'/_next/image?url=%2Fpackers-logo.png&w=96&q=75',
);
expect(screen.getByTestId('league-entry-logo')).toHaveAttribute(
'src',
'/_next/image?url=%2Fbears-logo.png&w=96&q=75',
);
});

it('should not display the user pick history if the entries selected teams are empty', async () => {
mockUseDataStore.mockReturnValue({
...mockUseDataStore(),
currentWeek: 2,
NFLTeams: [
{
teamId: 'packers',
teamLogo: '/packers-logo.png',
teamName: 'Packers',
},
{ teamId: '2', teamLogo: '/bears-logo.png', teamName: 'Bears' },
],
});
mockGetCurrentUserEntries.mockResolvedValueOnce([
{
$id: '123',
name: 'Test Entry',
week: 2,
selectedTeams: [],
},
]);
mockGetGameWeek.mockResolvedValueOnce({ week: 2 });
mockGetCurrentLeague.mockResolvedValue({
leagueName: 'Test League',
participants: ['123', '456'],
survivors: ['123', '456'],
});
mockGetNFLTeams.mockResolvedValue([
{ teamId: 'packers', teamLogo: '/packers-logo.png', teamName: 'Packers' },
{ teamId: 'bears', teamLogo: '/bears-logo.png', teamName: 'Bears' },
]);

render(<Entry params={{ leagueId: '123' }} />);

await waitFor(() => {
expect(mockGetGameWeek).toHaveBeenCalled();
expect(mockGetCurrentUserEntries).toHaveBeenCalled();
expect(mockGetCurrentLeague).toHaveBeenCalled();
expect(mockGetNFLTeams).toHaveBeenCalled();
});

expect(screen.queryByTestId('user-pick-history')).not.toBeInTheDocument();
});
});
9 changes: 0 additions & 9 deletions app/(main)/league/[leagueId]/entry/all/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ const Entry = ({

const selectedTeamLogo = getNFLTeamLogo(NFLTeams, selectedTeam);

let userPickHistory: string[] = [];

if (currentWeek > 1 && entry.selectedTeams.length > 0) {
userPickHistory = entry.selectedTeams
.slice(0, currentWeek - 1)
.map((teamName) => getNFLTeamLogo(NFLTeams, teamName));
}

return (
<section key={entry.$id}>
<LeagueEntries
Expand All @@ -188,7 +180,6 @@ const Entry = ({
isEliminated={entry.eliminated}
isPickSet={isPickSet}
linkUrl={linkUrl}
userPickHistory={userPickHistory}
selectedTeamLogo={selectedTeamLogo}
/>
</section>
Expand Down
51 changes: 38 additions & 13 deletions app/(main)/login/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ let continueButton: HTMLElement,
emailInput: HTMLInputElement,
passwordInput: HTMLInputElement;

const mockUseAuthContext = {
interface MockUseAuthContext {
getUser: jest.Mock;
isSignedIn: boolean | null;
login: jest.Mock;
}

const mockUseAuthContext: MockUseAuthContext = {
getUser,
isSignedIn: false,
login: mockLogin,
Expand Down Expand Up @@ -46,20 +52,45 @@ describe('Login', () => {
jest
.spyOn(React, 'useState')
.mockImplementation(() => [false, setIsLoading]);
});

it('should display GlobalSpinner while authenticating the user', async () => {
mockUseAuthContext.isSignedIn = null;

render(<Login />);

expect(screen.getByTestId('global-spinner')).toBeInTheDocument();
});

it('should not display GlobalSpinner once authentication is complete', async () => {
mockUseAuthContext.isSignedIn = false;

render(<Login />);

expect(screen.queryByTestId('global-spinner')).not.toBeInTheDocument();
});

it('should render the login page if the user is not logged in', () => {
mockUseAuthContext.isSignedIn = false;

render(<Login />);

continueButton = screen.getByTestId('continue-button');
emailInput = screen.getByTestId('email');
passwordInput = screen.getByTestId('password');
});
it('should render the login page', () => {

expect(continueButton).toBeInTheDocument();
expect(emailInput).toBeInTheDocument();
expect(passwordInput).toBeInTheDocument();
});

it('should update email and password fields and submit form', async () => {
mockUseAuthContext.isSignedIn = false;

render(<Login />);

const emailInput = screen.getByTestId('email');
const passwordInput = screen.getByTestId('password');
const form = screen.getByTestId('login-form');

await act(async () => {
Expand All @@ -80,16 +111,7 @@ describe('Login', () => {
});
});

it('redirects to /weeklyPicks when the button is clicked', () => {
mockUseAuthContext.isSignedIn = true;

render(<Login />);
expect(mockUseAuthContext.getUser).toHaveBeenCalled();

mockUseAuthContext.isSignedIn = false;
});

it('redirects to /league/all when user navigates to /login', async () => {
it('redirects to /league/all when user navigates to /login and is logged in', async () => {
mockUseAuthContext.isSignedIn = true;

act(() => {
Expand All @@ -106,6 +128,8 @@ describe('Login', () => {

describe('Login loading spinner', () => {
it('should show the loading spinner', async () => {
mockUseAuthContext.isSignedIn = false;

(useStateMock as jest.Mock).mockImplementation((init: boolean) => [
true,
setIsLoading,
Expand All @@ -117,6 +141,7 @@ describe('Login loading spinner', () => {
expect(screen.queryByTestId('loading-spinner')).toBeInTheDocument();
});
});

it('should not show the loading spinner', async () => {
(useStateMock as jest.Mock).mockImplementation((init: boolean) => [
false,
Expand Down
Loading

0 comments on commit 43e89a4

Please sign in to comment.