-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from CodeHive-Solutions/dev
Fix vacation response letter date bug
- Loading branch information
Showing
41 changed files
with
3,040 additions
and
2,623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
); | ||
}); | ||
}); |
Oops, something went wrong.