Skip to content

Commit 84e0540

Browse files
author
test
committed
fix(public): gate home navbar careers link
1 parent 109c1a0 commit 84e0540

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
5+
import { renderToStaticMarkup } from 'react-dom/server'
6+
import { beforeEach, describe, expect, it, vi } from 'vitest'
7+
8+
const { mockFeatureFlags } = vi.hoisted(() => ({
9+
mockFeatureFlags: {
10+
isPublicCareersLinkEnabled: true,
11+
},
12+
}))
13+
14+
vi.mock('next/link', () => ({
15+
default: ({ href, children, ...props }: React.ComponentProps<'a'>) => (
16+
<a href={typeof href === 'string' ? href : ''} {...props}>
17+
{children}
18+
</a>
19+
),
20+
}))
21+
22+
vi.mock('next/image', () => ({
23+
default: (props: React.ComponentProps<'img'>) => <img {...props} alt={props.alt ?? ''} />,
24+
}))
25+
26+
vi.mock('@/lib/core/config/feature-flags', () => ({
27+
get isPublicCareersLinkEnabled() {
28+
return mockFeatureFlags.isPublicCareersLinkEnabled
29+
},
30+
}))
31+
32+
vi.mock('@/app/(home)/components/navbar/components/github-stars', () => ({
33+
GitHubStars: () => <div>GitHubStars</div>,
34+
}))
35+
36+
import Navbar from './navbar'
37+
38+
describe('home navbar careers link', () => {
39+
beforeEach(() => {
40+
mockFeatureFlags.isPublicCareersLinkEnabled = true
41+
})
42+
43+
it('hides careers when the careers link flag is disabled', () => {
44+
mockFeatureFlags.isPublicCareersLinkEnabled = false
45+
46+
const html = renderToStaticMarkup(<Navbar />)
47+
48+
expect(html).not.toContain('>Careers<')
49+
expect(html).toContain('>Docs<')
50+
expect(html).toContain('>Pricing<')
51+
expect(html).toContain('>Enterprise<')
52+
})
53+
54+
it('keeps careers in the original position when the flag is enabled', () => {
55+
const html = renderToStaticMarkup(<Navbar />)
56+
57+
expect(html).toContain('>Pricing<')
58+
expect(html).toContain('>Careers<')
59+
expect(html).toContain('>Enterprise<')
60+
expect(html.indexOf('>Pricing<')).toBeLessThan(html.indexOf('>Careers<'))
61+
expect(html.indexOf('>Careers<')).toBeLessThan(html.indexOf('>Enterprise<'))
62+
})
63+
})

apps/sim/app/(home)/components/navbar/navbar.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Image from 'next/image'
22
import Link from 'next/link'
33
import { ChevronDown } from '@/components/emcn'
4+
import { isPublicCareersLinkEnabled } from '@/lib/core/config/feature-flags'
45
import { GitHubStars } from '@/app/(home)/components/navbar/components/github-stars'
56

67
interface NavLink {
@@ -10,12 +11,14 @@ interface NavLink {
1011
icon?: 'chevron'
1112
}
1213

13-
const NAV_LINKS: NavLink[] = [
14-
{ label: 'Docs', href: 'https://docs.sim.ai', external: true },
15-
{ label: 'Pricing', href: '/pricing' },
16-
{ label: 'Careers', href: '/careers' },
17-
{ label: 'Enterprise', href: '/enterprise' },
18-
]
14+
function getNavLinks(): NavLink[] {
15+
return [
16+
{ label: 'Docs', href: 'https://docs.sim.ai', external: true },
17+
{ label: 'Pricing', href: '/pricing' },
18+
...(isPublicCareersLinkEnabled ? [{ label: 'Careers', href: '/careers' }] : []),
19+
{ label: 'Enterprise', href: '/enterprise' },
20+
]
21+
}
1922

2023
/** Logo and nav edge: horizontal padding (px) for left/right symmetry. */
2124
const LOGO_CELL = 'flex items-center px-[20px]'
@@ -24,6 +27,8 @@ const LOGO_CELL = 'flex items-center px-[20px]'
2427
const LINK_CELL = 'flex items-center px-[14px]'
2528

2629
export default function Navbar() {
30+
const navLinks = getNavLinks()
31+
2732
return (
2833
<nav
2934
aria-label='Primary navigation'
@@ -48,7 +53,7 @@ export default function Navbar() {
4853

4954
{/* Links */}
5055
<ul className='mt-[0.75px] flex'>
51-
{NAV_LINKS.map(({ label, href, external, icon }) => (
56+
{navLinks.map(({ label, href, external, icon }) => (
5257
<li key={label} className='flex'>
5358
{external ? (
5459
<a href={href} target='_blank' rel='noopener noreferrer' className={LINK_CELL}>

0 commit comments

Comments
 (0)