Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/P4ADEV-1958--…
Browse files Browse the repository at this point in the history
…reporting-payment-detail
  • Loading branch information
abilello1 committed Feb 6, 2025
2 parents 43e8988 + 98d6f4e commit 7780c84
Show file tree
Hide file tree
Showing 34 changed files with 939 additions and 612 deletions.
63 changes: 37 additions & 26 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ import TelematicReceiptSearchResults from './routes/TelematicReceiptSearchResult
import TelematicReceipt from './routes/TelematicReceipt';
import TelematicReceiptDetail from './routes/TelematicReceiptDetail';
import TelematicReceiptExportFlowThankYouPage from './routes/TelematicReceiptExportFlowThankYouPage';
import TelematicReceiptFlowImport from './routes/TelematicReceiptFlowImport';
import TelematicReceiptFlowImportThankYouPage from './routes/TelematicReceiptFlowImportThankYouPage';
import TelematicReceiptImportFlowOverview from './routes/TelematicReceiptImportFlowOverview';
import ReportingSearchResults from './routes/ReportingSearchResults';
import Reporting from './routes/Reporting';
import ReportingImportFlowOverview from './routes/ReportingImportFlowOverview';
import ReportingFlowImport from './routes/ReportingFlowImport';
import ReportingFlowImportThankYouPage from './routes/ReportingFlowImportThankYouPage';
import Treasury from './routes/Treasury';
import ReportingDetail from './routes/ReportingDetail';
import ReportingPaymentDetail from './routes/ReportingPaymentDetail';
import Treasury from './routes/Treasury';
import TreasuryImportFlowOverview from './routes/TreasuryImportFlowOverview';
import ImportFlow from './routes/ImportFlowPage';

import { Overlay } from './components/Overlay';
import { useStore } from './store/GlobalStore';


