-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thibault Barske <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const packTypeLabel = { | ||
'hycu-cloud-vm-pack-25': '25 VMs', | ||
'hycu-cloud-vm-pack-50': '50 VMs', | ||
'hycu-cloud-vm-pack-100': '100 VMs', | ||
'hycu-cloud-vm-pack-150': '150 VMs', | ||
'hycu-cloud-vm-pack-200': '200 VMs', | ||
'hycu-cloud-vm-pack-250': '250 VMs', | ||
'hycu-cloud-vm-pack-500': '500 VMs', | ||
} as const; |
47 changes: 47 additions & 0 deletions
47
packages/manager/apps/hycu/src/hooks/service/usePackLabel.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, expect, it, test, vi } from 'vitest'; | ||
import { usePackTypeLabel } from './usePackLabel'; | ||
|
||
vi.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (translationKey: string) => `${translationKey}_translated`, | ||
i18n: { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
changeLanguage: () => new Promise(() => {}), | ||
}, | ||
}), | ||
})); | ||
|
||
describe('get service key type translation ', () => { | ||
const useCases: { | ||
type: string; | ||
label: string; | ||
}[] = [ | ||
{ | ||
type: 'hycu-cloud-vm-pack-25', | ||
label: '25 VMs', | ||
}, | ||
{ | ||
type: 'hycu-cloud-vm-pack-250', | ||
label: '250 VMs', | ||
}, | ||
]; | ||
test.each(useCases)( | ||
'should return the right translation key for $type', | ||
({ type, label }) => { | ||
// given type and translationKey | ||
// when | ||
const result = usePackTypeLabel(type); | ||
// then | ||
expect(result).toBe(label); | ||
}, | ||
); | ||
it('should return type if unexpected value', () => { | ||
// given | ||
const type = 'hycu-cloud-vm-pack-123'; | ||
// when | ||
const result = usePackTypeLabel(type); | ||
|
||
// then | ||
expect(result).toBe('hycu-cloud-vm-pack-unknown_translated'); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/manager/apps/hycu/src/hooks/service/usePackLabel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { packTypeLabel } from '@/constants'; | ||
|
||
export const usePackTypeLabel = (packType: string) => { | ||
const { t } = useTranslation('common'); | ||
|
||
return ( | ||
packTypeLabel[packType as keyof typeof packTypeLabel] ?? | ||
t('hycu-cloud-vm-pack-unknown') | ||
); | ||
}; |