Skip to content

Commit

Permalink
feat(container): fix the tests
Browse files Browse the repository at this point in the history
ref: MANAGER-16358

Signed-off-by: Maxime Bajeux <[email protected]>
  • Loading branch information
Maxime Bajeux committed Dec 18, 2024
1 parent 9284da0 commit 30ce7e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const pciProjects : Array<Partial<PciProject>> = [
];

const onProjectChange = vi.fn();
const onProjectCreate = vi.fn();
const onSeeAllProjects = vi.fn();
const onMenuOpen = vi.fn();

Expand All @@ -24,10 +23,8 @@ const props: Props = {
projects: pciProjects as Array<PciProject>,
selectedProject: pciProjects[0] as PciProject,
onProjectChange: onProjectChange,
onProjectCreate: onProjectCreate,
onSeeAllProjects: onSeeAllProjects,
onMenuOpen: onMenuOpen,
createLabel: "Créer un projet",
seeAllButton: true,
seeAllLabel: "Tous mes projets Public Cloud",
}
Expand All @@ -38,9 +35,7 @@ const renderProjectSelector = (props: Props) => {
projects={props.projects}
selectedProject={props.projects[0]}
onProjectChange={props.onProjectChange}
onProjectCreate={props.onProjectCreate}
onSeeAllProjects={props.onSeeAllProjects}
createLabel={props.createLabel}
seeAllButton={props.seeAllButton}
seeAllLabel={props.seeAllLabel}
/>);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { vi, it, describe, expect } from 'vitest';
import { render, waitFor } from '@testing-library/react';
import { render, act, fireEvent } from '@testing-library/react';
import { Node } from '../navigation-tree/node';
import { PublicCloudPanel, PublicCloudPanelProps } from './PublicCloudPanel';
import { mockShell } from '../mocks/sidebarMocks';
import { mockShell, mockPlugins } from '../mocks/sidebarMocks';
import { PciProject } from '../ProjectSelector/PciProject';
import { Props as ProjectSelectorProps } from '../ProjectSelector/ProjectSelector';
import { pciNode } from '../navigation-tree/services/publicCloud';
Expand Down Expand Up @@ -105,4 +105,12 @@ describe('PublicCloudPanel.component', () => {
expect(projectSelector).not.toBeNull();
expect(projectSelector.innerHTML).toBe('12345');
});

it('should navigate to project creation when the button is clicked', async () => {
const { queryByTestId } = renderPublicCloudPanelComponent(props);
const createButton = queryByTestId('pci-create-project');
await act(() => fireEvent.click(createButton));

expect(mockPlugins.navigation.navigateTo).toHaveBeenCalled();
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const PublicCloudPanel: React.FC<ComponentProps<
color={ODS_THEME_COLOR_INTENT.primary}
type={ODS_BUTTON_TYPE.button}
size={ODS_BUTTON_SIZE.sm}
data-testid="pci-create-project"
variant={ODS_BUTTON_VARIANT.flat}
onClick={() =>
navigationPlugin.navigateTo('public-cloud', `#/pci/projects/new`)
Expand Down

0 comments on commit 30ce7e4

Please sign in to comment.