@@ -36,12 +36,12 @@ describe('<SidebarUnit />', () => {
36
36
} ;
37
37
} ;
38
38
39
- function renderWithProvider ( props = { } , sidebarContext = defaultSidebarContext ) {
39
+ function renderWithProvider ( props = { } , sidebarContext = defaultSidebarContext , pathname = '/course' ) {
40
40
const { container } = render (
41
41
< AppProvider store = { store } wrapWithRouter = { false } >
42
42
< IntlProvider locale = "en" >
43
43
< SidebarContext . Provider value = { { ...sidebarContext } } >
44
- < MemoryRouter >
44
+ < MemoryRouter initialEntries = { [ { pathname } ] } >
45
45
< SidebarUnit
46
46
isFirst
47
47
id = { unit . id }
@@ -138,4 +138,34 @@ describe('<SidebarUnit />', () => {
138
138
expect ( window . sessionStorage . getItem ( 'hideCourseOutlineSidebar' ) ) . toEqual ( 'true' ) ;
139
139
} ) ;
140
140
} ) ;
141
+
142
+ describe ( 'UnitLinkWrapper' , ( ) => {
143
+ describe ( 'course in preview mode' , ( ) => {
144
+ beforeEach ( async ( ) => {
145
+ await initTestStore ( ) ;
146
+ renderWithProvider ( { unit : { ...unit } } , { ...defaultSidebarContext , shouldDisplayFullScreen : true } , '/preview/course' ) ;
147
+ } ) ;
148
+
149
+ it ( 'href includes /preview' , async ( ) => {
150
+ const unitLink = screen . getByText ( unit . title ) . closest ( 'a' ) ;
151
+ const linkHref = unitLink . getAttribute ( 'href' ) ;
152
+
153
+ expect ( linkHref . includes ( '/preview/' ) ) . toBeTruthy ( ) ;
154
+ } ) ;
155
+ } ) ;
156
+
157
+ describe ( 'course in live mode' , ( ) => {
158
+ beforeEach ( async ( ) => {
159
+ await initTestStore ( ) ;
160
+ renderWithProvider ( { unit : { ...unit } } , { ...defaultSidebarContext , shouldDisplayFullScreen : true } ) ;
161
+ } ) ;
162
+
163
+ it ( 'href does not include /preview/' , async ( ) => {
164
+ const unitLink = screen . getByText ( unit . title ) . closest ( 'a' ) ;
165
+ const linkHref = unitLink . getAttribute ( 'href' ) ;
166
+
167
+ expect ( linkHref . includes ( '/preview/' ) ) . toBeFalsy ( ) ;
168
+ } ) ;
169
+ } ) ;
170
+ } ) ;
141
171
} ) ;
0 commit comments