@@ -4,20 +4,46 @@ import { userEvent } from '@testing-library/user-event';
44import {
55 initializeMocks , render , screen , waitFor , within ,
66} from '@src/testUtils' ;
7+ import { CourseAuthoringProvider } from '@src/CourseAuthoringContext' ;
8+ import { executeThunk } from '@src/utils' ;
9+
10+ import {
11+ fetchCourseOutlineIndexQuery ,
12+ } from '../data/thunk' ;
13+ import {
14+ getCourseOutlineIndexApiUrl ,
15+ } from '../data/api' ;
16+ import {
17+ courseOutlineIndexMock ,
18+ } from '../__mocks__' ;
719
820import { OutlineSidebarProvider } from './OutlineSidebarContext' ;
921import OutlineSidebar from './OutlineSidebar' ;
1022
1123const courseId = 'course-v1:TestOrg+TestCourse+2023_1' ;
1224
25+ const extraWrapper = ( { children } ) => (
26+ < CourseAuthoringProvider courseId = { courseId } >
27+ < OutlineSidebarProvider >
28+ { children }
29+ </ OutlineSidebarProvider >
30+ </ CourseAuthoringProvider >
31+ ) ;
1332const renderComponent = ( ) => render (
1433 < OutlineSidebar courseId = { courseId } /> ,
15- { extraWrapper : OutlineSidebarProvider } ,
34+ { extraWrapper } ,
1635) ;
1736
1837describe ( '<OutlineSidebar>' , ( ) => {
19- beforeEach ( ( ) => {
20- initializeMocks ( ) ;
38+ beforeEach ( async ( ) => {
39+ const mocks = initializeMocks ( ) ;
40+
41+ const { axiosMock, reduxStore : store } = mocks ;
42+ axiosMock
43+ . onGet ( getCourseOutlineIndexApiUrl ( courseId ) )
44+ . reply ( 200 , courseOutlineIndexMock ) ;
45+
46+ await executeThunk ( fetchCourseOutlineIndexQuery ( courseId ) , store . dispatch ) ;
2147 } ) ;
2248
2349 it ( 'should render the help sidebar by default' , async ( ) => {
@@ -36,7 +62,7 @@ describe('<OutlineSidebar>', () => {
3662
3763 // Check that the new sidebar is rendered, with the Info page
3864 await waitFor ( ( ) => {
39- expect ( screen . getByText ( 'Course 1 ' ) ) . toBeInTheDocument ( ) ;
65+ expect ( screen . getByText ( 'Demonstration Course ' ) ) . toBeInTheDocument ( ) ;
4066 } ) ;
4167
4268 const sidebarToggle = screen . getByTestId ( 'sidebar-toggle' ) ;
@@ -48,14 +74,14 @@ describe('<OutlineSidebar>', () => {
4874 await userEvent . click ( toggleButton ) ;
4975
5076 // Check that there are no more Info sidebar elements
51- expect ( screen . queryByText ( 'Course 1 ' ) ) . not . toBeInTheDocument ( ) ;
77+ expect ( screen . queryByText ( 'Demonstration Course ' ) ) . not . toBeInTheDocument ( ) ;
5278
5379 // Show the sidebar
5480 await userEvent . click ( toggleButton ) ;
5581
5682 // Check that the new sidebar is rendered, with the Info page
5783 await waitFor ( ( ) => {
58- expect ( screen . getByText ( 'Course 1 ' ) ) . toBeInTheDocument ( ) ;
84+ expect ( screen . getByText ( 'Demonstration Course ' ) ) . toBeInTheDocument ( ) ;
5985 } ) ;
6086
6187 // Change page
0 commit comments