Skip to content

Commit f7f170d

Browse files
Merge pull request #293 from OneBusAway/fix-291
feat: add option to hide region name in navigation bar
2 parents 8214dc7 + de3e741 commit f7f170d

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PUBLIC_OBA_REGION_CENTER_LAT=47.60728155903877
1717
PUBLIC_OBA_REGION_CENTER_LNG=-122.3339240843084
1818
PUBLIC_OBA_REGION_NAME="Puget Sound"
1919

20+
# Set to "false" to hide the region name text in the navigation bar
21+
SHOW_REGION_NAME_IN_NAV_BAR=true
22+
2023
PUBLIC_OBA_SERVER_URL="https://api.pugetsound.onebusaway.org/"
2124

2225
PUBLIC_OTP_SERVER_URL=""

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ See `.env.example` for an example of the required keys and values.
2727

2828
- `PUBLIC_OBA_REGION_NAME` - string: (required) displayed in the header.
2929
- `PUBLIC_OBA_LOGO_URL` - string: (required) The URL of your transit agency's logo.
30+
- `SHOW_REGION_NAME_IN_NAV_BAR` - boolean: (optional) Set to "false" to hide the region name text in the navigation bar. Defaults to true.
3031
- `FAVICON_URL` - string: (optional) URL to a custom favicon. Falls back to the default favicon if not specified.
3132
- `PUBLIC_NAV_BAR_LINKS` - JSON string: (required) A dictionary of the links displayed across the navigation bar.
3233

eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default [
1616
...globals.node,
1717
L: 'readonly',
1818
google: 'readonly',
19-
$state: 'readonly'
19+
$state: 'readonly',
20+
__SHOW_REGION_NAME_IN_NAV_BAR__: 'readonly'
2021
}
2122
}
2223
},

src/components/navigation/Header.svelte

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import ThemeSwitcher from '$lib/ThemeSwitch/ThemeSwitcher.svelte';
1010
import MobileMenu from './MobileMenu.svelte';
1111
12+
const showRegionName = __SHOW_REGION_NAME_IN_NAV_BAR__;
13+
1214
let isMobileMenuOpen = $state(false);
1315
let shouldShowMobile = $state(false);
1416
let navContainer;
@@ -107,9 +109,11 @@
107109
<a href="/" class="block">
108110
<img src={PUBLIC_OBA_LOGO_URL} alt={PUBLIC_OBA_REGION_NAME} class="h-10 rounded-sm" />
109111
</a>
110-
<a href="/" class="block text-xl font-extrabold text-brand-foreground">
111-
{PUBLIC_OBA_REGION_NAME}
112-
</a>
112+
{#if showRegionName}
113+
<a href="/" class="block text-xl font-extrabold text-brand-foreground">
114+
{PUBLIC_OBA_REGION_NAME}
115+
</a>
116+
{/if}
113117
</div>
114118
</div>
115119

src/components/navigation/__tests__/Header.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ vi.mock('$env/static/public', () => ({
99
PUBLIC_NAV_BAR_LINKS: '{"Home": "/", "About": "/about"}'
1010
}));
1111

12+
// Set default value for the global define
13+
globalThis.__SHOW_REGION_NAME_IN_NAV_BAR__ = true;
14+
1215
// Mock ThemeSwitcher component
1316
vi.mock('$lib/ThemeSwitch/ThemeSwitcher.svelte', () => ({
1417
default: () => '<div data-testid="theme-switcher">Theme Switcher</div>'
@@ -131,3 +134,44 @@ describe('Header', () => {
131134
expect(textLink).toHaveClass('block', 'text-xl', 'font-extrabold');
132135
});
133136
});
137+
138+
describe('Header with region name hidden', () => {
139+
beforeEach(() => {
140+
globalThis.__SHOW_REGION_NAME_IN_NAV_BAR__ = false;
141+
142+
// Mock ResizeObserver
143+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
144+
observe: vi.fn(),
145+
unobserve: vi.fn(),
146+
disconnect: vi.fn()
147+
}));
148+
});
149+
150+
afterEach(() => {
151+
globalThis.__SHOW_REGION_NAME_IN_NAV_BAR__ = true;
152+
vi.restoreAllMocks();
153+
});
154+
155+
test('hides region name text when config is false', () => {
156+
render(Header);
157+
158+
// Region name text should not be present
159+
expect(screen.queryByText('Test Region')).not.toBeInTheDocument();
160+
});
161+
162+
test('logo alt text still uses region name for accessibility', () => {
163+
render(Header);
164+
165+
// Logo should still have the region name as alt text
166+
const logo = screen.getByRole('img');
167+
expect(logo).toHaveAttribute('alt', 'Test Region');
168+
});
169+
170+
test('only logo link exists when region name is hidden', () => {
171+
render(Header);
172+
173+
// Should only have one link for the logo
174+
const links = screen.getAllByRole('link', { name: /test region/i });
175+
expect(links).toHaveLength(1);
176+
});
177+
});

vite.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { sveltekit } from '@sveltejs/kit/vite';
22
import { svelteTesting } from '@testing-library/svelte/vite';
33
import { defineConfig } from 'vitest/config';
4+
import dotenv from 'dotenv';
5+
6+
dotenv.config();
47

58
export default defineConfig({
69
plugins: [sveltekit(), svelteTesting()],
10+
define: {
11+
__SHOW_REGION_NAME_IN_NAV_BAR__: JSON.stringify(
12+
process.env.SHOW_REGION_NAME_IN_NAV_BAR !== 'false'
13+
)
14+
},
715
test: {
816
include: ['src/**/*.{test,spec}.{js,ts}'],
917
coverage: {

0 commit comments

Comments
 (0)