Skip to content

Commit

Permalink
feat(pci-common): lint test and fix
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 27a5a5e commit 24fa9dd
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigation } from '@ovh-ux/manager-react-shell-client';
import { ODS_MESSAGE_TYPE } from '@ovhcloud/ods-components';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import '@testing-library/jest-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import {
ShellContext,
ShellContextType,
} from '@ovh-ux/manager-react-shell-client';
import { describe, it, vi } from 'vitest';
import PciSavingPlanBanner from './PciSavingsPlanBanner';
import { wrapper } from '@/wrapperRenders';

const mockNavigateTo = vi.fn();
vi.mock('@ovh-ux/manager-react-shell-client', () => ({
useNavigation: () => ({
navigateTo: mockNavigateTo,
}),
}));

const mockShellContext = {
shell: {
navigation: {
navigateTo: mockNavigateTo,
},
},
};

describe('PciSavingPlanBanner tests', () => {
it('should render the banner with the correct message and CTA', () => {
const { container } = render(
<PciSavingPlanBanner className="test-class" />,
{ wrapper },
);

expect(
Expand All @@ -28,7 +37,13 @@ describe('PciSavingPlanBanner tests', () => {
});

it('should call navigateToSavingsPlan on CTA click', async () => {
render(<PciSavingPlanBanner className="test-class" />);
render(
<ShellContext.Provider
value={(mockShellContext as unknown) as ShellContextType}
>
<PciSavingPlanBanner className="test-class" />
</ShellContext.Provider>,
);

const ctaButton = screen.getByText('pci_projects_savings_plan_cta');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 { t } = useTranslation('savings-plan-banner');
const projectURL = useProjectUrl('public-cloud');
const {
navigation: { navigateTo },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import pl_PL from './Messages_pl_PL.json';
import pt_PT from './Messages_pt_PT.json';

function addTranslations() {
i18next.addResources('de_DE', 'saving-plan-banner', de_DE);
i18next.addResources('en_GB', 'saving-plan-banner', en_GB);
i18next.addResources('es_ES', 'saving-plan-banner', es_ES);
i18next.addResources('fr_CA', 'saving-plan-banner', fr_CA);
i18next.addResources('fr_FR', 'saving-plan-banner', fr_FR);
i18next.addResources('it_IT', 'saving-plan-banner', it_IT);
i18next.addResources('pl_PL', 'saving-plan-banner', pl_PL);
i18next.addResources('pt_PT', 'saving-plan-banner', pt_PT);
i18next.addResources('de_DE', 'savings-plan-banner', de_DE);
i18next.addResources('en_GB', 'savings-plan-banner', en_GB);
i18next.addResources('es_ES', 'savings-plan-banner', es_ES);
i18next.addResources('fr_CA', 'savings-plan-banner', fr_CA);
i18next.addResources('fr_FR', 'savings-plan-banner', fr_FR);
i18next.addResources('it_IT', 'savings-plan-banner', it_IT);
i18next.addResources('pl_PL', 'savings-plan-banner', pl_PL);
i18next.addResources('pt_PT', 'savings-plan-banner', pt_PT);
}

if (i18next.isInitialized) {
Expand Down

0 comments on commit 24fa9dd

Please sign in to comment.