@@ -8,6 +8,7 @@ import { sendTrackEvent, sendTrackingLogEvent } from '@edx/frontend-platform/ana
8
8
import { initializeMockApp , initializeTestStore } from '@src/setupTest' ;
9
9
import SidebarContext from '../../../SidebarContext' ;
10
10
import SidebarUnit from './SidebarUnit' ;
11
+ import { ID } from '../constants' ;
11
12
12
13
jest . mock ( '@edx/frontend-platform/analytics' , ( ) => ( {
13
14
sendTrackEvent : jest . fn ( ) ,
@@ -20,7 +21,7 @@ describe('<SidebarUnit />', () => {
20
21
let store = { } ;
21
22
let unit ;
22
23
let sequenceId ;
23
- let mockData ;
24
+ let defaultSidebarContext ;
24
25
25
26
const initTestStore = async ( options ) => {
26
27
store = await initializeTestStore ( options ) ;
@@ -29,16 +30,17 @@ describe('<SidebarUnit />', () => {
29
30
const sequence = state . courseware . courseOutline . sequences [ sequenceId ] ;
30
31
unit = state . courseware . courseOutline . units [ sequence . unitIds [ 0 ] ] ;
31
32
32
- mockData = {
33
+ defaultSidebarContext = {
33
34
toggleSidebar : jest . fn ( ) ,
35
+ currentSidebar : ID ,
34
36
} ;
35
37
} ;
36
38
37
- function renderWithProvider ( props = { } ) {
39
+ function renderWithProvider ( props = { } , sidebarContext = defaultSidebarContext ) {
38
40
const { container } = render (
39
41
< AppProvider store = { store } wrapWithRouter = { false } >
40
42
< IntlProvider locale = "en" >
41
- < SidebarContext . Provider value = { { ...mockData } } >
43
+ < SidebarContext . Provider value = { { ...sidebarContext } } >
42
44
< MemoryRouter >
43
45
< SidebarUnit
44
46
isFirst
@@ -95,22 +97,45 @@ describe('<SidebarUnit />', () => {
95
97
expect ( screen . getByText ( unit . title ) ) . toBeInTheDocument ( ) ;
96
98
} ) ;
97
99
98
- it ( 'sends log event correctly when unit is clicked' , async ( ) => {
99
- const user = userEvent . setup ( ) ;
100
- await initTestStore ( ) ;
101
- renderWithProvider ( { unit : { ...unit } } ) ;
102
- const logData = {
103
- id : unit . id ,
104
- current_tab : 1 ,
105
- tab_count : 1 ,
106
- target_id : unit . id ,
107
- target_tab : 1 ,
108
- widget_placement : 'left' ,
109
- } ;
100
+ describe ( 'When a unit is clicked' , ( ) => {
101
+ it ( 'sends log event correctly' , async ( ) => {
102
+ const user = userEvent . setup ( ) ;
103
+ await initTestStore ( ) ;
104
+ renderWithProvider ( { unit : { ...unit } } ) ;
105
+ const logData = {
106
+ id : unit . id ,
107
+ current_tab : 1 ,
108
+ tab_count : 1 ,
109
+ target_id : unit . id ,
110
+ target_tab : 1 ,
111
+ widget_placement : 'left' ,
112
+ } ;
113
+
114
+ await user . click ( screen . getByText ( unit . title ) ) ;
115
+
116
+ expect ( sendTrackEvent ) . toHaveBeenCalledWith ( 'edx.ui.lms.sequence.tab_selected' , logData ) ;
117
+ expect ( sendTrackingLogEvent ) . toHaveBeenCalledWith ( 'edx.ui.lms.sequence.tab_selected' , logData ) ;
118
+ } ) ;
110
119
111
- await user . click ( screen . getByText ( unit . title ) ) ;
120
+ it ( 'leaves sidebar open in desktop mode' , async ( ) => {
121
+ const user = userEvent . setup ( ) ;
122
+ await initTestStore ( ) ;
123
+ renderWithProvider ( { unit : { ...unit } } ) ;
124
+ await user . click ( screen . getByText ( unit . title ) ) ;
112
125
113
- expect ( sendTrackEvent ) . toHaveBeenCalledWith ( 'edx.ui.lms.sequence.tab_selected' , logData ) ;
114
- expect ( sendTrackingLogEvent ) . toHaveBeenCalledWith ( 'edx.ui.lms.sequence.tab_selected' , logData ) ;
126
+ expect ( defaultSidebarContext . toggleSidebar ) . not . toHaveBeenCalled ( ) ;
127
+ expect ( window . sessionStorage . getItem ( 'hideCourseOutlineSidebar' ) ) . toBeNull ( ) ;
128
+ } ) ;
129
+
130
+ it ( 'closes sidebar on mobile devices' , async ( ) => {
131
+ const user = userEvent . setup ( ) ;
132
+ await initTestStore ( ) ;
133
+ renderWithProvider ( { unit : { ...unit } } , { ...defaultSidebarContext , shouldDisplayFullScreen : true } ) ;
134
+ await user . click ( screen . getByText ( unit . title ) ) ;
135
+
136
+ expect ( defaultSidebarContext . toggleSidebar ) . toHaveBeenCalledTimes ( 1 ) ;
137
+ expect ( defaultSidebarContext . toggleSidebar ) . toHaveBeenCalledWith ( null ) ;
138
+ expect ( window . sessionStorage . getItem ( 'hideCourseOutlineSidebar' ) ) . toEqual ( 'true' ) ;
139
+ } ) ;
115
140
} ) ;
116
141
} ) ;
0 commit comments