Skip to content

Commit

Permalink
fix: [P4PU-848] update routing and error handling in PreLoginLayout (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoivandiluccio authored Feb 19, 2025
1 parent 5094293 commit 7707469
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 37 deletions.
73 changes: 46 additions & 27 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Navigate, RouterProvider, createBrowserRouter, useRouteError } from 'react-router-dom';
import { Theme } from './utils/style';
import { Layout } from './components/Layout';
import { ArcRoutes } from './routes/routes';
import { ArcErrors, ArcRoutes } from './routes/routes';
import TransactionRoute from './routes/Transaction';
import DashboardRoute from './routes/Dashboard';
import { theme } from '@pagopa/mui-italia';
Expand Down Expand Up @@ -36,15 +36,6 @@ const router = createBrowserRouter([
throw useRouteError();
}
},
{
path: ArcRoutes.COURTESY_PAGE,
loader: ({ params }) => Promise.resolve(params.error),
element: (
<PreLoginLayout>
<CourtesyPage />
</PreLoginLayout>
)
},
{
path: ArcRoutes.LOGIN,
element: (
Expand All @@ -53,27 +44,37 @@ const router = createBrowserRouter([
</PreLoginLayout>
)
},
{
path: ArcRoutes.TOS,
element: (
<PreLoginLayout>
<Resources resource="tos" />
</PreLoginLayout>
)
},
{
path: ArcRoutes.PRIVACY_POLICY,
element: (
<PreLoginLayout>
<Resources resource="pp" />
</PreLoginLayout>
)
},
{
path: ArcRoutes.AUTH_CALLBACK,
element: <AuthCallback />,
loader: ({ request }) => getTokenOneidentity(request)
},
{
path: ArcRoutes.COURTESY_PAGE.replace(':error', ''),
element: <PreLoginLayout />,
children: [
{
path: ArcErrors['401'],
loader: () => ArcErrors['401'],
element: <CourtesyPage />
},
{
path: ArcErrors['403'],
loader: () => ArcErrors['403'],
element: <CourtesyPage />
},
{
path: ArcErrors['404'],
loader: () => ArcErrors['404'],
element: <CourtesyPage />
},
{
path: ArcErrors['408'],
loader: () => ArcErrors['408'],
element: <CourtesyPage />
}
]
},
{
path: ArcRoutes.DASHBOARD,
element: (
Expand Down Expand Up @@ -171,7 +172,25 @@ const router = createBrowserRouter([
}
}
]
: [])
: []),
{
path: ArcRoutes.TOS,
element: <Resources resource="tos" />
},
{
path: ArcRoutes.PRIVACY_POLICY,
element: <Resources resource="pp" />
},
{
path: ArcRoutes.COURTESY_PAGE,
loader: ({ params }) => Promise.resolve(params.error),
element: <CourtesyPage />,
handle: {
sidebar: {
visibile: false
}
}
}
]
}
]
Expand Down
7 changes: 6 additions & 1 deletion src/components/AssistanceForm/AssistanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ export const AssistanceForm = () => {
<Trans
i18nKey={t('app.assistance.privacy')}
components={{
link1: <Link href="#" fontWeight={800} />
link1: (
<Link
href="https://www.pagopa.it/it/privacy-policy-assistenza/"
fontWeight={800}
/>
)
}}
/>
</Typography>
Expand Down
42 changes: 35 additions & 7 deletions src/components/Cart/CartDrawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ vi.mock(import('store/CartStore'), async (importOriginal) => {
};
});

const mockUseStore = vi.hoisted(() => vi.fn());
vi.mock('store/GlobalStore', () => {
return {
useStore: () => ({
state: {
cart: {
items: []
}
}
})
useStore: mockUseStore
};
});

Expand All @@ -40,6 +35,14 @@ describe('CartDrawer', () => {
});

it('renders the cart drawer when empty', () => {
mockUseStore.mockReturnValue({
state: {
cart: {
items: []
}
}
});

render(
<QueryClientProvider client={queryClient}>
<CartDrawer />
Expand Down Expand Up @@ -77,4 +80,29 @@ describe('CartDrawer', () => {
expect(toggleCartDrawer).toHaveBeenCalled();
expect(mockNavigate).toHaveBeenCalledWith(ArcRoutes.PAYMENT_NOTICES);
});

it('allow the click on pay button when the cart is not empty', () => {
mockUseStore.mockReturnValue({
state: {
cart: {
items: [
{
amount: 100,
iuv: 'iuvTest',
paFullName: 'paFullNameTest',
description: 'descriptionTest'
}
]
}
}
});

render(
<QueryClientProvider client={queryClient}>
<CartDrawer />
</QueryClientProvider>
);
const payButton = screen.getByText('app.cart.items.pay');
fireEvent.click(payButton);
});
});
1 change: 1 addition & 0 deletions src/components/Cart/CartDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const CartDrawer = () => {

const onPayButton = () => {
carts.mutate({ notices: cart.items, email });
toggleCartDrawer();
};

return (
Expand Down
5 changes: 3 additions & 2 deletions src/components/PreLoginLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import utils from 'utils';
import { HeaderAccount } from '@pagopa/mui-italia';
import { ReactJSXElement } from '@emotion/react/types/jsx-namespace';
import { Footer } from './Footer';
import { Outlet } from 'react-router-dom';

export function PreLoginLayout({ children }: { children: ReactJSXElement }) {
export function PreLoginLayout({ children }: { children?: ReactJSXElement }) {
const ASSISTANCE_MAIL = utils.config.assistanceLink;
const onAssistanceClick = () => {
window.open(`mailto:${ASSISTANCE_MAIL}`);
Expand Down Expand Up @@ -44,7 +45,7 @@ export function PreLoginLayout({ children }: { children: ReactJSXElement }) {
alignItems={'center'}
justifyContent={'center'}
width={'100%'}>
{children}
{children || <Outlet />}
</Grid>
<Grid
item
Expand Down

0 comments on commit 7707469

Please sign in to comment.