diff --git a/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx b/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx index 6ee8efe3a0e2..4c1b2980a87e 100644 --- a/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx +++ b/projects/plugins/jetpack/_inc/client/components/global-notices/index.jsx @@ -69,10 +69,10 @@ class NoticesList extends Component { //and from the old component. When all notices are moved to redux store, this component //needs to be updated. noticesList = noticesList.concat( - this.props.storeNotices.map( function ( notice, index ) { + this.props.storeNotices.map( function ( notice ) { return ( , { store } ); + return store; +} + +describe( 'NoticesList', () => { + beforeEach( () => { + jest.useFakeTimers(); + } ); + + afterEach( () => { + jest.useRealTimers(); + } ); + + it( 'dismisses a notice that replaced an earlier one under the same id', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); + store.dispatch( createNotice( 'is-info', 'Activating Image CDN…', { id: 'module-toggle' } ) ); + } ); + expect( screen.getByText( 'Activating Image CDN…' ) ).toBeInTheDocument(); + + act( () => { + store.dispatch( removeNotice( 'module-toggle' ) ); + store.dispatch( + createNotice( 'is-success', 'Image CDN has been activated.', { + id: 'module-toggle', + duration: 2000, + } ) + ); + } ); + expect( screen.getByText( 'Image CDN has been activated.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Image CDN has been activated.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); + } ); + + it( 'dismisses a notice that replaced an earlier one under a different id', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); + store.dispatch( createNotice( 'is-info', 'Updating settings…', { id: 'setting-update' } ) ); + } ); + + act( () => { + store.dispatch( removeNotice( 'setting-update' ) ); + store.dispatch( + createNotice( 'is-success', 'Updated settings.', { + id: 'setting-update-success', + duration: 2000, + } ) + ); + } ); + expect( screen.getByText( 'Updated settings.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Updated settings.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); + } ); + + it( 'dismisses a notice added while another one is already on screen', () => { + const store = mountNotices(); + + act( () => { + store.dispatch( createNotice( 'is-info', 'Testing your connection…', { id: 'connection' } ) ); + } ); + + act( () => { + store.dispatch( + createNotice( 'is-success', 'Site is verified.', { id: 'verify', duration: 2000 } ) + ); + } ); + expect( screen.getByText( 'Site is verified.' ) ).toBeInTheDocument(); + + act( () => { + jest.advanceTimersByTime( 2000 ); + } ); + expect( screen.queryByText( 'Site is verified.' ) ).not.toBeInTheDocument(); + expect( screen.getByText( 'Testing your connection…' ) ).toBeInTheDocument(); + } ); +} ); diff --git a/projects/plugins/jetpack/_inc/client/security/allowList.jsx b/projects/plugins/jetpack/_inc/client/security/allowList.jsx index 2681ebcc3aaa..3af6dd15e2b0 100644 --- a/projects/plugins/jetpack/_inc/client/security/allowList.jsx +++ b/projects/plugins/jetpack/_inc/client/security/allowList.jsx @@ -59,6 +59,7 @@ const AllowList = class extends Component { this.props.removeNotice( 'module-setting-update' ); this.props.createNotice( 'is-success', __( 'Updated Settings.', 'jetpack' ), { id: 'module-setting-update-success', + duration: 2000, } ); } ) .catch( error => { diff --git a/projects/plugins/jetpack/_inc/client/security/waf.jsx b/projects/plugins/jetpack/_inc/client/security/waf.jsx index 2c73cbb4907d..a8f79f7f77f3 100644 --- a/projects/plugins/jetpack/_inc/client/security/waf.jsx +++ b/projects/plugins/jetpack/_inc/client/security/waf.jsx @@ -111,6 +111,7 @@ export const Waf = class extends Component { this.props.removeNotice( 'module-setting-update' ); this.props.createNotice( 'is-success', __( 'Updated Settings.', 'jetpack' ), { id: 'module-setting-update-success', + duration: 2000, } ); } ) .catch( error => { diff --git a/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss new file mode 100644 index 000000000000..fb4c6b0b6af6 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-toast-auto-dismiss @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Settings: Dismiss success notices automatically instead of leaving them on screen.