@@ -36,12 +36,12 @@ describe('<SidebarUnit />', () => {
3636 } ;
3737 } ;
3838
39- function renderWithProvider ( props = { } , sidebarContext = defaultSidebarContext ) {
39+ function renderWithProvider ( props = { } , sidebarContext = defaultSidebarContext , pathname = '/course' ) {
4040 const { container } = render (
4141 < AppProvider store = { store } wrapWithRouter = { false } >
4242 < IntlProvider locale = "en" >
4343 < SidebarContext . Provider value = { { ...sidebarContext } } >
44- < MemoryRouter >
44+ < MemoryRouter initialEntries = { [ { pathname } ] } >
4545 < SidebarUnit
4646 isFirst
4747 id = { unit . id }
@@ -138,4 +138,34 @@ describe('<SidebarUnit />', () => {
138138 expect ( window . sessionStorage . getItem ( 'hideCourseOutlineSidebar' ) ) . toEqual ( 'true' ) ;
139139 } ) ;
140140 } ) ;
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+ } ) ;
141171} ) ;
0 commit comments