Skip to content

Commit

Permalink
Merge branch 'develop' into clue355/alert-on-signout
Browse files Browse the repository at this point in the history
  • Loading branch information
Clue355 authored Jul 15, 2024
2 parents f4aa1cc + 6f9356a commit 2995a0b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const RootLayout = ({
}): JSX.Element => {
return (
<html lang="en" className={GeistSans.className}>
<body className="dark:dark bg-background px-4 pb-8 text-foreground">
<body className="dark:dark bg-background pb-8 px-4 text-foreground xl:pb-0">
<ErrorBoundary>
<AuthContextProvider>
<Nav />
Expand Down
11 changes: 7 additions & 4 deletions app/login/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ const mockLogin = jest.fn();
const mockPush = jest.fn();
const getUser = jest.fn();

let emailInput: HTMLInputElement,
passwordInput: HTMLInputElement,
continueButton: HTMLElement;
let continueButton: HTMLElement,
emailInput: HTMLInputElement,
passwordInput: HTMLInputElement;

const mockUseAuthContext = {
login: mockLogin,
getUser,
isSignedIn: false,
login: mockLogin,
getUser,
isSignedIn: false,
login: mockLogin,
};

jest.mock('next/navigation', () => ({
Expand Down
2 changes: 1 addition & 1 deletion app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Login = (): JSX.Element => {
};

return (
<section className="grid grid-rows-3 xl:grid-cols-2 xl:grid-rows-none">
<section className="grid xl:grid-cols-2 xl:grid-rows-none">
<div className="row-span-1 grid w-full place-items-center from-[#4E160E] to-zinc-950 dark:bg-gradient-to-b xl:h-screen xl:bg-gradient-to-b">
<Logo className="mx-auto w-52 xl:w-64 xl:place-self-end" src={logo} />
<div className="mx-auto grid gap-4 place-self-end px-8 pb-8 text-foreground text-white">
Expand Down
27 changes: 13 additions & 14 deletions app/register/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jest.mock('react-hot-toast', () => ({
},
}));

let emailInput: HTMLElement;
let passwordInput: HTMLElement;
let confirmPasswordInput: HTMLElement;
let continueButton: HTMLElement;
let emailInput: HTMLElement;
let passwordInput: HTMLElement;

const mockUseAuthContext = {
login: mockLogin,
isSignedIn: false,
login: mockLogin,
};

// Mock the useRouter and useAuthContext hooks
Expand Down Expand Up @@ -113,9 +113,9 @@ describe('Register', () => {
});

test('should show success notification upon successful submission', async () => {
fireEvent.change(emailInput, { target: { value: '[email protected]' }});
fireEvent.change(passwordInput, { target: { value: 'pw1234' }});
fireEvent.change(confirmPasswordInput, { target: { value: 'pw1234' }});
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(passwordInput, { target: { value: 'pw1234' } });
fireEvent.change(confirmPasswordInput, { target: { value: 'pw1234' } });
fireEvent.click(continueButton);

await waitFor(() => {
Expand All @@ -140,11 +140,13 @@ describe('Register', () => {
});

test('should show error notification upon submission failing', async () => {
mockLogin.mockImplementationOnce(() => Promise.reject(new Error('Mock error')));
mockLogin.mockImplementationOnce(() =>
Promise.reject(new Error('Mock error')),
);

fireEvent.change(emailInput, { target: { value: '[email protected]' }});
fireEvent.change(passwordInput, { target: { value: 'pw1234' }});
fireEvent.change(confirmPasswordInput, { target: { value: 'pw1234' }});
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(passwordInput, { target: { value: 'pw1234' } });
fireEvent.change(confirmPasswordInput, { target: { value: 'pw1234' } });
fireEvent.click(continueButton);

await waitFor(() => {
Expand All @@ -159,10 +161,7 @@ describe('Register', () => {
confirmPassword: 'pw1234',
});
expect(toast.custom).toHaveBeenCalledWith(
<Alert
variant={AlertVariants.Error}
message="Something went wrong!"
/>,
<Alert variant={AlertVariants.Error} message="Something went wrong!" />,
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions context/AuthContextProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('AuthContextProvider', () => {

const setIsSignedIn = jest.fn();
const resetUser = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
});
Expand All @@ -58,7 +58,7 @@ describe('AuthContextProvider', () => {
);
});

test('should show error notification after a login attempt errors', async () => {
test('should show error notification after a login attempt fails', async () => {
const mockError = new Error('Test error');

mockCreateEmailPasswordSession.mockRejectedValue(mockError);
Expand Down
6 changes: 3 additions & 3 deletions context/AuthContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type UserCredentials = {
};

type AuthContextType = {
isSignedIn: boolean;
getUser: () => Promise<IUser | undefined>;
setIsSignedIn: React.Dispatch<React.SetStateAction<boolean>>;
login: (user: UserCredentials) => Promise<void | Error>; // eslint-disable-line no-unused-vars
logoutAccount: () => Promise<void | Error>;
Expand Down Expand Up @@ -117,11 +117,11 @@ export const AuthContextProvider = ({
// Memoize context values to avoid unnecessary re-renders
const contextValue = useMemo(
() => ({
isSignedIn,
getUser,
setIsSignedIn,
login,
logoutAccount,
getUser,
setIsSignedIn,
}),
[isSignedIn],
);
Expand Down
2 changes: 1 addition & 1 deletion context/AuthHelper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import React, { createContext } from 'react';
import React from 'react';
import { account } from '@/api/config';
import Alert from '@/components/AlertNotification/AlertNotification';
import { AlertVariants } from '@/components/AlertNotification/Alerts.enum';
Expand Down

0 comments on commit 2995a0b

Please sign in to comment.