Skip to content

Commit

Permalink
Merge pull request #139 from CodeHive-Solutions/dev
Browse files Browse the repository at this point in the history
Fix vacation response letter date bug
  • Loading branch information
S-e-b-a-s authored Nov 7, 2024
2 parents 29f3030 + 1d7bd96 commit 4966149
Show file tree
Hide file tree
Showing 41 changed files with 3,040 additions and 2,623 deletions.
15 changes: 12 additions & 3 deletions INSIGHTSAPI/vacation/templates/vacation_response.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,18 @@

<div class="header">
<p>
Bogotá D.C.; {% if vacation.payroll_approved_at %} {{ vacation.payroll_approved_at|date:"d \d\e F \d\e Y" }} {% elif vacation.hr_approved_at %}
{{vacation.hr_approved_at|date:"d \d\e F \d\e Y" }} {% elif vacation.manager_approved_at %} {{vacation.manager_approved_at|date:"d \d\e F \d\e Y" }} {% elif
vacation.boss_approved_at %} {{ vacation.boss_approved_at|date:"d \d\e F \d\e Y" }} {% else %} No approval date available {% endif %}
Bogotá D.C.;
{% if vacation.payroll_approved_at %}
{{ vacation.payroll_approved_at|date:"d \\d\\e F \\d\\e Y" }}
{% elif vacation.hr_approved_at %}
{{ vacation.hr_approved_at|date:"d \\d\\e F \\d\\e Y" }}
{% elif vacation.manager_approved_at %}
{{ vacation.manager_approved_at|date:"d \\d\\e F \\d\\e Y" }}
{% elif vacation.boss_approved_at %}
{{ vacation.boss_approved_at|date:"d \\d\\e F \\d\\e Y" }}
{% else %}
No approval date available
{% endif %}
</p>
</div>

Expand Down
48 changes: 25 additions & 23 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^5.16.7",
"@mui/lab": "5.0.0-alpha.173",
"@mui/material": "^5.16.7",
"@mui/x-data-grid": "^7.16.0",
"@sentry/react": "^8.30.0",
"@sentry/vite-plugin": "^2.22.4",
"cally": "^0.7.1",
"@mui/icons-material": "^6.1.6",
"@mui/lab": "6.0.0-beta.14",
"@mui/material": "^6.1.6",
"@mui/x-data-grid": "^7.22.1",
"@sentry/react": "^8.37.1",
"@sentry/vite-plugin": "^2.22.6",
"cally": "^0.7.2",
"clsx": "^2.1.1",
"depcheck": "^1.4.7",
"embla-carousel-autoplay": "^8.2.1",
"embla-carousel-class-names": "^8.2.1",
"embla-carousel-fade": "^8.2.1",
"embla-carousel-react": "^8.2.1",
"filepond": "^4.31.3",
"embla-carousel-autoplay": "^8.3.1",
"embla-carousel-class-names": "^8.3.1",
"embla-carousel-fade": "^8.3.1",
"embla-carousel-react": "^8.3.1",
"filepond": "^4.32.1",
"filepond-plugin-file-validate-type": "^1.2.9",
"filepond-plugin-image-exif-orientation": "^1.0.11",
"filepond-plugin-image-preview": "^4.6.12",
Expand All @@ -35,28 +36,29 @@
"node-fetch": "^3.3.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-dropzone": "^14.2.3",
"react-dropzone": "^14.3.5",
"react-filepond": "^7.1.2",
"react-material-ui-carousel": "^3.4.2",
"react-router-dom": "^6.26.2",
"react-router-dom": "^6.27.0",
"rollup-plugin-visualizer": "^5.12.0",
"sonner": "^1.7.0",
"swiper": "^11.1.14",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
"yup": "^1.4.0"
},
"devDependencies": {
"@babel/eslint-parser": "^7.25.1",
"@testing-library/jest-dom": "^6.5.0",
"@babel/eslint-parser": "^7.25.9",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/react": "^18.3.5",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/ui": "^2.1.1",
"jsdom": "^25.0.0",
"oxlint": "^0.9.5",
"@types/react": "^18.3.12",
"@vitejs/plugin-react": "^4.3.3",
"@vitest/ui": "^2.1.4",
"jsdom": "^25.0.1",
"oxlint": "^0.11.0",
"prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.12.0",
"vite": "^5.4.4",
"vitest": "^2.1.0"
"vite": "^5.4.10",
"vitest": "^2.1.4"
}
}
1,886 changes: 920 additions & 966 deletions frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions frontend/src/__test__/AddImagesCarouselDialog.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ vi.mock('react-filepond', () => {
registerPlugin: vi.fn(),
};
});
vi.spyOn(console, 'warn');

