-
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.
Refactor Snackbar handling by removing SnackbarAlert component, intro…
…ducing SnackbarContext and ProgressbarContext for improved state management, and updating the modules and components to utilize these new context.
- Loading branch information
Showing
20 changed files
with
369 additions
and
588 deletions.
There are no files selected for viewing
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 } | ||
); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.