-
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: Pierre-Philippe <[email protected]>
- Loading branch information
Pierre-Philippe
committed
Dec 31, 2024
1 parent
d4e28fe
commit 27a5a5e
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...anager-pci-common/src/components/banner/savings-plan-banner/PciSavingsPlanBanner.spec.tsx
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,43 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { describe, it, vi } from 'vitest'; | ||
import PciSavingPlanBanner from './PciSavingsPlanBanner'; | ||
|
||
const mockNavigateTo = vi.fn(); | ||
vi.mock('@ovh-ux/manager-react-shell-client', () => ({ | ||
useNavigation: () => ({ | ||
navigateTo: mockNavigateTo, | ||
}), | ||
})); | ||
|
||
describe('PciSavingPlanBanner tests', () => { | ||
it('should render the banner with the correct message and CTA', () => { | ||
const { container } = render( | ||
<PciSavingPlanBanner className="test-class" />, | ||
); | ||
|
||
expect( | ||
screen.getByText('pci_projects_savings_plan_banner'), | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
screen.getByText('pci_projects_savings_plan_cta'), | ||
).toBeInTheDocument(); | ||
|
||
expect(container.querySelector('.test-class')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call navigateToSavingsPlan on CTA click', async () => { | ||
render(<PciSavingPlanBanner className="test-class" />); | ||
|
||
const ctaButton = screen.getByText('pci_projects_savings_plan_cta'); | ||
|
||
fireEvent.click(ctaButton); | ||
|
||
expect(mockNavigateTo).toHaveBeenCalledWith( | ||
'public-cloud', | ||
`#/pci/projects/mockProjectUrl/savings-plan`, | ||
{}, | ||
); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
...les/manager-pci-common/src/components/banner/savings-plan-banner/PciSavingsPlanBanner.tsx
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,32 @@ | ||
import { ActionBanner, useProjectUrl } from '@ovh-ux/manager-react-components'; | ||
import { ShellContext } from '@ovh-ux/manager-react-shell-client'; | ||
import { useContext } from 'react'; | ||
import { ODS_MESSAGE_TYPE } from '@ovhcloud/ods-components'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const PciSavingsPlanBanner = ({ className }: { className: string }) => { | ||
const { t } = useTranslation('saving-plan-banner'); | ||
const projectURL = useProjectUrl('public-cloud'); | ||
const { | ||
navigation: { navigateTo }, | ||
} = useContext(ShellContext).shell; | ||
const navigateToSavingsPlan = async () => { | ||
await navigateTo( | ||
'public-cloud', | ||
`#/pci/projects/${projectURL}/savings-plan`, | ||
{}, | ||
); | ||
}; | ||
|
||
return ( | ||
<ActionBanner | ||
message={t('pci_projects_savings_plan_banner')} | ||
cta={t('pci_projects_savings_plan_cta')} | ||
type={ODS_MESSAGE_TYPE.info} | ||
onClick={navigateToSavingsPlan} | ||
className={className} | ||
/> | ||
); | ||
}; | ||
|
||
export default PciSavingsPlanBanner; |