Skip to content

Commit

Permalink
feat(pci-db-analytics): rework modals (#14216)
Browse files Browse the repository at this point in the history
ref: DATATR-1690
ref: DATATR-1695
ref: DATATR-1757

Signed-off-by: Jonathan Perchoc <[email protected]>
Co-authored-by: CDS Translator Agent <[email protected]>
  • Loading branch information
2 people authored and fredericvilcot committed Dec 12, 2024
1 parent a549c73 commit 6b29873
Show file tree
Hide file tree
Showing 143 changed files with 5,346 additions and 3,669 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Eine ähnliche Integration ist bereits vorhanden.",
"addIntegrationErrorStringParamRequired": "Erforderlich",
"addIntegrationErrorIntegerParamRequired": "Geben Sie eine positive Zahl ein.",
"addIntegrationButtonAdd": "Hinzufügen"
"addIntegrationButtonAdd": "Hinzufügen",
"addIntegrationButtonCancel": "Abbrechen"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "A similar integration already exists",
"addIntegrationErrorStringParamRequired": "Required",
"addIntegrationErrorIntegerParamRequired": "Please enter a positive number",
"addIntegrationButtonAdd": "Add"
"addIntegrationButtonAdd": "Add",
"addIntegrationButtonCancel": "Cancel"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Ya existe una integración similar.",
"addIntegrationErrorStringParamRequired": "Requerido",
"addIntegrationErrorIntegerParamRequired": "Introduzca un número positivo",
"addIntegrationButtonAdd": "Añadir"
"addIntegrationButtonAdd": "Añadir",
"addIntegrationButtonCancel": "Cancelar"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Une intégration similaire existe déjà",
"addIntegrationErrorStringParamRequired": "Requis",
"addIntegrationErrorIntegerParamRequired": "Veuillez entrer un nombre positif",
"addIntegrationButtonAdd": "Ajouter"
"addIntegrationButtonAdd": "Ajouter",
"addIntegrationButtonCancel": "Annuler"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Une intégration similaire existe déjà",
"addIntegrationErrorStringParamRequired": "Requis",
"addIntegrationErrorIntegerParamRequired": "Veuillez entrer un nombre positif",
"addIntegrationButtonAdd": "Ajouter"
"addIntegrationButtonAdd": "Ajouter",
"addIntegrationButtonCancel": "Annuler"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Esiste già un'integrazione analoga.",
"addIntegrationErrorStringParamRequired": "Obbligatorio",
"addIntegrationErrorIntegerParamRequired": "Inserisci un numero positivo",
"addIntegrationButtonAdd": "Aggiungi"
"addIntegrationButtonAdd": "Aggiungi",
"addIntegrationButtonCancel": "Annulla"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Podobna integracja już istnieje.",
"addIntegrationErrorStringParamRequired": "Wymagane",
"addIntegrationErrorIntegerParamRequired": "Wprowadź liczbę dodatnią",
"addIntegrationButtonAdd": "Dodaj"
"addIntegrationButtonAdd": "Dodaj",
"addIntegrationButtonCancel": "Anuluj"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"addIntegrationErrorNoDuplicate": "Já existe uma integração semelhante",
"addIntegrationErrorStringParamRequired": "Obrigatório",
"addIntegrationErrorIntegerParamRequired": "Introduza um número positivo",
"addIntegrationButtonAdd": "Adicionar"
"addIntegrationButtonAdd": "Adicionar",
"addIntegrationButtonCancel": "Anular"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const FlavorsSelect = React.forwardRef<HTMLTableElement, FlavorsSelectProps>(
<Table
data-testid="flavor-select-table"
ref={ref}
className={cn('min-w-max w-full', className)}
className={cn('table-auto max-w-full overflow-x-auto', className)}
>
<TableHeader data-testid="flavor-select-table-header">
<TableRow className="bg-primary-100 hover:bg-primary-10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@ import { describe, it, vi } from 'vitest';
import OrderPrice from '@/components/order/price/OrderPrice.component';

describe('OrderPrice component', () => {
const mockedPrices = {
hourly: {
price: 1000500,
tax: 1005000,
},
monthly: {
price: 1000050000,
tax: 1000500000,
},
};
beforeEach(() => {
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, options: Record<string, string | number>): string => {
return `${key} ${options?.price}`;
},
}),
Trans: ({ children }: { children: React.ReactNode }) => children,
}));
vi.mock('@/hooks/api/catalog/useGetCatalog.hook', () => {
return {
useGetCatalog: vi.fn(() => ({
Expand All @@ -27,22 +45,20 @@ describe('OrderPrice component', () => {
});

it('should display Price component', async () => {
const mockedPrices = {
hourly: {
price: 10,
tax: 1,
},
monthly: {
price: 10,
tax: 1,
},
};

render(<OrderPrice showMonthly={false} prices={mockedPrices} />);
await waitFor(() => {
expect(screen.getByTestId('order-price-container')).toBeInTheDocument();
expect(screen.getByTestId('pricing-ht')).toBeInTheDocument();
expect(screen.getByTestId('pricing-ttc')).toBeInTheDocument();
});
});
it('should display Price component with montly values', async () => {
render(<OrderPrice showMonthly={true} prices={mockedPrices} />);
await waitFor(() => {
expect(screen.getByTestId('order-price-container')).toBeInTheDocument();
expect(screen.getByTestId('pricing-ht')).toBeInTheDocument();
expect(screen.getByText('pricing_ht 10,00 €')).toBeInTheDocument();
expect(screen.getByText('(pricing_ttc 20,01 €)')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { render, screen } from '@testing-library/react';
import { vi } from 'vitest';
import { UseQueryResult } from '@tanstack/react-query';
import Price from '@/components/price/Price.component';
import { useGetCatalog } from '@/hooks/api/catalog/useGetCatalog.hook';
import { order } from '@/types/catalog';

vi.mock('react-i18next', () => ({
useTranslation: () => ({
Expand Down Expand Up @@ -82,4 +85,22 @@ describe('Price component value', () => {
'(pricing_ttc 0,00 €)',
);
});

it('should display skeleton if catalog is fetching', () => {
vi.mocked(useGetCatalog).mockImplementation(() => {
return ({
isSuccess: false,
isLoading: true, // Simulate loading state
isError: false,
data: undefined,
error: null,
refetch: vi.fn(),
status: 'loading', // Provide status explicitly
} as unknown) as UseQueryResult<order.publicOrder.Catalog, Error>;
});
render(
<Price priceInUcents={1000000000} taxInUcents={200000000} decimals={2} />,
);
expect(screen.getByTestId('pricing-skeleton')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useNavigate } from 'react-router-dom';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
} from '../ui/dialog';
import { Skeleton } from '../ui/skeleton';

interface RouteModalProps {
backUrl?: string;
isLoading?: boolean;
children: React.ReactNode | React.ReactNode[];
}
const RouteModal = ({
backUrl = '../',
isLoading = false,
children,
}: RouteModalProps) => {
const navigate = useNavigate();
const onOpenChange = (open: boolean) => {
if (!open) navigate(backUrl);
};

return (
<Dialog defaultOpen onOpenChange={onOpenChange}>
{isLoading ? (
<DialogContent>
<DialogHeader>
<Skeleton className="w-3/5 h-5" />
</DialogHeader>
<DialogDescription className="flex flex-col gap-2">
<Skeleton className="w-4/5 h-4" />
<Skeleton className="w-100 h-4" />
<Skeleton className="w-2/3 h-4" />
<Skeleton className="w-4/5 h-4" />
<Skeleton className="w-1/3 h-4" />
<Skeleton className="w-4/5 h-4" />
</DialogDescription>
<DialogFooter className="flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 flex justify-end mt-2">
<Skeleton className="w-20 h-10" />
<Skeleton className="w-20 h-10" />
</DialogFooter>
</DialogContent>
) : (
children
)}
</Dialog>
);
};

export default RouteModal;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Skeleton({
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
<span
className={cn("animate-pulse rounded-md bg-muted", className)}
{...props}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import {
AddConnectionPool,
Expand All @@ -13,14 +13,26 @@ export interface UseAddConnectionPool {
}
export function useAddConnectionPool({
onError,
onSuccess,
onSuccess: customOnSuccess,
}: UseAddConnectionPool) {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: (cpInfo: AddConnectionPool) => {
return addConnectionPool(cpInfo);
},
onError,
onSuccess,
onSuccess: (data, variables) => {
queryClient.invalidateQueries({
queryKey: [
variables.projectId,
'database',
variables.engine,
variables.serviceId,
'connectionPool',
],
});
customOnSuccess(data);
},
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ describe('useAddConnectionPool', () => {
expect(databaseAPI.addConnectionPool).toHaveBeenCalledWith(
addConnectionPoolProps,
);
expect(onSuccess).toHaveBeenCalledWith(
mockedConnectionPool,
addConnectionPoolProps,
undefined,
);
expect(onSuccess).toHaveBeenCalledWith(mockedConnectionPool);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import {
DeleteConnectionPool,
deleteConnectionPool,
Expand All @@ -12,14 +12,26 @@ interface UseDeleteConnectionPool {

export function useDeleteConnectionPool({
onError,
onSuccess,
onSuccess: customOnSuccess,
}: UseDeleteConnectionPool) {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: (connectionPoolInfo: DeleteConnectionPool) => {
return deleteConnectionPool(connectionPoolInfo);
},
onError,
onSuccess,
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({
queryKey: [
variables.projectId,
'database',
variables.engine,
variables.serviceId,
'connectionPool',
],
});
customOnSuccess();
},
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ describe('useDeleteConnectionPool', () => {
expect(databaseAPI.deleteConnectionPool).toHaveBeenCalledWith(
deleteConnectionPoolProps,
);
expect(onSuccess).toHaveBeenCalledWith(
undefined,
deleteConnectionPoolProps,
undefined,
);
expect(onSuccess).toHaveBeenCalledWith();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import {
EditConnectionPool,
Expand All @@ -13,14 +13,26 @@ export interface UseEditConnectionPool {
}
export function useEditConnectionPool({
onError,
onSuccess,
onSuccess: customOnSuccess,
}: UseEditConnectionPool) {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: (cpInfo: EditConnectionPool) => {
return editConnectionPool(cpInfo);
},
onError,
onSuccess,
onSuccess: (data, variables) => {
queryClient.invalidateQueries({
queryKey: [
variables.projectId,
'database',
variables.engine,
variables.serviceId,
'connectionPool',
],
});
customOnSuccess(data);
},
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ describe('useEditConnectionPool', () => {
expect(databaseAPI.editConnectionPool).toHaveBeenCalledWith(
editConnectionPoolProps,
);
expect(onSuccess).toHaveBeenCalledWith(
mockedConnectionPool,
editConnectionPoolProps,
undefined,
);
expect(onSuccess).toHaveBeenCalledWith(mockedConnectionPool);
});
});
});
Loading

0 comments on commit 6b29873

Please sign in to comment.