File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,6 @@ import { Badge, Icon } from '@openedx/paragon';
5
5
import { Settings as IconSettings } from '@openedx/paragon/icons' ;
6
6
import { capitalize } from 'lodash' ;
7
7
8
- import { NOTIFICATION_MESSAGES } from '../../constants' ;
9
-
10
8
const ProcessingNotification = ( { isShow, title } ) => (
11
9
< Badge
12
10
className = { classNames ( 'processing-notification' , {
@@ -24,7 +22,7 @@ const ProcessingNotification = ({ isShow, title }) => (
24
22
25
23
ProcessingNotification . propTypes = {
26
24
isShow : PropTypes . bool . isRequired ,
27
- title : PropTypes . oneOf ( Object . values ( NOTIFICATION_MESSAGES ) ) . isRequired ,
25
+ title : PropTypes . string . isRequired ,
28
26
} ;
29
27
30
28
export default ProcessingNotification ;
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ describe('<ToastProvider />', () => {
50
50
} ,
51
51
} ) ;
52
52
store = initializeStore ( ) ;
53
+ jest . useFakeTimers ( ) ;
53
54
} ) ;
54
55
55
56
afterEach ( ( ) => {
@@ -61,6 +62,13 @@ describe('<ToastProvider />', () => {
61
62
expect ( await screen . findByText ( 'This is the toast!' ) ) . toBeInTheDocument ( ) ;
62
63
} ) ;
63
64
65
+ it ( 'should close toast after 5000ms' , async ( ) => {
66
+ render ( < RootWrapper > < TestComponentToShow /> </ RootWrapper > ) ;
67
+ expect ( await screen . findByText ( 'This is the toast!' ) ) . toBeInTheDocument ( ) ;
68
+ jest . advanceTimersByTime ( 6000 ) ;
69
+ expect ( screen . queryByText ( 'This is the toast!' ) ) . not . toBeInTheDocument ( ) ;
70
+ } ) ;
71
+
64
72
it ( 'should close toast' , async ( ) => {
65
73
render ( < RootWrapper > < TestComponentToClose /> </ RootWrapper > ) ;
66
74
expect ( await screen . findByText ( 'Content' ) ) . toBeInTheDocument ( ) ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
- import { Toast } from '@openedx/paragon' ;
2
+
3
+ import ProcessingNotification from '../processing-notification' ;
3
4
4
5
export interface ToastContextData {
5
6
toastMessage : string | null ;
@@ -35,7 +36,13 @@ export const ToastProvider = (props: ToastProviderProps) => {
35
36
setToastMessage ( null ) ;
36
37
} , [ ] ) ;
37
38
38
- const showToast = React . useCallback ( ( message ) => setToastMessage ( message ) , [ setToastMessage ] ) ;
39
+ const showToast = React . useCallback ( ( message ) => {
40
+ setToastMessage ( message ) ;
41
+ // Close the toast after 5 seconds
42
+ setTimeout ( ( ) => {
43
+ setToastMessage ( null ) ;
44
+ } , 5000 ) ;
45
+ } , [ setToastMessage ] ) ;
39
46
const closeToast = React . useCallback ( ( ) => setToastMessage ( null ) , [ setToastMessage ] ) ;
40
47
41
48
const context = React . useMemo ( ( ) => ( {
@@ -48,9 +55,7 @@ export const ToastProvider = (props: ToastProviderProps) => {
48
55
< ToastContext . Provider value = { context } >
49
56
{ props . children }
50
57
{ toastMessage && (
51
- < Toast show = { toastMessage !== null } onClose = { closeToast } >
52
- { toastMessage }
53
- </ Toast >
58
+ < ProcessingNotification isShow = { toastMessage !== null } title = { toastMessage } />
54
59
) }
55
60
</ ToastContext . Provider >
56
61
) ;
You can’t perform that action at this time.
0 commit comments