11import { Factory } from 'rosie' ;
2+ import userEvent from '@testing-library/user-event' ;
3+ import { createRef } from 'react' ;
24
35import {
46 initializeTestStore ,
79 fireEvent ,
810 waitFor ,
911} from '@src/setupTest' ;
10- import userEvent from '@testing-library/user-event' ;
11- import { createRef } from 'react' ;
1212import messages from '@src/courseware/course/messages' ;
1313import SidebarContext from '../SidebarContext' ;
1414import SidebarBase from './SidebarBase' ;
@@ -31,16 +31,17 @@ describe('SidebarBase', () => {
3131 let mockHandleKeyDown ;
3232 let mockHandleBackBtnKeyDown ;
3333
34+ const defaultComponentProps = {
35+ title : 'Test Sidebar Title' ,
36+ ariaLabel : 'Test Sidebar Aria Label' ,
37+ sidebarId : SIDEBAR_ID ,
38+ className : 'test-class' ,
39+ children : < div > Sidebar Content</ div > ,
40+ } ;
41+
3442 const renderSidebar = ( contextProps = { } , componentProps = { } ) => {
3543 const fullContextValue = { ...mockContextValue , ...contextProps } ;
36- const defaultProps = {
37- title : 'Test Sidebar Title' ,
38- ariaLabel : 'Test Sidebar Aria Label' ,
39- sidebarId : SIDEBAR_ID ,
40- className : 'test-class' ,
41- children : < div > Sidebar Content</ div > ,
42- ...componentProps ,
43- } ;
44+ const defaultProps = { ...defaultComponentProps , ...componentProps } ;
4445 return render (
4546 < SidebarContext . Provider value = { fullContextValue } >
4647 < SidebarBase { ...defaultProps } />
@@ -84,7 +85,7 @@ describe('SidebarBase', () => {
8485 it ( 'should render children, title, and close button when visible' , ( ) => {
8586 renderSidebar ( { currentSidebar : SIDEBAR_ID } ) ;
8687 expect ( screen . getByText ( 'Sidebar Content' ) ) . toBeInTheDocument ( ) ;
87- expect ( screen . getByText ( 'Test Sidebar Title' ) ) . toBeInTheDocument ( ) ;
88+ expect ( screen . getByText ( defaultComponentProps . title ) ) . toBeInTheDocument ( ) ;
8889 expect ( screen . getByRole ( 'button' , { name : messages . closeNotificationTrigger . defaultMessage } ) ) . toBeInTheDocument ( ) ;
8990 expect ( screen . getByTestId ( `sidebar-${ SIDEBAR_ID } ` ) ) . toBeInTheDocument ( ) ;
9091 expect ( screen . getByTestId ( `sidebar-${ SIDEBAR_ID } ` ) ) . not . toHaveClass ( 'd-none' ) ;
@@ -99,7 +100,7 @@ describe('SidebarBase', () => {
99100
100101 it ( 'should hide title bar when showTitleBar prop is false' , ( ) => {
101102 renderSidebar ( { currentSidebar : SIDEBAR_ID } , { showTitleBar : false } ) ;
102- expect ( screen . queryByText ( 'Test Sidebar Title' ) ) . not . toBeInTheDocument ( ) ;
103+ expect ( screen . queryByText ( defaultComponentProps . title ) ) . not . toBeInTheDocument ( ) ;
103104 expect ( screen . queryByRole ( 'button' , { name : messages . closeNotificationTrigger . defaultMessage } ) ) . not . toBeInTheDocument ( ) ;
104105 expect ( screen . getByText ( 'Sidebar Content' ) ) . toBeInTheDocument ( ) ;
105106 } ) ;
0 commit comments