Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5474bf6
created link iink in navbar that goes to /account/profile
HoldUpFjord Nov 4, 2024
641610e
got rid of comments
HoldUpFjord Nov 4, 2024
80eee47
Altered copy to be one word
HoldUpFjord Nov 4, 2024
5ecc1b0
created navlink component
HoldUpFjord Nov 13, 2024
634d468
refactored links to be navLinks
HoldUpFjord Nov 13, 2024
24d3425
added test for new /profile route
HoldUpFjord Nov 13, 2024
af5c6b1
Merge branch 'develop' into dominick/639-feat-add-user-account-link-t…
HoldUpFjord Nov 13, 2024
800457d
changes to pass build step/ linter
HoldUpFjord Nov 13, 2024
51151ad
Revert "changes to pass build step/ linter", namelyt altering the pac…
HoldUpFjord Nov 14, 2024
57e258e
fixed build errors in the following files
HoldUpFjord Nov 14, 2024
9347392
alias issue with storybook. Fixed by redefining import path
HoldUpFjord Nov 14, 2024
96bd584
fixed all storybook errors by converting to relative paths
HoldUpFjord Nov 14, 2024
0423909
testing local dev fix by reverting alias changes.
HoldUpFjord Nov 15, 2024
15b023f
fixes jsdoc break in cody nit
HoldUpFjord Nov 15, 2024
1065a79
restores break after imports
HoldUpFjord Nov 15, 2024
bc7b68c
fix: remove comment to resolve Shashi PR conversation.
HoldUpFjord Nov 19, 2024
d855689
Merge branch 'develop' into dominick/639-feat-add-user-account-link-t…
shashilo Nov 19, 2024
3f43c62
Merge branch 'develop' into dominick/639-feat-add-user-account-link-t…
HoldUpFjord Nov 19, 2024
2dbfc34
fix/ addresses pr review to expand JSdocs to cover props
HoldUpFjord Nov 19, 2024
177f43c
Merge branch 'dominick/639-feat-add-user-account-link-to-sidebar' of …
HoldUpFjord Nov 19, 2024
fa1f00b
added new navlink file
HoldUpFjord Nov 19, 2024
61a2961
fix: addresses new to test for props in NavLink componenet
HoldUpFjord Nov 20, 2024
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
9 changes: 9 additions & 0 deletions components/Nav/Nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ describe('Nav', () => {
expect(linkNav).toHaveAttribute('href', '/league/all');
});

it('renders link to user profile', async () => {
render(<Nav />);
fireEvent.click(screen.getByTestId('drawer-trigger'));
let linkNav: HTMLElement;
linkNav = screen.getByTestId('profile-link');
expect(linkNav).toBeInTheDocument();
expect(linkNav).toHaveAttribute('href', '/account/profile');
});

it('it should render the default component state', () => {
mockUsePathname.mockImplementation(() => '/league/all');

Expand Down
51 changes: 28 additions & 23 deletions components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { JSX } from 'react';
import LogoNav from '../LogoNav/LogoNav';
import { Menu } from 'lucide-react';
import { Button } from '../Button/Button';
import Link from 'next/link';
import NavLink from '../NavLink/NavLink';
import {
Drawer,
DrawerContent,
Expand All @@ -29,6 +29,12 @@ export const Nav = (): JSX.Element => {
const { logoutAccount } = useAuthContext();
const [open, setOpen] = React.useState(false);

/**
* Handles closing the drawer.
* @returns {void} No return value.
*/
const handleClose = (): void => setOpen(false);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a variable to call this useState directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting the following error if I didn't declare the useState directly:

Would you prefer this bit implemented differently?
image


/**
* Handles the logout.
* @returns {Promise<void>} The logout promise.
Expand Down Expand Up @@ -69,28 +75,27 @@ export const Nav = (): JSX.Element => {
<DrawerTitle data-testid="title">Gridiron Survivor</DrawerTitle>
</DrawerHeader>
<ul className="m-0 flex flex-col gap-1 p-0">
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could go as far as making this NavLinkContainer component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand what you mean here. Are you thinking NavLinkContainer would be a new component leveraging the <Drawer/> component?

<li>
<Link
href="/account/settings"
className="underline underline-offset-4 hover:text-primary-muted transition-colors"
onClick={() => setOpen(false)}
data-testid="settings-link"
>
Settings
</Link>
</li>
<li>
<Link
data-testid="league-link"
href="/league/all"
className={cn(
'underline underline-offset-4 hover:text-primary-muted transition-colors',
)}
onClick={() => setOpen(false)}
>
Leagues
</Link>
</li>
<NavLink
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

href="/account/settings"
testId="settings-link"
onClose={handleClose}
>
Settings
</NavLink>
<NavLink
href="/league/all"
testId="league-link"
onClose={handleClose}
>
Leagues
</NavLink>
<NavLink
href="/account/profile"
testId="profile-link"
onClose={handleClose}
>
Profile
</NavLink>
<li>
<Button
className="p-0 text-base font-normal hover:text-primary-muted transition-colors text-white"
Expand Down
30 changes: 30 additions & 0 deletions components/NavLink/NavLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render, screen, fireEvent } from '@testing-library/react';
import NavLink from './NavLink';

describe('NavLink componenet', () => {
it('renders link with href and testId', () => {
render(
<NavLink href="test/url" testId="test-link">
Test Link
</NavLink>,
);

const link = screen.getByTestId('test-link');
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', 'test/url');
expect(link).toHaveTextContent('Test Link');
});

it('calls onClose when link is clicked', () => {
const handleClose = jest.fn();
render(
<NavLink href="/test-url" testId="test-link" onClose={handleClose}>
Test Link
</NavLink>,
);

const linkNav = screen.getByTestId('test-link');
fireEvent.click(linkNav);
expect(handleClose).toHaveBeenCalledTimes(1);
});
});
44 changes: 44 additions & 0 deletions components/NavLink/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import React, { JSX } from 'react';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a unit test for this new component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so I should take the relevant tests form the original nav.tsx and move them into a new NavList.test file? That makes sense.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. You should create a brand new NavLink unit test file. It should ensure that all the props that can change will change correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shashilo Latest changes address this i think

import Link from 'next/link';
import { cn } from '@/utils/utils';
interface NavLinkProps {
href: string;
testId: string;
children: React.ReactNode;
onClose?: () => void;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is onClose optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be misunderstanding, but my line of thought was it needed to be optional because onClose it's a function that's toggled on click. The nature of the toggle indicating that the onClose function is always 'provided'/there.

}

/**
* Renders a navigation link.
* @param {string} props.href - The URL the link points to.
* @param {string} props.testId - The test ID for the link.
* @param {React.ReactNode} props.children - The content to be rendered inside the link.
* @param {Function} [props.onClose] - function to be called when the link is clicked.
* @returns {JSX.Element} The rendered navigation link.
*/
const NavLink = ({
href,
testId,
children,
onClose,
}: NavLinkProps): JSX.Element => {
return (
<li>
<Link
href={href}
data-testid={testId}
className={cn(
'underline underline-offset-4 hover:text-primary-muted transition-colors',
)}
onClick={onClose}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was optional, this code should fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's true. If it was optional, would the better way of handling it defining a variable that states its conditional and then testing that? Something like:"

const NavLink = ({
  href,
  testId,
  children,
  onClose,
}: NavLinkProps): JSX.Element => {
  const handleClick = () => {
    if (onClose) {
      onClose();
    }
  };

  return (
    <a href={href} data-testid={testId} onClick={handleClick}>
      {children}
    </a>
  );
};

>
{children}
</Link>
</li>
);
};

export default NavLink;