Skip to content

Commit d3467cb

Browse files
committed
BN-19 | Add. i18n for labels in SideNavBar Items
1 parent 8c668c9 commit d3467cb

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/__mocks__/configMocks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export const validDashboardConfig: DashboardConfig = {
203203
{
204204
name: 'Vitals',
205205
icon: 'heartbeat',
206-
translationKey: 'DASHBOARD_VITALS_KEY',
207206
controls: [],
208207
},
209208
{

src/components/common/sidebar/Sidebar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SideNav, SideNavItems, SideNavLink } from '@carbon/react';
33
import BahmniIcon from '@components/common/bahmniIcon/BahmniIcon';
44
import { ICON_SIZE } from '@constants/icon';
55
import * as styles from './styles/Sidebar.module.scss';
6+
import { useTranslation } from 'react-i18next';
67

78
/**
89
* SidebarItem component displays a single item in the sidebar with an icon and label.
@@ -34,6 +35,8 @@ interface SidebarProps {
3435
}
3536

3637
const Sidebar: React.FC<SidebarProps> = ({ items }) => {
38+
const { t } = useTranslation();
39+
3740
const handleOnClick = (e: React.MouseEvent, action: () => void) => {
3841
e.preventDefault();
3942
action();
@@ -63,7 +66,7 @@ const Sidebar: React.FC<SidebarProps> = ({ items }) => {
6366
isActive={item.active}
6467
data-testid={`sidebar-item-${item.id}`}
6568
>
66-
{item.label}
69+
{t(item.label)}
6770
</SideNavLink>
6871
))}
6972
</SideNavItems>

src/components/common/sidebar/__tests__/Sidebar.test.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import React from 'react';
22
import { render, screen, fireEvent } from '@testing-library/react';
33
import Sidebar from '../Sidebar';
44

5+
// Mock react-i18next
6+
jest.mock('react-i18next', () => ({
7+
useTranslation: () => ({
8+
t: (key: string) => {
9+
// For testing, we'll return the key to simulate translation
10+
return key;
11+
},
12+
}),
13+
}));
14+
515
// Mock the CSS module
616
jest.mock('../styles/Sidebar.module.scss', () => ({
717
sidebar: 'sidebar-mock',
@@ -89,11 +99,13 @@ describe('Sidebar', () => {
8999
icon: 'fa-clipboard-list',
90100
label: 'Item 1',
91101
active: true,
102+
action: () => {},
92103
},
93104
{
94105
id: 'item2',
95106
icon: 'fa-heartbeat',
96107
label: 'Item 2',
108+
action: () => {},
97109
},
98110
];
99111

@@ -130,7 +142,7 @@ describe('Sidebar', () => {
130142
const mockAction = jest.fn();
131143
const itemsWithAction = [
132144
{ ...defaultItems[0], action: mockAction },
133-
defaultItems[1],
145+
{ ...defaultItems[1] }, // action is already included from defaultItems
134146
];
135147

136148
render(<Sidebar items={itemsWithAction} />);

src/services/ConsultationPageService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const getSidebarItems = (
4141
id: section.name,
4242
icon: section.icon,
4343
// TODO: add translation
44-
label: section.name,
44+
label: section.translationKey || section.name,
4545
active: false,
4646
action: () => {},
4747
}));

0 commit comments

Comments
 (0)