describe('AddImagesCarouselDialog Component', () => {
const mockSetOpenAddDialog = vi.fn();
Expand Down Expand Up @@ -61,28 +62,31 @@ describe('AddImagesCarouselDialog Component', () => {
render(<AddImagesCarouselDialog {...defaultProps} />);

// Simulate opening the dropdown (for "position" field)
const positionInput = screen.getByLabelText(/Posición/i);
const positionInput = screen.getByDisplayValue('1');
const positionBox = screen.getByLabelText(/Posición/i);

fireEvent.mouseDown(positionInput); // Open the dropdown
// console.log(positionInput);

fireEvent.mouseDown(positionBox); // Open the dropdown

// Find the dropdown list within the document
const listbox = within(screen.getByRole('listbox'));
const listbox = within(screen.getByRole('listbox', { hidden: true }));

// Select the first option (e.g., value "1")
const firstOption = listbox.getByText('1');

fireEvent.click(firstOption);

// Now, simulate a change event to ensure the value is set
fireEvent.change(positionInput, { target: { value: '1' } });

// Now, add the file using the mocked FilePond input
const fileInput = screen.getByTestId('filepond-input');
const file = new File(['dummy content'], 'example.png', {
type: 'image/png',
});
fireEvent.change(fileInput, { target: { files: [file] } });

// Add a console log to inspect the form elements
const form = screen.getByRole('form');
console.log(form);
fireEvent.change(fileInput, { target: { files: [file] } });

// Submit the form
const submitButton = screen.getByText('Actualizar');
Expand Down
150 changes: 150 additions & 0 deletions frontend/src/__test__/CoexistenceCommittee.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import CoexistenceCommittee from '../components/pages/CoexistenceCommittee';
import { SnackbarProvider } from '../components/context/SnackbarContext';
import { ProgressbarProvider } from '../components/context/ProgressbarContext';

// Mock the fetch function and the custom hooks
global.fetch = vi.fn(() =>
Promise.resolve({
status: 201,
json: () => Promise.resolve({}),
})
);

const mockShowSnack = vi.fn();
const mockShowProgressbar = vi.fn();
const mockHideProgressbar = vi.fn();

vi.mock('../components/context/SnackbarContext', () => ({
useSnackbar: () => ({ showSnack: mockShowSnack }),
}));

vi.mock('../components/context/ProgressbarContext', () => ({
useProgressbar: () => ({
isProgressVisible: false,
showProgressbar: mockShowProgressbar,
hideProgressbar: mockHideProgressbar,
}),
}));

describe('CoexistenceCommittee component', () => {
it('renders the form correctly', () => {
render(
<SnackbarProvider>
<ProgressbarProvider>
<CoexistenceCommittee />
</ProgressbarProvider>
</SnackbarProvider>
);

// Check if the form fields are rendered
expect(screen.getByLabelText('Motivo')).toBeInTheDocument();
expect(
screen.getByLabelText('Deja tu mensaje aquí')
).toBeInTheDocument();
expect(
screen.getByRole('button', { name: /Enviar/i })
).toBeInTheDocument();
});

it('displays validation errors when fields are empty', async () => {
render(
<SnackbarProvider>
<ProgressbarProvider>
<CoexistenceCommittee />
</ProgressbarProvider>
</SnackbarProvider>
);

const submitButton = screen.getByRole('button', { name: /Enviar/i });

// Click submit without filling the form
fireEvent.click(submitButton);

// Wait for validation errors to appear
await waitFor(() => {
const errors = screen.getAllByText('Campo requerido');
expect(errors).toHaveLength(2);
});
});

it('submits the form correctly when fields are filled', async () => {
render(
<SnackbarProvider>
<ProgressbarProvider>
<CoexistenceCommittee />
</ProgressbarProvider>
</SnackbarProvider>
);

const [motivoInput] = screen.getAllByRole('textbox');
// Fill out the form
fireEvent.change(motivoInput, {
target: { value: 'Acoso laboral' },
});
fireEvent.change(screen.getByLabelText('Deja tu mensaje aquí'), {
target: { value: 'Test description' },
});

const submitButton = screen.getByRole('button', { name: /Enviar/i });

// Submit the form
fireEvent.click(submitButton);

// Wait for form submission and expect a success message
await waitFor(() => {
expect(mockShowSnack).toHaveBeenCalledWith(
'success',
'Mensaje enviado correctamente'
);
});

expect(mockShowProgressbar).toHaveBeenCalled();
expect(mockHideProgressbar).toHaveBeenCalled();
});

it('handles submission error correctly', async () => {
// Mock fetch to return an error response
global.fetch = vi.fn(() =>
Promise.resolve({
status: 400,
json: () => Promise.resolve({ message: 'Error message' }),
})
);

render(
<SnackbarProvider>
<ProgressbarProvider>
<CoexistenceCommittee />
</ProgressbarProvider>
</SnackbarProvider>
);

const [motivoInput] = screen.getAllByRole('textbox');
// Fill out the form
fireEvent.change(motivoInput, {
target: { value: 'Acoso laboral' },
});

fireEvent.change(screen.getByLabelText('Deja tu mensaje aquí'), {
target: { value: 'Test description' },
});

const submitButton = screen.getByRole('button', { name: /Enviar/i });

// Submit the form
fireEvent.click(submitButton);

// Wait for error handling
await waitFor(() => {
expect(mockShowSnack).toHaveBeenCalledWith(
'error',
'Error message'
);
});

expect(mockShowProgressbar).toHaveBeenCalled();
expect(mockHideProgressbar).toHaveBeenCalled();
});
});
49 changes: 0 additions & 49 deletions frontend/src/__test__/SnackBarAlert.test.jsx

This file was deleted.

47 changes: 47 additions & 0 deletions frontend/src/__test__/SnackbarContext.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import {
SnackbarProvider,
useSnackbar,
} from '../components/context/SnackbarContext';
import '@testing-library/jest-dom';

// Test component to use the Snackbar context
const TestComponent = () => {
const { showSnack } = useSnackbar();

return (
<button onClick={() => showSnack('success', 'Test message')}>
Show Snackbar
</button>
);
};

describe('SnackbarContext', () => {
it('should show and hide the snackbar with the correct message and severity', async () => {
render(
<SnackbarProvider>
<TestComponent />
</SnackbarProvider>
);

// Click the button to show the snackbar
fireEvent.click(screen.getByText('Show Snackbar'));

// Check if the snackbar is displayed with the correct message and severity
expect(await screen.findByText('Test message')).toBeInTheDocument();
expect(screen.getByRole('alert')).toHaveClass(
'MuiAlert-standardSuccess'
);

// Wait for the snackbar to auto-hide
await waitFor(
() => {
expect(
screen.queryByText('Test message')
).not.toBeInTheDocument();
},
{ timeout: 4000 }
);
});
});
Loading

0 comments on commit 4966149

Please sign in to comment.