Skip to content
Merged
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
4 changes: 3 additions & 1 deletion app/components/navbar/nav-item-with-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function NavItemWithDropdown({
const triggerStyles = cx(
flex({ gap: '1', align: 'center' }),
css({
px: '4',
// Same spacing as the plain links in `navbar.tsx`.
px: { base: '4', lg: '3', xl: '4' },
py: '2',
rounded: 'full',
fontSize: 'sm',
Expand All @@ -41,6 +42,7 @@ export function NavItemWithDropdown({
transitionDuration: 'slow',
color: isOpen || isCurrentPath ? 'ocobo.dark' : 'gray.500',
_hover: { color: 'ocobo.dark' },
whiteSpace: 'nowrap',
}),
);

Expand Down
15 changes: 11 additions & 4 deletions app/components/navbar/navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,29 @@ const withChallenges = (challenges: ChallengeMenuEntry[], failed = false) => ({
});

describe('Navbar challenge entry', () => {
it('is hidden when no challenge is published', () => {
it('is hidden when no challenge is published, and the offer stays', () => {
render(<Navbar />, withChallenges([]));

expect(
screen.queryByRole('button', { name: /vos enjeux/i }),
).not.toBeInTheDocument();
expect(
screen.getByRole('link', { name: 'Notre Offre' }),
).toBeInTheDocument();
});

it('comes first and lists the challenges in the order given', async () => {
it('replaces the offer entry and lists the challenges in order', async () => {
const user = userEvent.setup();
render(<Navbar />, withChallenges(frenchChallenges));

const trigger = screen.getByRole('button', { name: /vos enjeux/i });
const offer = screen.getByRole('link', { name: 'Notre Offre' });
expect(
trigger.compareDocumentPosition(offer) & Node.DOCUMENT_POSITION_FOLLOWING,
screen.queryByRole('link', { name: 'Notre Offre' }),
).not.toBeInTheDocument();
const stories = screen.getByRole('link', { name: 'Success Stories' });
expect(
trigger.compareDocumentPosition(stories) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();

await user.click(trigger);
Expand Down
8 changes: 5 additions & 3 deletions app/components/navbar/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const getLinkStyles = (isDropdownActive: boolean, isCurrent: boolean) =>
cx(
flex({ gap: '1', align: 'center' }),
css({
px: '4',
// Tighter between 1024px and 1280px, so the bar stays on one line.
px: { base: '4', lg: '3', xl: '4' },
py: '2',
rounded: 'full',
fontSize: 'sm',
Expand Down Expand Up @@ -71,7 +72,8 @@ export function Navbar() {
className={css({
position: 'relative',
w: 'full',
maxW: scrolled ? '5xl' : '7xl',
// 6xl holds every item on one line once the challenges entry shows.
maxW: scrolled ? '6xl' : '7xl',
transition: 'all',
transitionDuration: '[700ms]',
transitionTimingFunction: 'smooth',
Expand Down Expand Up @@ -136,7 +138,7 @@ export function Navbar() {
{/* Desktop Navigation */}
<div
className={cx(
hstack({ gap: '2' }),
hstack({ gap: { base: '2', lg: '1', xl: '2' } }),
css({
display: { base: 'none', lg: 'flex' },
px: '2',
Expand Down
64 changes: 64 additions & 0 deletions app/hooks/useMenuItems.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { describe, expect, it } from 'vitest';

import type { NavItem } from '~/components/navbar/types';

import { placeChallengeItem } from './useMenuItems';

const offer: NavItem = { key: 'offer', label: 'Notre offre', path: '/offer' };
const stories: NavItem = { key: 'stories', label: 'Stories', path: '/clients' };
const contact: NavItem = {
key: 'contact',
label: 'Contact',
path: '/contact',
isButton: true,
};
const challenges: NavItem = {
key: 'challenges',
label: 'Vos enjeux',
path: null,
dropdown: [
{
key: 'challenge-revenue-performance',
label: 'Revenue Performance',
path: '/challenges/revenue-performance',
color: 'yellow',
},
],
};

describe('placeChallengeItem', () => {
it('puts the challenge entry in the place of the offer entry', () => {
const items = placeChallengeItem([offer, stories, contact], challenges);

expect(items.map((item) => item.key)).toEqual([
'challenges',
'stories',
'contact',
]);
expect(items[0]).toBe(challenges);
});

it('keeps the offer entry when no challenge is published', () => {
const items = [offer, stories, contact];

expect(placeChallengeItem(items, null)).toEqual([offer, stories, contact]);
});

it('keeps the challenge entry, first, when there is no offer entry', () => {
const items = placeChallengeItem([stories, contact], challenges);

expect(items.map((item) => item.key)).toEqual([
'challenges',
'stories',
'contact',
]);
});

it('does not mutate the given list', () => {
const items = [offer, stories];

placeChallengeItem(items, challenges);

expect(items).toEqual([offer, stories]);
});
});
23 changes: 21 additions & 2 deletions app/hooks/useMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ const menuKeyToSlug: Record<string, PageSlug> = {
tools: 'tools',
};

/**
* Puts the challenge entry in the place of the offer entry: "Vos enjeux"
* replaces "Notre offre" once a challenge is published in the page language.
* Without one, the offer entry stays. The `/offer` route itself stays live.
*/
export function placeChallengeItem(
items: NavItem[],
challengeItem: NavItem | null,
): NavItem[] {
if (challengeItem === null) {
return items;
}
if (!items.some((item) => item.key === 'offer')) {
return [challengeItem, ...items];
}
return items.map((item) => (item.key === 'offer' ? challengeItem : item));
}

export function useMenuItems(): NavItem[] {
const { t } = useTranslation('common');
const getLocalizedPath = useLocalizedPathname();
Expand Down Expand Up @@ -127,8 +145,7 @@ export function useMenuItems(): NavItem[] {
},
];

return [
...(challengeItem ? [challengeItem] : []),
const items: NavItem[] = [
{
key: 'offer',
label: t('navigation.offer'),
Expand Down Expand Up @@ -164,4 +181,6 @@ export function useMenuItems(): NavItem[] {
isButton: true,
},
];

return placeChallengeItem(items, challengeItem);
}
Loading