const router = createBrowserRouter([
{
element: <ApiClient client={utils.apiClient} />,
Expand Down Expand Up @@ -154,16 +153,6 @@ const router = createBrowserRouter([
backButton: true,
} as RouteHandleObject,
},
{
path: PageRoutesConf.TELEMATIC_RECEIPT.children?.IMPORT_FLOW.path,
element: <TelematicReceiptFlowImport />,
handle: {
backButton: true,
sidebar: {
visibile: false
},
} as RouteHandleObject,
},
{
path: PageRoutesConf.TELEMATIC_RECEIPT.children?.IMPORT_FLOW_THANK_YOU_PAGE.path,
element: <TelematicReceiptFlowImportThankYouPage />,
Expand Down Expand Up @@ -240,16 +229,6 @@ const router = createBrowserRouter([
backButton: true
} as RouteHandleObject,
},
{
path: PageRoutesConf.REPORTING.children?.IMPORT_FLOW.path,
element: <ReportingFlowImport />,
handle: {
backButton: true,
sidebar: {
visibile: false
},
} as RouteHandleObject,
},
{
path: PageRoutesConf.REPORTING.children?.IMPORT_FLOW_THANK_YOU_PAGE.path,
element: <ReportingFlowImportThankYouPage />,
Expand Down Expand Up @@ -290,15 +269,47 @@ const router = createBrowserRouter([
},
backButton: false
} as RouteHandleObject,
/* -- TREASURY SECTION CHILDREN ROUTES -- */
children: [
{
index: true,
element: <Treasury />,
},
{
path: PageRoutesConf.TREASURY.children?.IMPORT_OVERVIEW.path,
element: <TreasuryImportFlowOverview />,
handle: {
crumbs: {
elements: [
{ name: 'FLOWS', fontWeight: 600, color: theme.palette.text.primary },
{ name: 'TREASURY', color: theme.palette.text.primary },
{ name: 'TREASURY_IMPORT_OVERVIEW', color: theme.palette.text.disabled}
]
},
backButton: true
} as RouteHandleObject,
},
]
},
/* -- END - TREASURY SECTION -- */
/* -- IMPORT SECTION -- */
{
path: PageRoutesConf.IMPORT.path,
element: <Layout />,
handle: {
backButton: true,
sidebar: {
visible: false
}
} as RouteHandleObject,
children: [
{
path: PageRoutesConf.IMPORT.children?.FLOWS.path,
element: <ImportFlow />,
}
]
}
/* -- TREASURY SECTION CHILDREN ROUTES -- */
/* -- END - TREASURY SECTION -- */
/* -- END - IMPORT SECTION -- */
]
}
]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/FileUploader/FileUploader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('FileUploader Component', () => {
file: null,
setFile: mockSetFile,
description: 'Drag and drop or upload a file',
requiredFieldText: 'This field is required',
requiredFileText: 'This field is required',
fileExtensionsAllowed: ['zip'],
};

Expand All @@ -40,7 +40,7 @@ describe('FileUploader Component', () => {

expect(screen.getByText('commons.files.file')).toBeDefined();
expect(screen.getByText(defaultProps.description)).toBeDefined();
expect(screen.getByText(defaultProps.requiredFieldText)).toBeDefined();
expect(screen.getByText(defaultProps.requiredFileText)).toBeDefined();
expect(screen.getByTestId('drop-zone')).toBeDefined();
expect(screen.getByText('commons.files.upload')).toBeDefined();
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/FileUploader/FileUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type FileUploaderProps = {
file: File | null;
setFile: React.Dispatch<React.SetStateAction<File | null>>;
description: string;
requiredFieldText: string;
requiredFileText: string;
fileExtensionsAllowed: string[];
};

Expand All @@ -34,7 +34,7 @@ const FileUploader = ({
file,
setFile,
description,
requiredFieldText,
requiredFileText,
fileExtensionsAllowed,
}: FileUploaderProps) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -178,7 +178,7 @@ const FileUploader = ({
</Button>
</Box>
<Typography variant="body2" mt={2} color="textSecondary">
{requiredFieldText}
{requiredFileText}
</Typography>
</>
)}
Expand Down
14 changes: 10 additions & 4 deletions src/components/FilterContainer/FilterContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Button, FormControl, Grid, InputAdornment, InputLabel, MenuItem, Select, TextField, useTheme } from '@mui/material';
import React, { useState } from 'react';
import { Button, FormControl, Grid, InputAdornment, InputLabel, MenuItem, Select, SelectChangeEvent, TextField, useTheme } from '@mui/material';

export enum COMPONENT_TYPE{
textField,
Expand All @@ -23,6 +23,12 @@ type FilterContainerProps = {
const FilterContainer = ({ items }: FilterContainerProps) => {
const theme = useTheme();

const [selectValue, setSelectValue] = useState('');

const handleChange = (event: SelectChangeEvent<string>) => {
setSelectValue(event.target.value);
};

return (
<>
{items.map((item, index) => {
Expand Down Expand Up @@ -54,8 +60,8 @@ const FilterContainer = ({ items }: FilterContainerProps) => {
<Select
sx={{ bgcolor: theme.palette.common.white }}
label={item.label}
onChange={function noRefCheck() {}}
value=""
onChange={handleChange}
value={selectValue}
>
{item.options?.map((option, optionIndex) => (
<MenuItem key={`${item.label}-${option.value}-${optionIndex}`} value={option.value}>
Expand Down
114 changes: 114 additions & 0 deletions src/components/ImportFlowPage/ImportFlowPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { describe, it, vi, expect, beforeEach } from 'vitest';
import { fireEvent, render, screen, within } from '@testing-library/react';
import ImportFlow from './ImportFlowPage';
import { useParams } from 'react-router-dom';

vi.mock('react-router-dom', () => ({
useNavigate: vi.fn(),
useParams: vi.fn(),
}));

describe('ImportFlow', () => {
const mockUseParams = vi.mocked(useParams);

beforeEach(() => {
vi.clearAllMocks();
});

describe('no select Config', () => {
beforeEach(() => {
mockUseParams.mockReturnValue({ category: 'reporting' });
});

it('renders without select', () => {
render(<ImportFlow/>);

expect(screen.getByText('commons.routes.REPORTING_IMPORT_FLOW')).toBeDefined();
expect(screen.getByText('commons.flowImport.description')).toBeDefined();
expect(screen.getByText('commons.flowImport.boxTitle')).toBeDefined();
expect(screen.getByText('commons.flowImport.boxDescription')).toBeDefined();
expect(screen.getByText('commons.flowImport.manualLink')).toBeDefined();
expect(screen.queryByText('commons.requiredFieldDescription')).toBeNull();
expect(screen.queryByLabelText('commons.flowType')).toBeNull();
});

it('should enable button when a file is uploaded', async () => {

render(<ImportFlow />);

const file = new File(['content'], 'test.zip', { type: 'application/zip' });
const dropZone = screen.getByTestId('drop-zone');

fireEvent.dragOver(dropZone);
fireEvent.drop(dropZone, {
dataTransfer: {
files: [file]
}
});

await vi.waitFor(() => expect(screen.getAllByText('test.zip')).toBeDefined());
const successButton = screen.getByTestId('success-button');

expect(successButton).toHaveProperty('disabled', false);
});
});

describe('select config', () => {
beforeEach(() => {
mockUseParams.mockReturnValue({ category: 'treasury' });
});

it('renders with select', () => {
render(<ImportFlow />);

expect(screen.getByText('commons.routes.TREASURY_IMPORT_FLOW')).toBeDefined();
expect(screen.getByText('commons.requiredFieldDescription')).toBeDefined();
expect(screen.getByRole('select-flowType')).toBeDefined();
expect(screen.getByTestId('success-button')).toHaveProperty('disabled', true);
});

it('should show all flow type options when select is clicked', () => {
render(<ImportFlow />);

const selectCombo = screen.getByRole('combobox', { name: 'commons.flowType' });
fireEvent.mouseDown(selectCombo);

const listbox = within(screen.getByRole('listbox'));

const options = [
'Giornale di Cassa XLS',
'Giornale di Cassa CSV',
'Giornale di Cassa OPI',
'Estrato conto poste'
];

options.forEach(option => {
expect(listbox.getByText(option)).toBeDefined();
});
});
it('should enable button when a file is uploaded and a flow type is selected', async () => {

render(<ImportFlow />);

const file = new File(['content'], 'test.zip', { type: 'application/zip' });
const dropZone = screen.getByTestId('drop-zone');

fireEvent.dragOver(dropZone);
fireEvent.drop(dropZone, {
dataTransfer: {
files: [file]
}
});

await vi.waitFor(() => expect(screen.getAllByText('test.zip')).toBeDefined());

const selectCombo = screen.getByRole('combobox', { name: 'commons.flowType' });
fireEvent.mouseDown(selectCombo);

const firstOption = within(screen.getByRole('listbox')).getAllByRole('option')[0];
fireEvent.click(firstOption);

expect(screen.getByTestId('success-button')).toHaveProperty('disabled', false);
});
});
});
Loading

0 comments on commit 7780c84

Please sign in to comment.