Skip to content

Commit

Permalink
feat(pci-common): lint
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Philippe <[email protected]>
  • Loading branch information
Pierre-Philippe committed Dec 31, 2024
1 parent d4e28fe commit 27a5a5e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
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`,
{},
);
});
});
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;

0 comments on commit 27a5a5e

Please sign in to comment.