Skip to content

Commit 0bb09b7

Browse files
committed
feat(web-domains): add subdomain and multisite on associated services cards
ref: DCE-3
1 parent e4c3d85 commit 0bb09b7

File tree

16 files changed

+409
-107
lines changed

16 files changed

+409
-107
lines changed

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/AssociatedServicesCards.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ vi.mock('./Hosting', () => ({
1313
default: () => <div data-testid="hosting-component">Hosting Component</div>,
1414
}));
1515

16+
vi.mock('./SubDomainsMultiSite', () => ({
17+
default: () => (
18+
<div data-testid="subdomains-multisite-component">
19+
SubDomains MultiSite Component
20+
</div>
21+
),
22+
}));
23+
24+
vi.mock('@/domain/hooks/data/query', () => ({
25+
useGetAssociatedHosting: vi.fn(() => ({
26+
data: ['hosting1.com', 'hosting2.com'],
27+
})),
28+
}));
29+
1630
describe('AssociatedServicesCards component', () => {
1731
it('should render the component with title', () => {
1832
render(<AssociatedServicesCards serviceName="example.com" />, { wrapper });
@@ -38,12 +52,26 @@ describe('AssociatedServicesCards component', () => {
3852
expect(screen.getByText('Emails Component')).toBeInTheDocument();
3953
});
4054

55+
it('should render SubDomainsMultiSite component', () => {
56+
render(<AssociatedServicesCards serviceName="example.com" />, { wrapper });
57+
58+
expect(
59+
screen.getByTestId('subdomains-multisite-component'),
60+
).toBeInTheDocument();
61+
expect(
62+
screen.getByText('SubDomains MultiSite Component'),
63+
).toBeInTheDocument();
64+
});
65+
4166
it('should pass serviceName prop to child components', () => {
4267
render(<AssociatedServicesCards serviceName="test-domain.com" />, {
4368
wrapper,
4469
});
4570

4671
expect(screen.getByTestId('hosting-component')).toBeInTheDocument();
72+
expect(
73+
screen.getByTestId('subdomains-multisite-component'),
74+
).toBeInTheDocument();
4775
expect(screen.getByTestId('emails-component')).toBeInTheDocument();
4876
});
4977
});

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/AssociatedServicesCards.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ManagerTile } from '@ovh-ux/manager-react-components';
22
import { useTranslation } from 'react-i18next';
33
import Emails from './Emails';
44
import Hosting from './Hosting';
5+
import SubDomainMultiSite from './SubDomainsMultiSite';
6+
import { useGetAssociatedHosting } from '@/domain/hooks/data/query';
57

68
interface AssociatedServicesCardsProps {
79
readonly serviceName: string;
@@ -11,13 +13,16 @@ export default function AssociatedServicesCards({
1113
serviceName,
1214
}: AssociatedServicesCardsProps) {
1315
const { t } = useTranslation(['domain']);
16+
17+
const { data: associatedHosting } = useGetAssociatedHosting(serviceName);
1418
return (
1519
<ManagerTile>
1620
<ManagerTile.Title>
1721
{t(`domain_tab_general_information_associated_services_title`)}
1822
</ManagerTile.Title>
1923
<ManagerTile.Divider />
2024
<Hosting serviceName={serviceName} />
25+
<SubDomainMultiSite serviceNames={associatedHosting} />
2126
<Emails serviceName={serviceName} />
2227
</ManagerTile>
2328
);

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/Emails.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ vi.mock('@/domain/hooks/data/query', () => ({
1313

1414
describe('Emails component', () => {
1515
it('renders with MXPLAN service detected', async () => {
16-
(useEmailService as jest.Mock).mockReturnValue({
16+
vi.mocked(useEmailService).mockReturnValue({
1717
data: {
1818
serviceDetected: AssociatedEmailsServicesEnum.MXPLAN,
1919
data: 'mxplan-service-id',
2020
},
21-
});
21+
} as ReturnType<typeof useEmailService>);
2222

2323
render(<Emails serviceName="example.com" />, { wrapper });
2424

@@ -39,12 +39,12 @@ describe('Emails component', () => {
3939
});
4040

4141
it('renders with ZIMBRA service detected', async () => {
42-
(useEmailService as jest.Mock).mockReturnValue({
42+
vi.mocked(useEmailService).mockReturnValue({
4343
data: {
4444
serviceDetected: AssociatedEmailsServicesEnum.ZIMBRA,
4545
data: 'zimbra-service-id',
4646
},
47-
});
47+
} as ReturnType<typeof useEmailService>);
4848

4949
render(<Emails serviceName="example.com" />, { wrapper });
5050

@@ -65,12 +65,12 @@ describe('Emails component', () => {
6565
});
6666

6767
it('renders with default service detected', async () => {
68-
(useEmailService as jest.Mock).mockReturnValue({
68+
vi.mocked(useEmailService).mockReturnValue({
6969
data: {
70-
serviceDetected: 'UNKNOWN_SERVICE',
70+
serviceDetected: 'UNKNOWN_SERVICE' as AssociatedEmailsServicesEnum,
7171
data: 'unknown-service-id',
7272
},
73-
});
73+
} as ReturnType<typeof useEmailService>);
7474

7575
render(<Emails serviceName="example.com" />, { wrapper });
7676

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer.spec.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '@/common/setupTests';
22
import React from 'react';
33
import { describe, it, expect, vi, beforeEach } from 'vitest';
44
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
5-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5+
import { wrapper } from '@/common/utils/test.provider';
66
import FreeHostingDrawer from './FreeHostingDrawer';
77
import { FreeHostingOptions } from './Hosting';
88
import { TInitialOrderFreeHosting } from '@/domain/types/hosting';
@@ -141,12 +141,6 @@ vi.mock('../Card/PriceCard', () => ({
141141
}));
142142

143143
describe('FreeHostingDrawer Component', () => {
144-
const queryClient = new QueryClient({
145-
defaultOptions: {
146-
queries: { retry: false },
147-
},
148-
});
149-
150144
const mockOrderFreeHosting = vi.fn();
151145
const mockOnClose = vi.fn();
152146
const mockSetFreeHostingOptions = vi.fn();
@@ -187,11 +181,9 @@ describe('FreeHostingDrawer Component', () => {
187181
});
188182

189183
const renderComponent = (props = {}) => {
190-
return render(
191-
<QueryClientProvider client={queryClient}>
192-
<FreeHostingDrawer {...defaultProps} {...props} />
193-
</QueryClientProvider>,
194-
);
184+
return render(<FreeHostingDrawer {...defaultProps} {...props} />, {
185+
wrapper,
186+
});
195187
};
196188

197189
describe('Drawer rendering', () => {
@@ -421,12 +413,10 @@ describe('FreeHostingDrawer Component', () => {
421413
};
422414

423415
rerender(
424-
<QueryClientProvider client={queryClient}>
425-
<FreeHostingDrawer
426-
{...defaultProps}
427-
freeHostingOptions={updatedOptions}
428-
/>
429-
</QueryClientProvider>,
416+
<FreeHostingDrawer
417+
{...defaultProps}
418+
freeHostingOptions={updatedOptions}
419+
/>,
430420
);
431421

432422
const validateButton = screen.getByTestId('button-default');

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import ActivationSection from './FreeHostingDrawer/ActivationSection';
1919
import LoadingState from './FreeHostingDrawer/LoadingState';
2020

2121
interface FreeHostingDrawerProps {
22-
serviceName: string;
23-
isDrawerOpen: boolean;
24-
freeHostingOptions: FreeHostingOptions;
25-
isInitialOrderFreeHostingPending: boolean;
26-
isOrderFreeHostingPending: boolean;
27-
orderCartDetails: TInitialOrderFreeHosting;
28-
setFreeHostingOptions: React.Dispatch<
22+
readonly serviceName: string;
23+
readonly isDrawerOpen: boolean;
24+
readonly freeHostingOptions: FreeHostingOptions;
25+
readonly isInitialOrderFreeHostingPending: boolean;
26+
readonly isOrderFreeHostingPending: boolean;
27+
readonly orderCartDetails: TInitialOrderFreeHosting;
28+
readonly setFreeHostingOptions: React.Dispatch<
2929
React.SetStateAction<FreeHostingOptions>
3030
>;
31-
onClose: () => void;
32-
orderFreeHosting: UseMutateFunction<
31+
readonly onClose: () => void;
32+
readonly orderFreeHosting: UseMutateFunction<
3333
void,
3434
Error,
3535
{

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer/ActivationSection.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import { TInitialOrderFreeHosting } from '@/domain/types/hosting';
1414
import Section from './Section';
1515

1616
interface ActivationSectionProps {
17-
isLoading: boolean;
18-
freeHostingOptions: FreeHostingOptions;
19-
orderCartDetails: TInitialOrderFreeHosting;
20-
onCheckedChange: (key: keyof FreeHostingOptions, value: boolean) => void;
17+
readonly isLoading: boolean;
18+
readonly freeHostingOptions: FreeHostingOptions;
19+
readonly orderCartDetails: TInitialOrderFreeHosting;
20+
readonly onCheckedChange: (
21+
key: keyof FreeHostingOptions,
22+
value: boolean,
23+
) => void;
2124
}
2225

2326
export default function ActivationSection({

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer/CheckboxCard.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import { useTranslation } from 'react-i18next';
1111
import { FreeHostingOptions } from '../Hosting';
1212

1313
interface CheckboxCardProps {
14-
optionKey: keyof FreeHostingOptions;
15-
translationKey: string;
16-
onCheckedChange: (key: keyof FreeHostingOptions, value: boolean) => void;
14+
readonly optionKey: keyof FreeHostingOptions;
15+
readonly translationKey: string;
16+
readonly onCheckedChange: (
17+
key: keyof FreeHostingOptions,
18+
value: boolean,
19+
) => void;
1720
}
1821

1922
export default function CheckboxCard({

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer/DnsSection.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import CheckboxCard from './CheckboxCard';
55
import Section from './Section';
66

77
interface DnsSectionProps {
8-
onCheckedChange: (key: keyof FreeHostingOptions, value: boolean) => void;
8+
readonly onCheckedChange: (
9+
key: keyof FreeHostingOptions,
10+
value: boolean,
11+
) => void;
912
}
1013

1114
export default function DnsSection({ onCheckedChange }: DnsSectionProps) {

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer/LoadingState.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import { useTranslation } from 'react-i18next';
1212

1313
interface LoadingStateProps {
14-
isOpen: boolean;
15-
onOpenChange: (detail: DrawerOpenChangeDetail) => void;
14+
readonly isOpen: boolean;
15+
readonly onOpenChange: (detail: DrawerOpenChangeDetail) => void;
1616
}
1717

1818
export default function LoadingState({

packages/manager/apps/web-domains/src/domain/components/AssociatedServicesCards/FreeHostingDrawer/Section.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Text, TEXT_PRESET } from '@ovhcloud/ods-react';
22
import { useTranslation } from 'react-i18next';
33

44
interface SectionProps {
5-
title: string;
6-
children: React.ReactNode;
5+
readonly title: string;
6+
readonly children: React.ReactNode;
77
}
88

99
export default function Section({ title, children }: SectionProps) {
1010
const { t } = useTranslation(['domain']);
1111

1212
return (
13-
<div className="space-y-8">
13+
<div className="space-y-6">
1414
<Text preset={TEXT_PRESET.heading3}>{t(title)}</Text>
1515
{children}
1616
</div>

0 commit comments

Comments
 (0)