11import React from 'react' ;
22
3+ import { fireEvent } from '@testing-library/react' ;
34import MockAdapter from 'axios-mock-adapter' ;
45
56import { getConfig } from '@edx/frontend-platform' ;
6- import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
77import { sendTrackEvent } from '@edx/frontend-platform/analytics' ;
8+ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
89
10+ import { getSessionStorage , setSessionStorage } from '../../../../../../data/sessionStorage' ;
911import {
1012 initializeMockApp , initializeTestStore , render , screen ,
1113} from '../../../../../../setupTest' ;
@@ -14,11 +16,19 @@ import { buildTopicsFromUnits } from '../../../../../data/__factories__/discussi
1416import { getCourseDiscussionTopics } from '../../../../../data/thunks' ;
1517import SidebarContext from '../../../SidebarContext' ;
1618import DiscussionsNotificationsSidebar from '../DiscussionsNotificationsSidebar' ;
19+ import DiscussionsNotificationsTrigger from '../DiscussionsNotificationsTrigger' ;
1720import DiscussionsWidget from './DiscussionsWidget' ;
1821
1922initializeMockApp ( ) ;
2023jest . mock ( '@edx/frontend-platform/analytics' ) ;
2124
25+ jest . mock ( '../../../../../../data/sessionStorage' , ( ) => ( {
26+ getSessionStorage : jest . fn ( ) ,
27+ setSessionStorage : jest . fn ( ) ,
28+ } ) ) ;
29+
30+ const onClickMock = jest . fn ( ) ;
31+
2232describe ( 'DiscussionsWidget' , ( ) => {
2333 let axiosMock ;
2434 let mockData ;
@@ -81,4 +91,34 @@ describe('DiscussionsWidget', () => {
8191 expect ( screen . queryByText ( 'Back to course' ) ) . toBeInTheDocument ( ) ;
8292 expect ( sendTrackEvent ) . toHaveBeenCalledTimes ( 1 ) ;
8393 } ) ;
94+
95+ it ( 'should open notification tray if closed' , ( ) => {
96+ ( getSessionStorage as jest . Mock ) . mockReturnValue ( 'closed' ) ;
97+
98+ renderWithProvider ( ( ) => < DiscussionsNotificationsTrigger onClick = { onClickMock } /> ) ;
99+
100+ const button = screen . getByRole ( 'button' ) ;
101+ fireEvent . click ( button ) ;
102+
103+ expect ( setSessionStorage ) . toHaveBeenCalledWith (
104+ `notificationTrayStatus.${ courseId } ` ,
105+ 'open' ,
106+ ) ;
107+ expect ( onClickMock ) . toHaveBeenCalled ( ) ;
108+ } ) ;
109+
110+ it ( 'should close notification tray if open' , ( ) => {
111+ ( getSessionStorage as jest . Mock ) . mockReturnValue ( 'open' ) ;
112+
113+ renderWithProvider ( ( ) => < DiscussionsNotificationsTrigger onClick = { onClickMock } /> ) ;
114+
115+ const button = screen . getByRole ( 'button' ) ;
116+ fireEvent . click ( button ) ;
117+
118+ expect ( setSessionStorage ) . toHaveBeenCalledWith (
119+ `notificationTrayStatus.${ courseId } ` ,
120+ 'open' ,
121+ ) ;
122+ expect ( onClickMock ) . toHaveBeenCalled ( ) ;
123+ } ) ;
84124} ) ;
0 commit comments