Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav Menu Presentation #1086

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ const expectedNoAssociationsSummaryUrl =

// Test with isNonAssociatedUser true
test.use({ isNonAssociatedUser: true });
test('Complete User Profile -- Validate Nav Menu', async ({ page }) => {
await test.step('Verify nav options', async () => {
const navContainer = page.locator('nav#nav-links');
await expect(navContainer).toBeVisible();
await expect(
navContainer.getByRole('button', { name: 'LOG OUT' }),
).toBeVisible();
await expect(
navContainer.getByRole('link', { name: 'Filing', exact: true }),
).not.toBeVisible();
});
});

test('Complete User Profile -- No Associations -- process', async ({
page,
}) => {
Expand Down
11 changes: 11 additions & 0 deletions e2e/pages/shared-lending-platform/UserProfile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ test('User Profile Page', async ({ page, navigateToFilingHome }) => {
await expect(page.locator('h1')).toContainText('View your user profile');
});

await test.step('Verify nav options', async () => {
const navContainer = page.locator('nav#nav-links');
await expect(navContainer).toBeVisible();
await expect(
navContainer.getByRole('button', { name: 'LOG OUT' }),
).toBeVisible();
await expect(
navContainer.getByRole('link', { name: 'Filing', exact: true }),
).toBeVisible();
});

// Verify Name + Email
await test.step('Name & Email', async () => {
await expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from '@playwright/test';

test('Unauthenticated homepage: Validate Nav Menu', async ({ page }) => {
await test.step('Verify nav options', async () => {
const navContainer = page.locator('nav#nav-links');
await expect(navContainer).not.toBeVisible();
});
});
67 changes: 40 additions & 27 deletions src/utils/useHeaderAuthLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,59 @@ import { Button } from 'design-system-react';
import type { ReactElement } from 'react';
import { NavLink, useLocation } from 'react-router-dom';

const AUTH_LINKS_EXCLUDED = new Set(['/', '/profile/complete', '/summary']);
const AUTH_LINKS_EXCLUDED = new Set([
'/',
'/privacy-notice',
'/paperwork-reduction-act-notice',
]);

export const useHeaderAuthLinks = (): ReactElement[] => {
const { pathname } = useLocation();
const auth = useSblAuth();
const headerLinks = [];

const onLogout = (): void => {
// Works well without waiting
// eslint-disable-next-line @typescript-eslint/no-floating-promises
auth.onLogout();
};

if (auth.isLoading || !auth.isAuthenticated) return [];

if (!AUTH_LINKS_EXCLUDED.has(pathname)) {
// Logged in
headerLinks.push(
<NavLink key='home' className='nav-item a-link' to='/landing'>
Home
</NavLink>,
<NavLink key='filing' className='nav-item a-link' to='/filing'>
Filing
</NavLink>,
<NavLink
key='user-name'
className='nav-item a-link profile snapshot-ignore'
to='/profile/view'
>
<span>
{auth.user?.profile.name ??
auth.user?.profile.email ??
'User profile'}
</span>
</NavLink>,
<Button key='logout' label='LOG OUT' asLink onClick={onLogout} />,
);
if (
auth.isLoading ||
!auth.isAuthenticated ||
AUTH_LINKS_EXCLUDED.has(pathname)
) {
return [];
}

return headerLinks;
const headerLinksFull = [
<NavLink key='home' className='nav-item a-link' to='/landing'>
Home
</NavLink>,
<NavLink key='filing' className='nav-item a-link' to='/filing'>
Filing
</NavLink>,
<NavLink
key='user-name'
className='nav-item a-link profile snapshot-ignore'
to='/profile/view'
>
<span>
{auth.user?.profile.name ?? auth.user?.profile.email ?? 'User profile'}
</span>
</NavLink>,
];
const headerLinksPartial = [
<Button key='logout' label='LOG OUT' asLink onClick={onLogout} />,
];

if (
pathname.startsWith('/profile') &&
!pathname.startsWith('/profile/view')
) {
return headerLinksPartial;
}

return [...headerLinksFull, ...headerLinksPartial];
};

export default useHeaderAuthLinks;
Loading