Skip to content

Commit

Permalink
test(pci-common): update region-selector test suites
Browse files Browse the repository at this point in the history
ref: TAPC-2378
Signed-off-by: Frédéric Vilcot <[email protected]>
  • Loading branch information
fredericvilcot committed Dec 16, 2024
1 parent 0408b8e commit 08fd2b7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
3 changes: 2 additions & 1 deletion packages/manager/modules/manager-pci-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"prettier": "prettier --write \"src/**/*.{ts,tsx,js,mdx}\"",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"test:watch": "vitest --watch"
"test:watch": "vitest --watch",
"type:check": "tsc --noEmit"
},
"dependencies": {
"@ovh-ux/manager-tailwind-config": "^0.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { render, screen } from '@testing-library/react';
import { render } from '@testing-library/react';
import { RegionGlobalzoneChip } from './RegionGlobalzoneChip.component';
import { wrapper } from '@/wrapperRenders';

describe('RegionGlobalzoneChip', () => {
it('renders chip with correct text', () => {
render(<RegionGlobalzoneChip />, { wrapper });
expect(
screen.getByText('pci_project_flavors_zone_global_region'),
).toBeInTheDocument();
it('renders tag with correct text', () => {
const { container } = render(<RegionGlobalzoneChip id="fake-id" />, {
wrapper,
});
const tagElt = container.querySelector('#fake-id').firstChild;

expect(tagElt).toBeInTheDocument();
expect(tagElt).toHaveAttribute(
'label',
'pci_project_flavors_zone_global_region',
);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react';
import { FC, useContext } from 'react';
import { Links, LinkType } from '@ovh-ux/manager-react-components';
import { ShellContext } from '@ovh-ux/manager-react-shell-client';
import { useTranslation } from 'react-i18next';
Expand All @@ -10,7 +10,11 @@ import {
} from '@ovhcloud/ods-components';
import { URL_INFO } from './constants';

export function RegionGlobalzoneChip() {
export type TRegionGlobalzoneChipProps = Readonly<{ id: string }>;

export const RegionGlobalzoneChip: FC<TRegionGlobalzoneChipProps> = ({
id,
}) => {
const { t } = useTranslation('pci-region-selector');
const context = useContext(ShellContext);
const { ovhSubsidiary } = context.environment.getUser();
Expand All @@ -20,7 +24,7 @@ export function RegionGlobalzoneChip() {

return (
<>
<div id="popover-trigger">
<div id={id}>
<OdsTag
className="font-bold"
label={t('pci_project_flavors_zone_global_region')}
Expand All @@ -30,7 +34,7 @@ export function RegionGlobalzoneChip() {
onClick={(event) => event.stopPropagation()}
/>
</div>
<OdsPopover triggerId="popover-trigger">
<OdsPopover triggerId={id}>
<OdsText preset="span">
{t('pci_project_flavors_zone_globalregions_tooltip')}
</OdsText>
Expand All @@ -45,4 +49,4 @@ export function RegionGlobalzoneChip() {
</OdsPopover>
</>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { RegionLocalzoneChip } from './RegionLocalzoneChip.component';
import { wrapper } from '@/wrapperRenders';

describe('RegionLocalzoneChip', () => {
it('renders chip with correct text', () => {
render(<RegionLocalzoneChip />, { wrapper });
expect(
screen.getByText('pci_project_flavors_zone_localzone'),
).toBeInTheDocument();
it('renders tag with correct text', () => {
const { container } = render(<RegionLocalzoneChip id="fake-id" />, {
wrapper,
});
const tagElt = container.querySelector('#fake-id').firstChild;

expect(tagElt).toBeInTheDocument();
expect(tagElt).toHaveAttribute(
'label',
'pci_project_flavors_zone_localzone',
);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react';
import { FC, useContext } from 'react';
import { Links, LinkType } from '@ovh-ux/manager-react-components';
import { ShellContext } from '@ovh-ux/manager-react-shell-client';
import { useTranslation } from 'react-i18next';
Expand All @@ -10,7 +10,9 @@ import {
} from '@ovhcloud/ods-components';
import { URL_INFO } from './constants';

export function RegionLocalzoneChip() {
export type TRegionLocalzoneChipProps = Readonly<{ id: string }>;

export const RegionLocalzoneChip: FC<TRegionLocalzoneChipProps> = ({ id }) => {
const { t } = useTranslation('pci-region-selector');
const context = useContext(ShellContext);
const { ovhSubsidiary } = context.environment.getUser();
Expand All @@ -20,7 +22,7 @@ export function RegionLocalzoneChip() {

return (
<>
<div id="popover-trigger">
<div id={id}>
<OdsTag
className="font-bold"
label={t('pci_project_flavors_zone_localzone')}
Expand All @@ -30,7 +32,7 @@ export function RegionLocalzoneChip() {
onClick={(event) => event.stopPropagation()}
/>
</div>
<OdsPopover triggerId="popover-trigger">
<OdsPopover triggerId={id}>
<OdsText preset="span">
{t('pci_project_flavors_zone_localzone_tooltip')}
</OdsText>
Expand All @@ -45,4 +47,4 @@ export function RegionLocalzoneChip() {
</OdsPopover>
</>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const RegionTile = ({
<hr className="w-full border-solid border-0 border-b border-ods-primary-200" />
<div>
{region?.isLocalZone ? (
<RegionLocalzoneChip />
<RegionLocalzoneChip id={`popover-localzone-${region.name}`} />
) : (
<RegionGlobalzoneChip />
<RegionGlobalzoneChip id={`popover-globalzone-${region.name}`} />
)}
</div>
</>
Expand Down

0 comments on commit 08fd2b7

Please sign in to comment.